digitalmars.D.learn - Quine using strings?
- Nestor (10/10) Jan 15 2017 I was reading some of the examples of writing a quine with D, but
- Nestor (3/13) Jan 15 2017 Well I just noticed a few problems in the code, I guess quines
- pineapple (2/4) Jan 15 2017 When compiling with the -main flag, this D program is a quine:
- Nestor (2/6) Jan 15 2017 You forgot to include the program... or is this a joke? ;)
- Adam D. Ruppe (4/5) Jan 15 2017 Neither: the empty program compiles and runs, outputting nothing.
- Michael Coulombe (10/10) Jan 15 2017 A quine I came up with a while ago, using q{} string notation:
- Basile B. (9/19) Jan 15 2017 I remember on Rosetta to have seen this:
- Nestor (6/14) Jan 16 2017 Very good! By the way, module name and arguments aren't needed,
- pineapple (5/6) Jan 16 2017 I'm afraid so - while the empty program has been technically
- Jesse Phillips (4/10) Jan 17 2017 But the program doesn't read from IO it's own program. It is a
I was reading some of the examples of writing a quine with D, but
apparently the language has evolved and they no longer compiled
unchanged.
So I tried to program one by myself using strings and std.stdio,
but the result seems long and redundant:
import std.stdio;void main(){string s=`import std.stdio;void
main(){string
s=writefln("%s\x60%s\x60;s",s[0..38],s,s[38..$]);}`;writefln("%s\x60%s\x60;%s",s[0..38],s,s[38..$]);}
Any ideas for a shorter version (preferably without using
pointers)?
Jan 15 2017
On Sunday, 15 January 2017 at 19:43:22 UTC, Nestor wrote:
I was reading some of the examples of writing a quine with D,
but apparently the language has evolved and they no longer
compiled unchanged.
So I tried to program one by myself using strings and
std.stdio, but the result seems long and redundant:
import std.stdio;void main(){string s=`import std.stdio;void
main(){string
s=writefln("%s\x60%s\x60;s",s[0..38],s,s[38..$]);}`;writefln("%s\x60%s\x60;%s",s[0..38],s,s[38..$]);}
Any ideas for a shorter version (preferably without using
pointers)?
Well I just noticed a few problems in the code, I guess quines
are a little complex to write.
Jan 15 2017
On Sunday, 15 January 2017 at 21:37:53 UTC, Nestor wrote:When compiling with the -main flag, this D program is a quine:Any ideas for a shorter version (preferably without using pointers)?
Jan 15 2017
On Sunday, 15 January 2017 at 22:08:47 UTC, pineapple wrote:On Sunday, 15 January 2017 at 21:37:53 UTC, Nestor wrote:You forgot to include the program... or is this a joke? ;)When compiling with the -main flag, this D program is a quine:Any ideas for a shorter version (preferably without using pointers)?
Jan 15 2017
On Sunday, 15 January 2017 at 22:35:26 UTC, Nestor wrote:You forgot to include the program... or is this a joke? ;)Neither: the empty program compiles and runs, outputting nothing. Since its empty output matches its empty source file, it technically fits the definition of the quine :)
Jan 15 2017
A quine I came up with a while ago, using q{} string notation:
enum s = q{enum s = q{%s};
void main() {
import std.stdio;
writefln(s,s);
}};
void main() {
import std.stdio;
writefln(s,s);
}
Jan 15 2017
On Sunday, 15 January 2017 at 19:43:22 UTC, Nestor wrote:
I was reading some of the examples of writing a quine with D,
but apparently the language has evolved and they no longer
compiled unchanged.
So I tried to program one by myself using strings and
std.stdio, but the result seems long and redundant:
import std.stdio;void main(){string s=`import std.stdio;void
main(){string
s=writefln("%s\x60%s\x60;s",s[0..38],s,s[38..$]);}`;writefln("%s\x60%s\x60;%s",s[0..38],s,s[38..$]);}
Any ideas for a shorter version (preferably without using
pointers)?
I remember on Rosetta to have seen this:
module quine;
import std.stdio;
void main(string[] args)
{
write(import("quine.d"));
}
compiles with: dmd path/quine.d -Jpath
Jan 15 2017
On Monday, 16 January 2017 at 06:41:50 UTC, Basile B. wrote:
I remember on Rosetta to have seen this:
module quine;
import std.stdio;
void main(string[] args)
{
write(import("quine.d"));
}
compiles with: dmd path/quine.d -Jpath
Very good! By the way, module name and arguments aren't needed,
so:
import std.stdio;void main(){write(import("q.d"));}
compile with: "dmd q -J."
PS. Isn't this approach considered "cheating" in quines? ;)
Jan 16 2017
On Monday, 16 January 2017 at 09:33:23 UTC, Nestor wrote:PS. Isn't this approach considered "cheating" in quines? ;)I'm afraid so - while the empty program has been technically accepted as being a quine (e.g. http://www.ioccc.org/1994/smr.hint) programs which use file io to read their own source have not.
Jan 16 2017
On Monday, 16 January 2017 at 13:11:38 UTC, pineapple wrote:On Monday, 16 January 2017 at 09:33:23 UTC, Nestor wrote:But the program doesn't read from IO it's own program. It is a stand alone executable which does no file IO. The compiler on the other hand does IO to inject the file into the program.PS. Isn't this approach considered "cheating" in quines? ;)I'm afraid so - while the empty program has been technically accepted as being a quine (e.g. http://www.ioccc.org/1994/smr.hint) programs which use file io to read their own source have not.
Jan 17 2017









Adam D. Ruppe <destructionator gmail.com> 