Quine: Difference between revisions
Clarified. Removed Perl, PHP and UNIX Shell examples |
No edit summary |
||
Line 30: | Line 30: | ||
Haskell does not keep the code in an uncompiled-equivalent form around at runtime, so the "quotation trick" has to be used. |
Haskell does not keep the code in an uncompiled-equivalent form around at runtime, so the "quotation trick" has to be used. |
||
=={{header|LISP}}== |
|||
The empty list is a valid LISP routine. Upon invocation it returns ... an empty list. Which is thus its own code: |
|||
() |
|||
This is bound to be one of the shortest quines in existence. |
|||
=={{header|Seed7}}== |
=={{header|Seed7}}== |
Revision as of 22:00, 20 November 2007
Print out a program's own source code without reading from the source file.
Ada
with Text_Io; procedure Self is Q:Character:='"'; A:String(1..132):="with text_io;procedure self is q:character:=;a:string(1..132):=;begin text_io.put_line(a(1..45)&q&a(46..65)&q&a&q&a(66..132));end;"; begin Text_Io.Put_Line(A(1..45)&Q&A(46..65)&Q&A&Q&A(66..132)); end;
Befunge
The code space is also the data space of a Befunge program. Programs can be read and modified on the fly. This quine works by reading and printing each character of the source. (This is a implicit loop, since the Befunge codespace wraps around.)
:0g,:66+`#@_1+
Forth
SOURCE TYPE
Haskell
The obvious solution, as a one-liner:
let q s = putStrLn $ s ++ show s in q "let q s = putStrLn $ s ++ show s in q "
Having the string at the end makes things a bit simpler than in generic version mentioned in the Wikipedia article.
Haskell does not keep the code in an uncompiled-equivalent form around at runtime, so the "quotation trick" has to be used.
LISP
The empty list is a valid LISP routine. Upon invocation it returns ... an empty list. Which is thus its own code:
()
This is bound to be one of the shortest quines in existence.
Seed7
$ include "seed7_05.s7i"; const array string: prog is []( "$ include \"seed7_05.s7i\";", "const array string: prog is [](", "const proc: main is func", " local var integer: number is 0;", " begin", " for number range 1 to 2 do writeln(prog[number]); end for;", " for number range 1 to 11 do", " writeln(literal(prog[number]) <& \",\");", " end for;", " writeln(literal(prog[12]) <& \");\");", " for number range 3 to 12 do writeln(prog[number]); end for;", " end func;"); const proc: main is func local var integer: number is 0; begin for number range 1 to 2 do writeln(prog[number]); end for; for number range 1 to 11 do writeln(literal(prog[number]) <& ","); end for; writeln(literal(prog[12]) <& ");"); for number range 3 to 12 do writeln(prog[number]); end for; end func;
Original source: [1]