Re: Quine using strings?
On Monday, 16 January 2017 at 13:11:38 UTC, pineapple wrote: 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. 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.
Re: Quine using strings?
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.
Re: Quine using strings?
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? ;)
Re: Quine using strings?
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
Re: Quine using strings?
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); }
Re: Quine using strings?
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 :)
Re: Quine using strings?
On Sunday, 15 January 2017 at 22:08:47 UTC, pineapple wrote: On Sunday, 15 January 2017 at 21:37:53 UTC, Nestor wrote: Any ideas for a shorter version (preferably without using pointers)? When compiling with the -main flag, this D program is a quine: You forgot to include the program... or is this a joke? ;)
Re: Quine using strings?
On Sunday, 15 January 2017 at 21:37:53 UTC, Nestor wrote: Any ideas for a shorter version (preferably without using pointers)? When compiling with the -main flag, this D program is a quine:
Quine using strings?
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)?