[futurebasic] Ken's Quine

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : January 2009 : Group Archive : Group : All Groups

From: Ken Shmidheiser <kshmidheiser@...>
Date: Fri, 23 Jan 2009 06:55:40 -0500
Okay, it was a slow night. Anyway, it's been way too serious around  
here. So since I have about forgotten how to dim a long, I decided  
for practice to write a little program that does one thing: replicate  
its own source.

Hence was born "Ken's Quine."

Yes, I know it has a tiny flaw. See if you can find it. Better yet,  
let me challenge you listers to create your own new and improved self- 
replicator and post it here for our edification. The more obtuse and  
orthogonal (gotta love RP) to conventional thinking, the better it  
will be.

Maybe we can even resurrect Jay Reeve and have him do it with  
pointers in two lines. Then again, RP will probably create a fuzzy- 
logic genetic algorithm that browns out the northeast power grid when  
compiled. Bernie and Steve Van Voorst can slap on a Cocoa-like GUI  
and Brian Stevens will follow through with a volume of cross-platform  
XML documentation. Shoot, Robert Covington can add a self-replicating  
GWorld pun generator-- hey, pun spelled backwards is nup, and a nup  
is a nup.. (If that ain't a quine, then nothing is.)

Deep can add a quine bar code generator that replicates its own  
mirrored UPCs-- maybe even Code 39s. Herbie and Alain and Pierre can  
handle the German and French localizations, respectively. Michele and  
Carminati can take care of the Italian. Oh, we can't forget Piet and  
Yoshiyuki. We can probably even press Joe Lewis Wilkins to do some  
Spanish. And Andy can make sure every occurrence of "color" is fixed  
to read "colour."

Chris Wyatt can have his kids document it on the FB Wiki and George  
Beckman can be sure that teachers in every school system have it  
added to their grading applications so all the kids can replicate  
straight As for themselves. Waverly can scrub the C code. Laurent can  
compress the whole thing to .00053 nano-bytes and post for FTPing to  
the world. Rich Love can fix it to output to any terminal made in the  
last 50 years, and Al Staffieri can translate it to run on any  
version of BASIC ever written.

Mark Chappell can put a commemorative copy of the code in a  
hermitically sealed container and bury it for posterity at the South  
Pole during his next Antarctic trek. Stu Cram can handle distribution  
at the opposite end of the world. Max Taylor can quine it into OOP  
(or would that be POO in quine-speak?) And Ted Spencer, Paul Bruneau  
and John Grimsley can handle quality control. When Joe Lertola  
figures out tabs, we can show multiple quine iterations in self- 
replicating panes. And Walter Lenk can translate into for sed and awk  
on Unix. And Patrick can containerize it. And Charlie Poole can put  
the whole project into a nib.

Dang I'm excited now.

Why this might be so fun that even Mel and tedd might come back.

Compiles fine in FB 5.1.3.

Ken Quineheiser

/*

    Ken's Quine

    Simpleton project that duplicates its own source code.

    Guaranteed to be good for nothing, but I bet you still

    Ken Shmidheiser
    January 23, 2009

     (I'll leave it as a trivial exercise to the reader
      to replicate these comments in the code)

*/

_codeLines = 25
local fn Quine
dim as str255 a, b
dim as long   i, j, k
for i = 1 to 2
restore
for j = 1 to _codeLines
read a
b = ""
for k = 1 to a[0]
if asc( mid$( a, k, 1 )) = 35 then b = b + chr$(34) else b = b + mid$ 
( a, k, 1 )
next
if i = 1 then print " "; b else print " data "; chr$(34); b; chr$(34)
next
next
end fn
local fn DoDialog
dim as long evnt, id
evnt = dialog(0) : id = dialog(evnt)
if (evnt = _wndClose) then end
end fn
on dialog fn DoDialog
window 1,"Quine Self-Replicator",( 0,0 )-( 420,630 )
fn Quine
do:handleevents:until gFBQuit
data "_codeLines = 25"
data "local fn Quine"
data "dim as str255 a, b"
data "dim as long   i, j, k"
data "for i = 1 to 2"
data "restore"
data "for j = 1 to _codeLines"
data "read a"
data "b = ##"
data "for k = 1 to a[0]"
data "if asc( mid$( a, k, 1 )) = 35 then b = b + chr$(34) else b = b  
+ mid$( a, k, 1 )"
data "next
data "if i = 1 then print # #; b else print # data #; chr$(34); b; chr 
$(34)"
data "next
data "next
data "end fn"
data "local fn DoDialog"
data "dim as long evnt, id"
data "evnt = dialog(0) : id = dialog(evnt)"
data "if (evnt = _wndClose) then end"
data "end fn"
data "on dialog fn DoDialog"
data "window 1,#Quine Self-Replicator#,( 0,0 )-( 420,630 )"
data "fn Quine"
data "do:handleevents:until gFBQuit"