www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Shortest quine in D

reply "H. S. Teoh via Digitalmars-d" <digitalmars-d puremagic.com> writes:
------hello.d:------
import std.stdio;void main(){write(import("hello.d"));}
--------------------

Thanks to string imports, quines in D are actually trivial. :-D


T

-- 
Knowledge is that area of ignorance that we arrange and classify. -- Ambrose
Bierce
Apr 26 2017
next sibling parent reply Stefan Koch <uplink.coder googlemail.com> writes:
On Wednesday, 26 April 2017 at 23:19:32 UTC, H. S. Teoh wrote:
 ------hello.d:------
 import std.stdio;void main(){write(import("hello.d"));}
 --------------------

 Thanks to string imports, quines in D are actually trivial. :-D


 T
use __FILE__ to make it a little more portable
Apr 26 2017
parent =?UTF-8?Q?Ali_=c3=87ehreli?= <acehreli yahoo.com> writes:
On 04/26/2017 04:48 PM, Stefan Koch wrote:
 On Wednesday, 26 April 2017 at 23:19:32 UTC, H. S. Teoh wrote:
 ------hello.d:------
 import std.stdio;void main(){write(import("hello.d"));}
 --------------------

 Thanks to string imports, quines in D are actually trivial. :-D


 T
use __FILE__ to make it a little more portable
Or a single letter source file to make it shorter. :p Ali
Apr 26 2017
prev sibling parent reply Jon Degenhardt <jond noreply.com> writes:
On Wednesday, 26 April 2017 at 23:19:32 UTC, H. S. Teoh wrote:
 ------hello.d:------
 import std.stdio;void main(){write(import("hello.d"));}
 --------------------

 Thanks to string imports, quines in D are actually trivial. :-D


 T
:) https://en.wikipedia.org/wiki/Quine_
Apr 26 2017
parent reply "H. S. Teoh via Digitalmars-d" <digitalmars-d puremagic.com> writes:
On Thu, Apr 27, 2017 at 12:15:32AM +0000, Jon Degenhardt via Digitalmars-d
wrote:
 On Wednesday, 26 April 2017 at 23:19:32 UTC, H. S. Teoh wrote:
 ------hello.d:------
 import std.stdio;void main(){write(import("hello.d"));}
 --------------------
 
 Thanks to string imports, quines in D are actually trivial. :-D
 
 
 T
:) https://en.wikipedia.org/wiki/Quine_
Technically, the *program* itself takes no input, because string imports happen at compile-time, and the program's source is in fact embedded in the executable, not read at runtime. So technically it's not cheating. :-P But of course, it's in the "spirit of cheating" because it actually avoids the insight that comes with actually writing a quine without using string imports. And on that note, an actual cheating quine for D would be the blank .d file: because compiling with dmd -main produces an executable that writes no output (i.e., output of length zero, identical to the source code). T -- If creativity is stifled by rigid discipline, then it is not true creativity.
Apr 26 2017
parent "Nick Sabalausky (Abscissa)" <SeeWebsiteToContactMe semitwist.com> writes:
On 04/26/2017 11:37 PM, H. S. Teoh via Digitalmars-d wrote:
 On Thu, Apr 27, 2017 at 12:15:32AM +0000, Jon Degenhardt via Digitalmars-d
wrote:
 On Wednesday, 26 April 2017 at 23:19:32 UTC, H. S. Teoh wrote:
 ------hello.d:------
 import std.stdio;void main(){write(import("hello.d"));}
 --------------------

 Thanks to string imports, quines in D are actually trivial. :-D
And on that note, an actual cheating quine for D would be the blank .d file: because compiling with dmd -main produces an executable that writes no output (i.e., output of length zero, identical to the source code).
Finally, our killer app!!! :)
Apr 26 2017