Quine: Difference between revisions

3,995 bytes added ,  2 months ago
m
m (syntax highlighting fixup automation)
(23 intermediate revisions by 16 users not shown)
Line 261:
 
<syntaxhighlight lang="lisp">(let((q"(let((q~x0))(cw q q))"))(cw q q))</syntaxhighlight>
 
=={{header|Acornsoft Lisp}}==
 
<syntaxhighlight lang="lisp">((lambda (s) (list s (list (quote quote) s)))
(quote (lambda (s) (list s (list (quote quote) s)))))
</syntaxhighlight>
 
=={{header|Ada}}==
Line 595 ⟶ 601:
 
=={{header|Binary Lambda Calculus}}==
As explained at https://tromp.github.io/cl/Binary_lambda_calculus.html#A_quinea_quine
<syntaxhighlightpre lang="blc">000101100100011010000000000001011011110010111100111111011111011010000101100100011010000000000001011011110010111100111111011111011010</syntaxhighlightpre>A byte oriented version is given by the 18 byte program
 
<code>16 46 80 05 bc bc fd f6 80 16 46 80 05 bc bc fd f6 80</code>                                                       
 
=={{header|Bob}}==
Line 712 ⟶ 720:
The C1R compiler usually copies C solutions from tasks at Rosetta Code. The Quine task is an exception; it gets special treatment in the C1R compiler.
<syntaxhighlight lang="c">Quine</syntaxhighlight>
 
=={{header|C3}}==
<syntaxhighlight lang="c">import std::io; fn void main() => io::printfn("%sString q = \x60%s\x60;", q, q);String q = `import std::io; fn void main() => io::printfn("%sString q = \x60%s\x60;", q, q);`;</syntaxhighlight>
 
=={{header|Ceylon}}==
Line 1,350 ⟶ 1,361:
=={{header|E}}==
<syntaxhighlight lang="e">" =~ x; println(E.toQuote(x),x)" =~ x; println(E.toQuote(x),x)</syntaxhighlight>
 
=={{header|EasyLang}}==
<syntaxhighlight lang="easylang">
S$ = "print strchar 83 & strchar 36 & strchar 32 & strchar 61 & strchar 32 & strchar 34 & S$ & strchar 34 & strchar 10 & S$"
print strchar 83 & strchar 36 & strchar 32 & strchar 61 & strchar 32 & strchar 34 & S$ & strchar 34 & strchar 10 & S$
</syntaxhighlight>
 
=={{header|Ecstasy}}==
<syntaxhighlight lang="java">
module test {
@Inject Console console;
void run() {
console.print($./test.x);
}
}
</syntaxhighlight>
 
{{out}}
<pre>
module test {
@Inject Console console;
void run() {
console.print($./test.x);
}
}
</pre>
 
=={{header|Elixir}}==
Line 1,486 ⟶ 1,523:
=={{header|Fōrmulæ}}==
 
{{FormulaeEntry|page=https://formulae.org/?script=examples/Quine}}
Fōrmulæ programs are not textual, visualization/edition of programs is done showing/manipulating structures but not text. Moreover, there can be multiple visual representations of the same program. Even though it is possible to have textual representation &mdash;i.e. XML, JSON&mdash; they are intended for storage and transfer purposes more than visualization and edition.
 
'''Solution'''
Programs in Fōrmulæ are created/edited online in its [https://formulae.org website], However they run on execution servers. By default remote servers are used, but they are limited in memory and processing power, since they are intended for demonstration and casual use. A local server can be downloaded and installed, it has no limitations (it runs in your own computer). Because of that, example programs can be fully visualized and edited, but some of them will not run if they require a moderate or heavy computation/memory resources, and no local server is being used.
 
'''Preamble. Symbolic computation'''
In '''[https://formulae.org/?example=Quine this]''' page you can see the program(s) related to this task and their results.
 
Symbolic computation works different than traditional one. In symbolic computation, the program becomes gradually in its output, by the application of [[wp:Rewriting|rewriting rules]].
 
'''Example 1. The simplest program'''
 
The simplest program is a Null expression. Please notice that it is not an empty program (which is disallowed). It is just a one expression program: the Null expression, which has no rewriting rules.
 
[[File:Fōrmulæ - Quine 01.png]]
 
[[File:Fōrmulæ - Quine 02.png]]
 
'''Example 2. A program with non-reducible expressions'''
 
According to symbolic computation, if a program contains only non-reducible expressions (expression with no rewriting rules), then it will no be transformed to anything else, and it will be its own output.
 
[[File:Fōrmulæ - Quine 03.png]]
 
[[File:Fōrmulæ - Quine 04.png]]
 
[[File:Fōrmulæ - Quine 05.png]]
 
[[File:Fōrmulæ - Quine 06.png]]
 
[[File:Fōrmulæ - Quine 07.png]]
 
[[File:Fōrmulæ - Quine 08.png]]
 
=={{header|Furor}}==
Line 1,517 ⟶ 1,580:
{ „selfstring” }
{ „maxlines” }</syntaxhighlight>
 
=={{header|Peri}}==
<syntaxhighlight lang="peri">
###sysinclude standard.uh
#g §vége §eleje - sto maxlines
#s
8 {{ {{}} §eleje[] printnl }}
@maxlines {{ {{}} §eleje[] QUOTE print QUOTE NL }}
8 @maxlines {{ , {{}} §eleje[] printnl }}
end
eleje:
"###sysinclude standard.uh"
"#g §vége §eleje - sto maxlines"
"#s"
"8 {{ {{}} §eleje[] printnl }}"
" @maxlines {{ {{}} §eleje[] QUOTE print QUOTE NL }}"
"8 @maxlines {{ , {{}} §eleje[] printnl }}"
"end"
"eleje:"
"vége:"
"{ „selfstring” }"
"{ „maxlines” }"
vége:
{ „selfstring” }
{ „maxlines” }
 
</syntaxhighlight>
 
=={{header|FutureBasic}}==
This quine depends on BASIC syntax which, although still compilable with FB, is long obsolete.
<syntaxhighlight lang="futurebasic">
window 1,,(0,0,350,430)
Str255 d, x
read d
do
read x
print x
until len$(x) == 0
restore
do
read x
print d; chr$(34); x; chr$(34)
until len$(x) == 0
HandleEvents
 
data "data "
data "window 1,,(0,0,350,430)"
data "Str255 d, x"
data "read d"
data "do"
data " read x"
data " print x"
data "until len$(x) == 0"
data "restore"
data "do"
data " read x"
data " print d; chr$(34); x; chr$(34)"
data "until len$(x) == 0"
data "HandleEvents"
data ""
</syntaxhighlight>
{{output}}
<pre>
Ditto, of course.
</pre>
 
 
=={{header|Gabuzomeu}}==
Line 1,667 ⟶ 1,796:
=={{header|Inform 7}}==
<syntaxhighlight lang="inform7">R is a room. To quit: (- quit; -). When play begins: say entry 1 in Q; say Q in brace notation; quit. Q is a list of text variable. Q is {"R is a room. To quit: (- quit; -). When play begins: say entry 1 in Q; say Q in brace notation; quit. Q is a list of text variable. Q is "}</syntaxhighlight>
 
=={{header|Insitux}}==
<syntaxhighlight lang="insitux">(#(join(char-code 34)[% %(char-code 41)])"(#(join(char-code 34)[% %(char-code 41)])")</syntaxhighlight>
 
=={{header|INTERCAL}}==
Line 1,711 ⟶ 1,843:
=== Replacing String ===
<syntaxhighlight lang="javascript">(function(){str=["(function(){str=[F].join(String.fromCharCode(34));str=str.replace(/F/,String.fromCharCode(34)+str+String.fromCharCode(34));console.log(str)})()"].join(String.fromCharCode(34));str=str.replace(/F/,String.fromCharCode(34)+str+String.fromCharCode(34));console.log(str)})()</syntaxhighlight>
 
=== encodeURI as string escapes ===
Functions like <code>encodeURI/decodeURI</code> benefit js with highly controllable string escapes, like the quotes, newlines, etc. Thus, the following js-flavored quine requires no explicit or implicit <code>stringify</code>, <code>eval</code> or template literals functionalities:
<syntaxhighlight lang="javascript">let x="let x=%22quinner%22; alert(decodeURI(x).replace(%22quinner%22, x));"; alert(decodeURI(x).replace("quinner", x));
</syntaxhighlight>
 
===Code As Data===
Line 1,827 ⟶ 1,964:
<syntaxhighlight lang="scheme">{{lambda {:x} :x} '{lambda {:x} :x}}
-> {lambda {:x} :x}</syntaxhighlight>
 
=={{header|Lang}}==
<syntaxhighlight lang="lang"># Execute in command line without any arguments except this Lang file
lang.name = Quine
lang.version = v1.0.0
 
$h = {{{# Execute in command line without any arguments except this Lang file
lang.name = Quine
lang.version = v1.0.0}}}
$s = {{{func.printf($h\n\n\$h \= %s{{%s}}%s\n\$s \= %s{{%s}}%s\n%s, {, $h, }, {, $s, }, $s)}}}
func.printf($h\n\n\$h \= %s{{%s}}%s\n\$s \= %s{{%s}}%s\n%s, {, $h, }, {, $s, }, $s)</syntaxhighlight>
 
=={{header|Lasso}}==
Line 2,672 ⟶ 2,820:
quine(`define(`quine',``$1(`$1')'')dnl
quine')</syntaxhighlight>
 
=={{header|make}}==
 
<syntaxhighlight lang="make">quine=$(info quine=$(value quine))$(info $$(quine))$(eval quine:;@:)
$(quine)</syntaxhighlight>
 
=={{header|Mathematica}}/{{header|Wolfram Language}}==
Line 2,719 ⟶ 2,872:
 
=={{header|Maxima}}==
<syntaxhighlight lang="maxima">/* Using ?format from the unerlying Lisp system */
/* Using ?format from the underlying Lisp system */
 
lambda([],block([q:ascii(34),s:"lambda([],block([q:ascii(34),s:~A~A~A],print(?format(false,s,q,s,q))))()$"],print(?format(false,s,q,s,q))))()$</syntaxhighlight>
</syntaxhighlight>
 
=={{header|MiniScript}}==
Line 2,887 ⟶ 3,042:
 
=={{header|Nim}}==
 
The empty program is a quine in Nim:
<syntaxhighlight lang="nim"></syntaxhighlight>
 
Another quine:
Line 3,634 ⟶ 3,786:
<syntaxhighlight lang="ring">v = "see substr(`v = ` + char(34) + `@` + char(34) + nl + `@` ,`@`,v)"
see substr(`v = ` + char(34) + `@` + char(34) + nl + `@` ,`@`,v)</syntaxhighlight>
 
=={{header|RPL}}==
RPL programs are stored in RAM as a specific data structure, and can then be recalled the same way as an ordinary variable.
{{works with|Halcyon Calc|4.2.7}}
≪ 'QUINE' RCL ≫
'QUINE' STO
QUINE
{{out}}
<pre>
1: ≪ 'QUINE' RCL ≫
</pre>
 
=={{header|Ruby}}==
Line 3,661 ⟶ 3,825:
 
As the above implementation depends on the code being saved in a file, it doesn’t work in IRB.
 
 
=={{header|Rust}}==
Line 4,341 ⟶ 4,504:
=={{header|Wren}}==
{{libheader|Wren-fmt}}
<syntaxhighlight lang="ecmascriptwren">import "./fmt" for Fmt
 
var a = "import $c./fmt$c for Fmt$c$cvar a = $q$cFmt.lprint(a, [34, 34, 10, 10, a, 10])"
Fmt.lprint(a, [34, 34, 10, 10, a, 10])</syntaxhighlight>
 
56

edits