This page is a truly naked, brutalist html quine.
October 23, 2020 5:39 AM   Subscribe

<p>The world of esoteric programming is filled with examples of people stretching the rules to breaking point, and misusing technology in creative ways. In particular (for example) I love <a href='http://wiki.secretgeek.net/quine'>quines</a>. Quines are programs which output their own source code. Life is a Quine.</p>

<a href='https://www.metafilter.com/130059/yo-dawg'>Previously</a>, <a href='https://www.metafilter.com/91544/What-is-this-posts-title'>previously</a>, <a href='https://www.metafilter.com/68463/This-is-the-title-of-this-post'>previously</a>.
posted by Cardinal Fang (23 comments total) 19 users marked this as a favorite
 
HTML error reported to mods. Or is it!? 🤪
posted by terrapin at 5:47 AM on October 23, 2020 [5 favorites]


This is great fun.

Also, today I learned that I have strong opinions about whether or not "life is a quine" is a true statement.

Also, also, someone who isn't me should edit the naked objects <a href="https://en.wikipedia.org/wiki/Naked_objects">wikipedia page.</a> I'm certainly not an expert, but I care more about both programming and architecture than most people. . . and reading it a third time was not helpful.
posted by eotvos at 6:18 AM on October 23, 2020


I don't know of a programming language that implements quines more tidily than Applesoft BASIC.

1 LIST

is all it takes.
posted by flabdablet at 6:28 AM on October 23, 2020 [4 favorites]


I had never met this concept before; I was intrigued when they started putting an example in a compiled language together but also vaguely uneasy with the eventual solution. I guess it's because I'm used to thinking of string literals as grey blocks of non-functional stuff and having code where correct behavior critically depends on a long string being exactly correct sets my alarm bells ringing.
posted by each day we work at 6:59 AM on October 23, 2020


Joke's on you, Cardinal Fang, MeFi just interpolates <br> tags for vertical whitespace!

Also I love quines and appreciate this post deeply. Programming quines are one of those subjects that always both please me and remind how basically shallow most of my programming knowledge is; creating them is a deep systems engagement with the structure and tools of the languages and the systems they operate in, which is a lot farther than I generally want to go for my workmanlike "I don't care about the code, I just want to make a thing that does a thing" code sculpting.
posted by cortex at 7:52 AM on October 23, 2020 [2 favorites]


Life is a quine, but a quine that's figured out how to create useful errors and variation during the self-copying phase. It's remarkably robust.
posted by Nelson at 8:29 AM on October 23, 2020


Although life does it the 'cheating' way, by copying its own source from storage. If life were a Python program, it would be print(open(__file__).read()).
posted by Pyry at 9:04 AM on October 23, 2020 [1 favorite]




This is really cool stuff. I read Godel, Escher, Bach at a formative age and it kicked off a lifelong interest in this sort of thing.

This isn't quite the same thing but it reminds me a bit of an inifinitely-expanding self-referential paragraph I thought up once. It goes like this:

The first letter of this paragraph is T. The second letter is h. The third is e. The fourth is l...
posted by treepour at 12:47 PM on October 23, 2020 [6 favorites]


My JavasScript quine:
a="console.log(\"a=\"+JSON.stringify(a)+\";\"+a)";console.log("a="+JSON.stringify(a)+";"+a)
A slightly cheaty version:
a="console.log("a="+JSON.stringify(a)+";eval(a)")";eval(a)
And, for what it's worth, an empty file is trivially a JavaScript quine.
posted by sjswitzer at 12:48 PM on October 23, 2020 [1 favorite]


How about palindrome polyglot quines?
posted by sjswitzer at 12:54 PM on October 23, 2020


Ken Thompson's Turing Award lecture is relevant.

I was tickled by his example because I once wrote a compiler which, when bootstrapped, would treat escaped characters, e.g. '\t', '\n', as whatever happened to do. That is, \ then n was translated to \n. It worked, but the only way to know that it did was to run it or look at the binary.
posted by sjswitzer at 12:59 PM on October 23, 2020


This Unix script is a pretty close second to Applesoft BASIC:
#!/bin/cat
posted by flabdablet at 8:22 PM on October 23, 2020 [2 favorites]


Some fun ideas here but the definition of a quine usually stipulates, “without reading any input.”
posted by sjswitzer at 9:29 PM on October 23, 2020


#!/bin/cat

This script's only purpose is to emit its
own source code on standard output. As you
will gather from its shebang line, it is
written in the nameless language implemented
by the standard interpreter /bin/cat, available
on almost every POSIX operating system.

The *only* operation defined in this language
is quining, i.e. outputting the script's own
source code. In particular, the language does
*not* define any way to perform arithmetic
or logical operations, manipulate variables,
define functions, read input, insert implied
semicolons, or almost all of the other things
easily achievable in more complete computer
languages. But it's *really* good at quining.

In fact, because quining is indeed the only
operation implemented by the interpreter, no
specific syntax is required to make it happen;
any old script will do, this one included.

So if writing a quine is what you're setting out
to do, and you're looking for a language to
implement it in, the /bin/cat interpreter seems
like a pretty robust choice.
posted by flabdablet at 12:17 AM on October 24, 2020 [2 favorites]


The first character of this sentence is a T; the second is an h… somewhere near the middle there's an ellipsis or two… the second-last is a t and the last is a dot.
posted by flabdablet at 12:32 AM on October 24, 2020 [1 favorite]


...profit
posted by flabdablet at 12:33 AM on October 24, 2020


an empty file is trivially a JavaScript quine

If you chmod +x it, it's trivially a Unix executable quine as well.
posted by flabdablet at 12:44 AM on October 24, 2020 [2 favorites]


It's only a quine if it's from the Quine region of France; otherwise it's just sparkling shell pain.
posted by cortex at 8:08 AM on October 24, 2020 [4 favorites]


Ah, yes, the empty executable holds an important place in UNIX lore. A shell script returns success by default but can “exit” with a status code to indicate failure. So the “false” command was simply “exit 1” but the “true” command was an empty file. Was.

Due to some unfortunate events, including neglecting to trademark “Yellow Pages,” AT&T went from a company that cared little about intellectual property (save patents) to one that cared very very much. And this is how they came to place a copyright notice in an otherwise empty file. John Cage would be proud.
posted by sjswitzer at 8:59 AM on October 24, 2020 [3 favorites]


This one, written in Bourne shell, looks at first glance like "proper" quine logic that doesn't "cheat"; however, paying close attention to what it's actually doing reveals that the #!/bin/cat foolery above really does involve no more I/O than this does.
#!/bin/sh
q=\' s='#!/bin/sh
q=\%s s=%s%s%s
printf "$s" "$q" "$q" "$s" "$q"
'
printf "$s" "$q" "$q" "$s" "$q"
In neither case does the script itself request any file I/O, unlike the Python "cheat" mentioned above.

Any interpreted POSIX script works by having the script itself supplied as standard input to the interpreter named on its shebang line. And as long as the script is smaller than a single 4KiB MMU page, the OS's I/O subsystem will already have buffered it in order for the OS to be able to parse the interpreter name and invoke the interpreter; there is no more disk input required than that needed to allow any script to be executed in the first place.

The truly beautiful part about the Applesoft BASIC
1  LIST
solution is that it really does re-create its own source code. If you go looking in the chunk of RAM where that program is stored, you won't find any of the ASCII characters it outputs. Applesoft programs get tokenized and stored as a non-text binary data structure as soon as they're typed in on the keyboard. The LIST command reverses that process in order to reveal the source code.
posted by flabdablet at 10:09 AM on October 24, 2020 [1 favorite]


The first letter of this paragraph is T. The second letter is h. The third is e. The fourth is l...

The first character of this sentence is a T; the second is an h… somewhere near the middle there's an ellipsis or two… the second-last is a t and the last is a dot.


Would it be possible to write a paragraph that states "The last character in this paragraph is a dot. The second is a T. The third is an A..." and ? Seems like no, but it'd be interesting to see a proof that proves it's impossible.
posted by Mr.Encyclopedia at 10:27 PM on October 24, 2020


Depends how seriously you take your impossibilities.

On one level it's obviously not impossible to write such a paragraph, because you've just done it.

It's when you adopt the implicit additional stipulation that the paragraph you're specifying has to be both in-principle constructible and true that things get kind of tricky.

In the particular case you've raised, the way to attack it is to start filling in the gap where the ellipsis is, based on the information available, and work out whether you're bound to hit a contradiction or not. So, starting with
The last character in this paragraph is a dot. The second is a T. The third is an A...
and assuming that "second" and "third" in this context mean second-last and third-last, we can fill in the last three letters and get
The last character in this paragraph is a dot. The second is a T. The third is an A...AT.
We now have pretty much a totally free choice about how to go about filling in the rest of the ellipsis. Essentially we can put anything we like there, as long as it ends with "AT." and results in something readable as English.

But if we want to adhere strictly to the pattern that every sentence in the paragraph is about a character in the paragraph, and that all sentences have the same form, and that the descriptions occur in a consistent order from the last character back, then we've already run aground. The last sentence in the paragraph would, it seems, necessarily need to end with "is a ?." where ? is some single letter. But since the ending we've already got is "AT.", that doesn't match.

If we relax the rules so that letter case doesn't matter and spaces are ignored, things look better: under the relaxed rules, the ending of "is a T." does match the ending "AT." So we can keep on working backwards, filling in more of the gap the ellipsis represents with sentences consistent with the form, until another T turns up for the last sentence to refer to:
The last character in this paragraph is a dot. The second is a T. The third is an A. ... is a T.

The last character in this paragraph is a dot. The second is a T. The third is an A. ... The *th is a T.
And now we can fill in the rest:
The last character in this paragraph is a dot. The second is a T. The third is an A. The fourth is an S. The fifth is an I. The sixth is an H. The seventh is a T.
This is constructible because we just constructed it, and true by inspection, but it's deeply disappointing. Because although the thing is self-documenting, it's not completely self-documenting and from the get-go it looked like that's what it was trying to be.

Unfortunately there's nothing to be done about that. If it were completely self-documenting it would have a whole sentence for each letter, and since each sentence contains multiple letters by inspection, there's no way to make that one-to-one correspondence work with any finite paragraph length; the ellipsis, therefore, never goes away and completeness is unachievable.

In order to get completely self-documenting sentences of finite length we need to stop caring about where the documented characters occur, so that each documenting sentence can refer to multiple characters; the correspondence then can be made to work.
posted by flabdablet at 12:35 AM on October 25, 2020 [1 favorite]


« Older Wait for Version 3   |   Bongo Cat Newer »


This thread has been archived and is closed to new comments