|
Forum Index : Microcontroller and PC projects : "Quine" in MMBasic
| Author | Message | ||||
| William Leue Guru Joined: 03/07/2020 Location: United StatesPosts: 405 |
A "Quine" is a self-replicating program: when run, it emits exactly its own source code, letter for letter. People have written Quines in many different programming languages, including C, C++, Java, and various dialects of BASIC. Here is a Quine in MMBasic. It was originally written by Ariel Scolnicov in some unknown BASIC dialog; I have adapted it so that it runs correctly on CMM2 and probably on all Maximites. It is pretty straightforward except for some tricky aliasing of quote signs so that they work in both the executable and clone contexts. Enjoy! -Bill 'This is a QUINE in MMBasic: that is, a self-replicating program ' Originally written by Ariel Scolnicov ' Adapted for MMBasic by William M Leue 5/15/2021 for i = 1 to 2 restore for j = 1 to 21 read a$ b$ = "" for k = 1 to len(a$) if i = 1 and asc(mid$(a$, k, 1)) = 35 then b$ = b$ + chr$(34) else b$ = b$ + mid$(a$, k, 1) end if next k if i = 1 then print b$ else print "data ";chr$(34);b$;chr$(34) end if next j, i data "'This is a QUINE in MMBasic: that is, a self-replicating program" data "' Originally written by Ariel Scolnicov" data "' Adapted for MMBasic by William M Leue 5/15/2021" data "for i = 1 to 2" data "restore" data "for j = 1 to 21" data "read a$" data "b$ = ##" data "for k = 1 to len(a$)" data "if asc(mid$(a$, k, 1)) = 35 then" data "b$ = b$ + chr$(34)" data "else" data "b$ = b$ + mid$(a$, k, 1)" data "end if" data "next k" data "if i = 1 then" data "print b$" data "else" data "print #data #;chr$(34);b$;chr$(34) data "end if" data "next j, i" |
||||
| William Leue Guru Joined: 03/07/2020 Location: United StatesPosts: 405 |
I forgot to mention that the name "Quine" with reference to a self-rep program was coined by Douglas Hofstadter in his book "Godel, Escher, Bach", in homage to the American philosopher Willard Van Oman Quine. Grrrr, why doesn't the bulletin board software let me include the umlaut over the 'o' in Godel? Dumb! -Bill |
||||
| Geoffg Guru Joined: 06/06/2011 Location: AustraliaPosts: 3308 |
Intriguing idea. BTW some indenting would make it much easier to understand. Perhaps that is lost in the cloning process? Geoff Geoff Graham - http://geoffg.net |
||||
| William Leue Guru Joined: 03/07/2020 Location: United StatesPosts: 405 |
I deliberately did not indent to keep in the spirit of the original, but of course indentation is possible so long as both the "active" and "clone" copies of the program have the identical indentation. -Bill |
||||
| MustardMan Senior Member Joined: 30/08/2019 Location: AustraliaPosts: 175 |
Nice! You should check out "the art of code" by 'Dylan Beattie' on youtube (1hr). I have watched it multiple times, and even at an hour I watch it at 1x. Cheers, |
||||
| William Leue Guru Joined: 03/07/2020 Location: United StatesPosts: 405 |
I watched it: pure fun! -BIll |
||||
| The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2025 |