@t[The Escher Quine]~~META:date created = 2019.08.08., 19:06~~ //[[az_escher-quine|(magyarul)]]// Well, folks, this is going to be a bit complicated. The title is from the names of two gentlemen, of whom the latter one is used as a common noun, let’s start with him. Willard Van Orman Quine (1908–2000), one of the most influential philosophers of the twentieth century, mathematic logician, language philosopher, creator of several important thoughts, like the Quine paradox. This paradox is happening to me when learning a language. @s5[The Quine Paradox] @jr[ablakzsiraf]For example I’m seeing a picture with several things. (This is from children’s lexicon Ablak–Zsiráf, 11th edition, 1971.) This was made for Hungarian native children who can read, the text is designed for their ages and knowledge levels, but let’s imagine I’m viewing it for the purpose of language learning. (I’m really using books written for young native Latvian schoolchildren.) At the middle, for the man dressed in white, there’s PÉK written, and he puts something into something with a peel. Or takes it out. I speak no Hungarian, I don’t know this word, and I can’t recognize what happens on the picture. Possibly I am a child and I never saw a baker in work. Will I make it out that they are maize he is placing in the krāsns and this man is a maiznieks? And this is a simple case since in reality, when a toddler learning their native tongue is hearing the name of something the situation is most frequently ambivalent: mom points at an object, but there are a lot of objects to that direction, and if the child identifies the correct one, maybe mom takes it in her hand: is that word the name of that exact object, or should s/he abstract to a category of objects, and if yes, which one, or to an attribute of the object, or some action regarding to the object? I saw a video about someone who knows the names of one thousand objects, each name is for one individual object, but she cannot abstract from either one to a group or category of objects, any attribute of objects, she is unable for any abstraction. However she is an adult – but a dog. We expect a toddler hearing the word //labda// to extend the association in a short while from the certain individual object to an abstraction of all objects that are spherical toys, can roll, fly and bounce when thrown, and if s/he is a Hungarian child we expect them to distinguish it from the word and category of object //golyó// (which also belongs to the vocabulary of their age), what’s not a simple task for an adult native English speaker learning Hungarian, who considers both //ball.// @s5[The Quines] Professor Quine was working such things, and this gave the motivation for Douglas Hofstadter to use his name for a special form of recursion. His book //Gödel, Escher, Bach: An Eternal Golden Braid,// published 1979, gives the name //quine// to computer programs that display their own source codes. For example, the following ZX Spectrum program: @zxcolor[0f0|10 PRINT "This is a text here"] @zxcolor[0f0|20 PRINT "(two lines)"] will display this when run: @zx[This is a text here] @zx[(two lines)] So this isn’t a quine. To make it a quine, it should display the text shown in green above. But it will display that only if we type this: @zxcolor[f00|10 PRINT "10 PRINT ""This is a text here"""] @zxcolor[f00|20 PRINT "20 PRINT ""(two lines)"""] (we have to type double quotation marks in a quotation mark to display a quotation mark). But by changing the text to this red one, the expectation became the red text to be displayed, not the green one. It would be a quine only that case. I believe it’s obvious it isn’t easy to write a quine. However, there are single line quines, like this little program in Python: print((lambda s:s%s)('print((lambda s:s%%s)(%r))')) which, when run on a machine knowing Python, will display, of course print((lambda s:s%s)('print((lambda s:s%%s)(%r))')) So, //to write// a quine is an interesting brain exercise, but //running// it is total boredom, we know exactly what will happen. The same text will appear, seen previously. But programmers love to play, so several kinds of additional quines were made. @s5[Quine Variants] **Cheating quines.** A quine has to create its own source code again, and not to peek in the memory or the disk and read the source. This is what cheating quines do. Of course, any home computer understanding BASIC language, when given a program which consists of 1 LIST will display 1 LIST – so this is a quine, but it’s cheating, it doesn’t create the text that goes ''1'' (space) ''L'' ''I'' ''S'' ''T'', just it reads the program from the memory and lists it. **Ouroboroses.** Ancient Greeks, who had a word for all the things frequently happening in life, //ouroboros// meant a serpent biting its own tail. I don’t know when do snakes such a thing, but ouroboros programs do. We write a program in a given language (say, C+`+) which produces a source code of a program written in another language (say, Java); and this latter program produces the source code of the original C+`+ program. But this is simple. [[https://github.com/mame/quine-relay|Yusuke Endoh]] wrote a program in Ruby language, which produces a program in Rust language, which produces one in Scala language, which produces one in Scheme language, and so on, in alphabetical order till Zsh, then comes A+, Ada, AFNIX and so on through the alphabet, reaching Ruby language, totalling //one hundred and twenty-eight// programming languages used to get the same Ruby language source code back it was begun with. **Multiquines.** A group of programs written in several different languages, of which every one is able to display the source code of any member of the group (including its own), and we can choose with a parameter which one we want. **Radiation hardened quines.** Quines which can display their source code even if we remove any (single) character, but by replacing that character. Obviously, we can invent more of these. Now I’ve just invented the //mutating quine,// inspired by the radiation hardened one: it displays its source code, but it may happen that one character will be missing, or there will be another one, or one of them will be replaced by another character, but it still is a quine and can display its own source code, but with a chance to changes like these, and so on, so if we run the original quine a hundred times we get a hundred quine children which differ from the original at a single point only, and if we run these a hundred times each we get ten thousand quine grandchildren which differ now at two points, and so on, and so on. I’ve got no idea if such a thing can be written at all. With my programmer’s knowledge I can’t get a hint. But all the program types mentioned so far match in one thing. When we run them, we’ll get a //text.// Their own source code or that of another program, anyhow, a text. You can open it in a text editor, you can read it, you can print it. I wrote this article on a program with an output which isn’t text but action. However, it is a quine, too. It’s the //Escher quine.// @s5[The Escher Quine] {{ escher-quine.mp4 }} You can see on the video Daniel A. Nagy typing a program on [[https://en.wikipedia.org/wiki/ZX_Spectrum|ZX Spectrum]]. They do it so on Sinclair machines, there’s an editor window on the bottom of the screen, one line tall, and if it’s filled it grows upwards; when ready (Enter pressed) it jumps to the upper screen part. Typing is very special on the colorful keyboard of Spectrum: the cursor isn’t a line nor a block but a flashing letter, either one of @zxinv[K] @zxinv[E] @zxinv[L] @zxinv[C] @zxinv[G], and it depends on the letter which symbol or word gives the key pressed. For example, key @basic[N] in mode @zxinv[L] gives lowercase letter @zx[n], in mode @zxinv[C] uppercase @zx[N], in mode @zxinv[K] the statement word @zx[NEXT], in mode @zxinv[E] the function name @zx[INKEY$], and it knows also word @zx[OVER] and the @zx[,] comma. This single key. This is a unique speciality of Sinclair machines, it was a pioneering invention at the beginning of the eighties, and by the way, it’s adored by Spectrum fans. At least me. So this is why @zxinv[K] and @zxinv[L] are changing there all the time, and this is why BASIC words are appearing at once and not letter by letter, because they are single key presses. The keyboard contains all the vocabulary of Spectrum BASIC on purpose. @jc[spectrum] Now, having explained what happens on the video I tell you //it isn’t// what happens on the video. It doesn’t show Daniel’s typing of the program but the running of the program. This is a quine since it outputs its own source code, but not as a text but it pretends typing it. Imitation is almost perfect. We can know it’s actually an imitation from that words like @zx[RESTORE], @zx[READ], @zx[DATA], @zx[FLASH], @zx[LEN], @zx[STR$] and @zx[CHR$] are appearing without the cursor changing to @zxinv[E], however on a real Spectrum (or even an emulator) these words cannot be reached without changing the cursor (by pressing @basic[Caps Shift] and @basic[Symbol Shift] at the same time) to @zxinv[E], and after that we have to move a finger on the key of the respective keyword, what takes time, and @zxinv[E] should be visible for a bit of time if Daniel would be typing, himself. But who cares? Universe as a whole cannot be described by a model simpler than itself. Spectrum is a tiny universe, too. @s5[The Name] The name @basic[Escher-quine] was given it by myself. The second gentleman from the title, M. C. Escher created this famous drawing: @jc[lw355-mc-escher-drawing-hands-1948] Its title is //Drawing Hands (Tekenen),// published in 1948. Of course, Hofstadter featured this drawing in his book mentioned, Escher’s name is included in its title. But this way, @basic[Escher quine], I couldn’t find on the net, so there’s a chance that I’ve invented it. According to my definition, //an Escher quine is a quine which doesn’t reproduce its source code (its own finished state) but the **creation** of its own source code.// @zx[(© Láng Attila D., 2019.)] The procedure isn’t completely unknown in the history of computing. There are inscriptions in many movies that appear as if a person would be typing them into a computer; for example, in the 1979 movie [[https://www.youtube.com/watch?v=IJaypC51Dds|The Black Hole.]] In computing literature, once there was a category of magazines which was written and distributed as programs, and in a part of these, the pages weren’t simply displayed but the letters were typed one after another, as if a person would be typing them at that very moment. I wrote one, too. But combining this with a quine, writing a quine which imitates its own entering – this is a world record. @s5[The Code of the Quine] Since my reader’s browser isn’t a Spectrum, it took some effort to describe the Spectrum with a model simpler than itself and to create a listing that looks like on a real Spectrum. At least in the mine it does. It appears on grey background with black letters, with a real Spectrum font. I hope it looks like this at my reader, too. That way it’s the real one.