Quine using strings?

Basile B. via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sun Jan 15 22:41:50 PST 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


More information about the Digitalmars-d-learn mailing list