Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Quine for Inform 7

244 views
Skip to first unread message

Juhana Leinonen

unread,
Dec 26, 2007, 1:34:52 PM12/26/07
to
During the slow holidays I started to think if making a quine in Inform
7 would be possible. Quine is a computer program that does nothing else
but prints its own complete source code (see
http://en.wikipedia.org/wiki/Quine_%28computing%29 ). Turns out it is
possible and here it is for your amusement: a quine for Inform 7! If you
paste the following code to I7 and run it, the output should be the
exact same code.

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]";

Nikos Chantziaras

unread,
Dec 27, 2007, 5:06:18 AM12/27/07
to
Juhana Leinonen wrote:
> During the slow holidays I started to think if making a quine in Inform
> 7 would be possible. Quine is a computer program that does nothing else
> but prints its own complete source code (see
> http://en.wikipedia.org/wiki/Quine_%28computing%29 ). Turns out it is
> possible and here it is for your amusement: a quine for Inform 7!

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');
}

0 new messages