A bit of I6 code is included to force the interpreter to quit without
any prompt to create a true quine. There must be shorter quines possible
in I7 but this is what I came up with; I'd be interested to hear if
someone finds a different solution.
Note that for some reason you may have to compile the code twice to have
anything printed in the I7 IDE. Also it looks like some interpreters
change the quotation marks to different characters than what I7 uses.
An I6 quine has been made several years ago:
http://www.nyx.net/~gthompso/self_inform.txt (notably shorter than its
I7 counterpart!)
"Quine" by Juhana Leinonen
Quine is a room.
When play begins: say "[quine-list]".
To insta-quit: (- quit; -).
The L is a list of text that varies. The B is a list of numbers that
varies. The Q is a list of numbers that varies. The S1 is a list of
numbers that varies. The S2 is a list of numbers that varies.
The L is { "", "Quine", "", " by Juhana Leinonen", "", "Quine is a
room.", "", "When play begins: say ", "", "", "quine-list", "", "", ".",
"", "To insta-quit: (- quit; -).", "", "The L is a list of text that
varies. The B is a list of numbers that varies. The Q is a list of
numbers that varies. The S1 is a list of numbers that varies. The S2 is
a list of numbers that varies.", "", "", "The L is { ", "", " };", "",
"", "The B is { 4, 5, 6, 7, 14, 15, 16, 17, 18, 19, 22, 23, 24, 26, 27,
28, 60, 61, 62 }. The Q is { 1, 3, 10, 13, 30, 34, 36, 40, 42, 46, 48,
52, 64, 75, 77, 84 }. The S1 is { 10, 31, 37, 43, 49, 65, 68, 71, 78, 81
}. The S2 is { 12, 33, 39, 45, 51, 67, 70, 73, 80, 83 }.", "", "To say
quine-list:", "let c be 0; repeat with x running through L begin; ",
"increase c by 1; if c is 22 begin; list-print; otherwise; say ", "",
"", "x", "", "", "; if c is listed in Q, say ", "", "", "unicode 34",
"", "", "; if c is listed in B, say ", "", "", "line break", "", "", ";
if c is listed in S1, say ", "", "", "unicode 91", "", "", "; if c is
listed in S2, say ", "", "", "unicode 93", "", "", "; end if; end
repeat; insta-quit;", "", "To list-print:", "remove entry 86 from L;
repeat with x running through L begin; say ", "", "", "unicode 34", "",
"", "x", "", "", "unicode 34", "", ", ", "", "; end repeat; say ", "",
"", "unicode 34", "", "", "unicode 34", "", "", ";", "" };
The B is { 4, 5, 6, 7, 14, 15, 16, 17, 18, 19, 22, 23, 24, 26, 27, 28,
60, 61, 62 }. The Q is { 1, 3, 10, 13, 30, 34, 36, 40, 42, 46, 48, 52,
64, 75, 77, 84 }. The S1 is { 10, 31, 37, 43, 49, 65, 68, 71, 78, 81 }.
The S2 is { 12, 33, 39, 45, 51, 67, 70, 73, 80, 83 };
To say quine-list:
let c be 0; repeat with x running through L begin; increase c by 1; if c
is 22 begin; list-print; otherwise; say "[x]"; if c is listed in Q, say
"[unicode 34]"; if c is listed in B, say "[line break]"; if c is listed
in S1, say "[unicode 91]"; if c is listed in S2, say "[unicode 93]"; end
if; end repeat; insta-quit;
To list-print:
remove entry 86 from L; repeat with x running through L begin; say
"[unicode 34][x][unicode 34], "; end repeat; say "[unicode 34][unicode 34]";
Out of curiosity, I wondered how a quine for Tads 3 would look like.
Turns out you can just use an existing C++ one with only minor
modifications :P
I guess I can't claim "credit" for this one ;P The C++ original is by
David Rogers and can be found here:
http://www.nyx.net/~gthompso/self_c++.txt
OK, here goes:
#include "tads.h"
#define M(TEMPLATE) tadsSay(TEMPLATE + '(' + #@TEMPLATE + ');\n}');
main(a)
{
M('#include "tads.h"\n#define M(TEMPLATE) tadsSay(TEMPLATE + \'(\' +
#@TEMPLATE + \');\\n}\');\bmain(a)\n{\n\tM');
}