Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 03:26 19 Nov 2025 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : "Quine" in MMBasic

Author Message
William Leue
Guru

Joined: 03/07/2020
Location: United States
Posts: 405
Posted: 06:42pm 15 May 2021
Copy link to clipboard 
Print this post

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 States
Posts: 405
Posted: 07:31pm 15 May 2021
Copy link to clipboard 
Print this post

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: Australia
Posts: 3308
Posted: 09:28pm 15 May 2021
Copy link to clipboard 
Print this post

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 States
Posts: 405
Posted: 07:38pm 16 May 2021
Copy link to clipboard 
Print this post

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: Australia
Posts: 175
Posted: 09:18pm 16 May 2021
Copy link to clipboard 
Print this post

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 States
Posts: 405
Posted: 11:19pm 17 May 2021
Copy link to clipboard 
Print this post

I watched it: pure fun!
-BIll
 
Print this page


To reply to this topic, you need to log in.

The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2025