Quines

If you'd like to know what a quine is, here's a short definition and a lengthy discussion. There are many other lists of quines - here's one. This particular list is composed entirely of quines written by me.

LanguagePropertiesNotesProgram
Common Lispprint, circle2005-12-16

#1=(progn (write '#1# :readably t :circle t) (values))

repl, circle2009-07-28
Getting dangerously close to “trivial”

#1='#1#

Haskellrepl, quoting

(\a -> a ++ show a) "(\\a -> a ++ show a) "

2006-11-27
Point-free version of the above

ap (++) show "ap (++) show "

MOO-Coderepl, quoting

;;s={";;s=", ";return s[1] + toliteral(s) + s[2];"};return s[1] + toliteral(s) + s[2];

Pythonrepl, quoting

x=['x=', ';x[0] + repr(x) + x[1]'];x[0] + repr(x) + x[1]

repl, quoting

(lambda x:repr(x).join(x))(['(lambda x:repr(x).join(x))(', ')'])

repl, quoting

(lambda x: x + repr((x,)))('(lambda x: x + repr((x,)))',)

print, eval, quoting

s='print "s=" + repr(s) + ";exec s"';exec s

E repl, quoting

def x := ["def x := ", "; x[0] + E.toQuote(x) + x[1]"]; x[0] + E.toQuote(x) + x[1]

print, quoting

println(def [a, c] := def b := ["println(def [a, c] := def b := ", "; a+b+c)"]; a+b+c)

print, quoting Shortest E quine I know of.

[" =~ [x]; println([x],x)"] =~ [x]; println([x],x)

print, quoting The above without using lists as a trick to force quoting.

" =~ x; println(E.toQuote(x),x)" =~ x; println(E.toQuote(x),x)

print, quoting

println(def a; a, def [bind a, b] := ["println(def a; a, def [bind a, b] := ", ", b)"], b)

print, quoting

" =~ b; stdout.quote(b); stdout.println(b)" =~ b; stdout.quote(b); stdout.println(b)

printUnlike all the above E quines, does its own quoting.

println(def _(a){return a+"`"+a.replaceAll("`", "``")+"`))"}(`))
println(def _(a){return a+"``"+a.replaceAll("``", "````")+"``))"}(`))

Perl 5print, metaUses require and a quoted package name because B::Deparse cannot reproduce use statements.

sub _{
    require(B::Deparse);
    printf "sub _%s_\n", 'B::Deparse'->new->coderef2text(\&_);
}_

print, eval, nesting
$_=q{print"\$_=q{$_};eval\n"};eval
print, nesting
(printf((q((printf((q(%s))x2))))x2))
print, nestingThere must be a blank line at the end of the source.
die<<''x2,$/
die<<''x2,$/

print, nesting
$_=q{$_=q{X};s/X/$_/;print};s/X/$_/;print
print, cycle, evalThis is actually the 'seed' program - it is outside of the cycle, but produces a program in the cycle when run.
$_=q{%_=map{$_,1}45,123,125,92;$"=$,;sub r{
  my (@t, $f) = grep !$_{$_}, (32..126);
  unshift @t, splice @t, shift @_; push @t,
  -1; my ($aa, $bb) = ($t[0], 1+shift @t);
  for ($bb++; defined (my $this = shift @t); $bb++)
  { next if $this     == $bb;
    $f .= chr($aa) . ("-" . chr($bb-1))
           x ($aa     !=        $bb-1);
    $aa = $bb = $this;}"{$f}"}
s/(r\(-?)(\d+)\)/$1.($2+1).')'/ge;eval'y'.r.r(1);
print"\$_=q{$_};  y".r.r(-1).";eval;print\$@\n"
};  eval;print$@
print, cheatingThese are not strictly quines, and are only included to make this my complete collection of quinelike programs.
open 0;print<0>
print, cheating
seek DATA,0,0;print<DATA>__END__
print, cheating, eval
#!/usr/bin/perl -w-e 'open ${-%{$@}};print'
$_=q=_=;s##scalar((($_='!;_$$,!$_!;') =~
 tr@_$;!,@=",$;@),$_)#ee;eval "@{[reverse
 split+/[1-9]/, '>1A2T3A5D4<6 7t8in1r2p2;4'
.'05,801,8A9AT3k D5e6e7s8']}" __END__
print, cheating, eval
#!perl -w-e'seek DATA, 0, 0; print <DATA>'
$_=q;\;0+nepo; ;$_?$_:$!=s;(.*);(join+q..,
reverse+split+m++,$1).q.print<0>.;see? 00:01

Definition of properties:

cheating
Reads its own source code from a file, thus not really a quine.
circle
Contains a reference to its own source code.
meta
Uses language facilities for recreating the source from intermediate representations, thus whether it is a quine is questionable.
eval
Requires ability to evaluate code written in the language.
cycle
One of a set of N programs such that executing program i produces program (i + 1) mod N.
nesting
Uses language facilities for nested quoting such that the code can be inserted as data with no quote munging.
quoting
Uses language facilities for writing a string in the form of the language's string literals.
print
As opposed to 'repl', writes its source to an output stream.
repl
As opposed to 'print', produces its source as the value of the expression.