Another update from ingydotnet^djgoku
This commit is contained in:
parent
91df62d461
commit
948b86eafa
7604 changed files with 108452 additions and 22726 deletions
|
|
@ -19,4 +19,5 @@ There are several difficulties that one runs into when writing a quine, mostly d
|
|||
** If the language has a way of getting the "source code representation", it usually handles the escaping of characters, so this is not a problem.
|
||||
** Some languages allow you to have a string literal that spans multiple lines, which embeds the newlines into the string without escaping.
|
||||
** Write the entire program on one line, for free-form languages (as you can see for some of the solutions here, they run off the edge of the screen), thus removing the need for newlines. However, this may be unacceptable as some languages require a newline at the end of the file; and otherwise it is still generally good style to have a newline at the end of a file. (The task is not clear on whether a newline is required at the end of the file.) Some languages have a print statement that appends a newline; which solves the newline-at-the-end issue; but others do not.
|
||||
<br>See the nostalgia note under Fortran.
|
||||
|
||||
'''Next to the Quines presented here, many other versions can be found on the [http://www.nyx.net/~gthompso/quine.htm Quine] page.'''
|
||||
|
|
|
|||
1
Task/Quine/AWK/quine-1.awk
Normal file
1
Task/Quine/AWK/quine-1.awk
Normal file
|
|
@ -0,0 +1 @@
|
|||
BEGIN{c="BEGIN{c=%c%s%c;printf(c,34,c,34);}";printf(c,34,c,34);}
|
||||
1
Task/Quine/AWK/quine-2.awk
Normal file
1
Task/Quine/AWK/quine-2.awk
Normal file
|
|
@ -0,0 +1 @@
|
|||
BEGIN{c="BEGIN{c=%c%s%c;printf c,34,c,34}";printf c,34,c,34}
|
||||
1
Task/Quine/Haskell/quine-6.hs
Normal file
1
Task/Quine/Haskell/quine-6.hs
Normal file
|
|
@ -0,0 +1 @@
|
|||
main = putStrLn $ (++) <*> show $ "main = putStrLn $ (++) <*> show $ "
|
||||
6
Task/Quine/Logo/quine.logo
Normal file
6
Task/Quine/Logo/quine.logo
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
make "a [ 116 121 112 101 32 34 124 109 97 107 101 32 34 97 32 91 124 10 102 111 114 101 97 99 104 32 58 97 32 91 32 116 121 112 101 32 119 111 114 100 32 34 124 32 124 32 63 32 93 10 112 114 105 110 116 32 34 124 32 93 124 10 102 111 114 101 97 99 104 32 58 97 32 91 32 116 121 112 101 32 99 104 97 114 32 63 32 93 10 98 121 101 10 ]
|
||||
type "|make "a [|
|
||||
foreach :a [ type word "| | ? ]
|
||||
print "| ]|
|
||||
foreach :a [ type char ? ]
|
||||
bye
|
||||
1
Task/Quine/NewLISP/quine.newlisp
Normal file
1
Task/Quine/NewLISP/quine.newlisp
Normal file
|
|
@ -0,0 +1 @@
|
|||
(lambda (s) (print (list s (list 'quote s))))
|
||||
111
Task/Quine/Prolog/quine-3.pro
Normal file
111
Task/Quine/Prolog/quine-3.pro
Normal file
|
|
@ -0,0 +1,111 @@
|
|||
% Tested with SWI-Prolog version 7.1.37
|
||||
:- initialization(main).
|
||||
|
||||
before(Lines) :- Lines = [
|
||||
"% Tested with SWI-Prolog version 7.1.37",
|
||||
":- initialization(main).",
|
||||
"",
|
||||
"before(Lines) :- Lines = ["
|
||||
].
|
||||
|
||||
after(Lines) :- Lines = [
|
||||
"].",
|
||||
"",
|
||||
"% replaces quotes by harmless ats",
|
||||
"% replaces backslashes by harmless slashes",
|
||||
"% replaces linebreaks by harmless sharps",
|
||||
"maskCode(34, 64).",
|
||||
"maskCode(92, 47).",
|
||||
"maskCode(10, 35).",
|
||||
"maskCode(X, X).",
|
||||
"",
|
||||
"% Encodes dangerous characters in a string",
|
||||
"encode(D, S) :- ",
|
||||
" string_codes(D, DC),",
|
||||
" maplist(maskCode, DC, SC),",
|
||||
" string_codes(S, SC).",
|
||||
"",
|
||||
"decode(S, D) :- ",
|
||||
" string_codes(S, SC),",
|
||||
" maplist(maskCode, DC, SC),",
|
||||
" string_codes(D, DC).",
|
||||
"",
|
||||
"% writes each entry indented by two spaces,",
|
||||
"% enclosed in quotes and separated by commas,",
|
||||
"% with a newline between the list entries.",
|
||||
"mkStringList([],@@).",
|
||||
"mkStringList([Single],Out) :-",
|
||||
" atomics_to_string([@ /@@, Single, @/@@], Out).",
|
||||
"",
|
||||
"mkStringList([H|T], Res) :-",
|
||||
" mkStringList(T, TailRes),",
|
||||
" atomics_to_string([@ /@@, H, @/@,/n@, TailRes], Res).",
|
||||
"",
|
||||
"quine(Q) :- ",
|
||||
" before(BeforeEncoded),",
|
||||
" after(AfterEncoded),",
|
||||
" maplist(decode, BeforeEncoded, BeforeDecoded),",
|
||||
" maplist(decode, AfterEncoded, AfterDecoded),",
|
||||
" atomic_list_concat(BeforeDecoded, @/n@, B),",
|
||||
" atomic_list_concat(AfterDecoded, @/n@, A),",
|
||||
" mkStringList(BeforeEncoded, BeforeData),",
|
||||
" mkStringList(AfterEncoded, AfterData),",
|
||||
" Center = @/n]./n/nafter(Lines) :- Lines = [/n@,",
|
||||
" atomic_list_concat([",
|
||||
" B, @/n@, BeforeData, ",
|
||||
" Center, ",
|
||||
" AfterData, @/n@, A, @/n@",
|
||||
" ], Q).",
|
||||
"",
|
||||
"main :- (quine(Q), write(Q);true),halt.",
|
||||
"% line break in the end of file is important"
|
||||
].
|
||||
|
||||
% replaces quotes by harmless ats
|
||||
% replaces backslashes by harmless slashes
|
||||
% replaces linebreaks by harmless sharps
|
||||
maskCode(34, 64).
|
||||
maskCode(92, 47).
|
||||
maskCode(10, 35).
|
||||
maskCode(X, X).
|
||||
|
||||
% Encodes dangerous characters in a string
|
||||
encode(D, S) :-
|
||||
string_codes(D, DC),
|
||||
maplist(maskCode, DC, SC),
|
||||
string_codes(S, SC).
|
||||
|
||||
decode(S, D) :-
|
||||
string_codes(S, SC),
|
||||
maplist(maskCode, DC, SC),
|
||||
string_codes(D, DC).
|
||||
|
||||
% writes each entry indented by two spaces,
|
||||
% enclosed in quotes and separated by commas,
|
||||
% with a newline between the list entries.
|
||||
mkStringList([],"").
|
||||
mkStringList([Single],Out) :-
|
||||
atomics_to_string([" \"", Single, "\""], Out).
|
||||
|
||||
mkStringList([H|T], Res) :-
|
||||
mkStringList(T, TailRes),
|
||||
atomics_to_string([" \"", H, "\",\n", TailRes], Res).
|
||||
|
||||
quine(Q) :-
|
||||
before(BeforeEncoded),
|
||||
after(AfterEncoded),
|
||||
maplist(decode, BeforeEncoded, BeforeDecoded),
|
||||
maplist(decode, AfterEncoded, AfterDecoded),
|
||||
atomic_list_concat(BeforeDecoded, "\n", B),
|
||||
atomic_list_concat(AfterDecoded, "\n", A),
|
||||
mkStringList(BeforeEncoded, BeforeData),
|
||||
mkStringList(AfterEncoded, AfterData),
|
||||
Center = "\n].\n\nafter(Lines) :- Lines = [\n",
|
||||
atomic_list_concat([
|
||||
B, "\n", BeforeData,
|
||||
Center,
|
||||
AfterData, "\n", A, "\n"
|
||||
], Q).
|
||||
|
||||
main :- (quine(Q), write(Q);true),halt.
|
||||
% line break in the end of file is important
|
||||
3
Task/Quine/R/quine-2.r
Normal file
3
Task/Quine/R/quine-2.r
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
src <- "\nwriteLines(c(paste(\"src <-\", encodeString(src, quote='\"')), src))"
|
||||
|
||||
writeLines(c(paste("src <-", encodeString(src, quote='"')), src))
|
||||
3
Task/Quine/Racket/quine-2.rkt
Normal file
3
Task/Quine/Racket/quine-2.rkt
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
#lang racket
|
||||
((λ(x)(printf "#lang racket\n(~a\n ~s)" x x))
|
||||
"(λ(x)(printf \"#lang racket\\n(~a\\n ~s)\" x x))")
|
||||
|
|
@ -1,59 +1,7 @@
|
|||
fn main()
|
||||
{
|
||||
let q = 34u8;
|
||||
let p = 44u8;
|
||||
let l = [
|
||||
"fn main()",
|
||||
"{",
|
||||
" let q = 34u8;",
|
||||
" let p = 44u8;",
|
||||
" let l = [",
|
||||
" ",
|
||||
" ];",
|
||||
" let mut i = 0;",
|
||||
" while i < 5",
|
||||
" {",
|
||||
" println(l[i]);",
|
||||
" i+=1;",
|
||||
" }",
|
||||
" i = 0;",
|
||||
" while i < l.len()",
|
||||
" {",
|
||||
" print(l[5]);",
|
||||
" print((q as char).to_str());",
|
||||
" print(l[i]);",
|
||||
" print((q as char).to_str());",
|
||||
" println((p as char).to_str());",
|
||||
" i+=1;",
|
||||
" }",
|
||||
" i = 6;",
|
||||
" while i < l.len()",
|
||||
" {",
|
||||
" println(l[i]);",
|
||||
" i+=1;",
|
||||
" }",
|
||||
"}",
|
||||
];
|
||||
let mut i = 0;
|
||||
while i < 5
|
||||
{
|
||||
println(l[i]);
|
||||
i+=1;
|
||||
}
|
||||
i = 0;
|
||||
while i < l.len()
|
||||
{
|
||||
print(l[5]);
|
||||
print((q as char).to_str());
|
||||
print(l[i]);
|
||||
print((q as char).to_str());
|
||||
println((p as char).to_str());
|
||||
i+=1;
|
||||
}
|
||||
i = 6;
|
||||
while i < l.len()
|
||||
{
|
||||
println(l[i]);
|
||||
i+=1;
|
||||
}
|
||||
fn main() {
|
||||
let x = "fn main() {\n let x = ";
|
||||
let y = "print!(\"{}{:?};\n let y = {:?};\n {}\", x, x, y, y)\n}\n";
|
||||
print!("{}{:?};
|
||||
let y = {:?};
|
||||
{}", x, x, y, y)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,59 @@
|
|||
extern crate debug;
|
||||
fn main() {
|
||||
let x = "extern crate debug;\nfn main() {\n let x = ";
|
||||
let y = "print!(\"{}{:?};\n let y = {:?};\n {}\", x, x, y, y)\n}";
|
||||
print!("{}{:?};
|
||||
let y = {:?};
|
||||
{}", x, x, y, y)
|
||||
fn main()
|
||||
{
|
||||
let q = 34u8;
|
||||
let p = 44u8;
|
||||
let l = [
|
||||
"fn main()",
|
||||
"{",
|
||||
" let q = 34u8;",
|
||||
" let p = 44u8;",
|
||||
" let l = [",
|
||||
" ",
|
||||
" ];",
|
||||
" let mut i = 0;",
|
||||
" while i < 5",
|
||||
" {",
|
||||
" println(l[i]);",
|
||||
" i+=1;",
|
||||
" }",
|
||||
" i = 0;",
|
||||
" while i < l.len()",
|
||||
" {",
|
||||
" print(l[5]);",
|
||||
" print((q as char).to_str());",
|
||||
" print(l[i]);",
|
||||
" print((q as char).to_str());",
|
||||
" println((p as char).to_str());",
|
||||
" i+=1;",
|
||||
" }",
|
||||
" i = 6;",
|
||||
" while i < l.len()",
|
||||
" {",
|
||||
" println(l[i]);",
|
||||
" i+=1;",
|
||||
" }",
|
||||
"}",
|
||||
];
|
||||
let mut i = 0;
|
||||
while i < 5
|
||||
{
|
||||
println(l[i]);
|
||||
i+=1;
|
||||
}
|
||||
i = 0;
|
||||
while i < l.len()
|
||||
{
|
||||
print(l[5]);
|
||||
print((q as char).to_str());
|
||||
print(l[i]);
|
||||
print((q as char).to_str());
|
||||
println((p as char).to_str());
|
||||
i+=1;
|
||||
}
|
||||
i = 6;
|
||||
while i < l.len()
|
||||
{
|
||||
println(l[i]);
|
||||
i+=1;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue