[comp.misc] self-reproducing programs

lang@bigburd.UUCP (04/22/87)

I recall some discussion in comp.lang.prolog a while back
(last summer?) about self-reproducing programs
(programs which print their own text when they are run).
Did anybody keep that information, by any chance?
Does anybody have any references to any literature
or any other information about self-reproducing programs?
Many thanks.

----------------------------------------------------------------------------
Francois-Michel Lang			      Daytime phone:  (215) 648-7490
Paoli Research Center, Unisys Corporation        lang@bigburd.PRC.unisys.COM
Dept of Comp. & Info Science, U of PA                     lang@cis.upenn.edu

-- 
----------------------------------------------------------------------------
Francois-Michel Lang			      Daytime phone:  (215) 648-7490
Paoli Research Center, Unisys Corporation        lang@bigburd.PRC.unisys.COM
Dept of Comp. & Info Science, U of PA                     lang@cis.upenn.edu

keeshu@nikhefk.UUCP (Kees Huyser) (04/24/87)

In article <3248@bigburd.PRC.Unisys.COM> lang@bigburd.PRC.Unisys.COM (Michel Lang) writes:
>
>I recall some discussion in comp.lang.prolog a while back
>(last summer?) about self-reproducing programs
>(programs which print their own text when they are run).
>Did anybody keep that information, by any chance?
>Does anybody have any references to any literature
>or any other information about self-reproducing programs?
>Many thanks.
>
>----------------------------------------------------------------------------
>Francois-Michel Lang			      Daytime phone:  (215) 648-7490
>Paoli Research Center, Unisys Corporation        lang@bigburd.PRC.unisys.COM
>Dept of Comp. & Info Science, U of PA                     lang@cis.upenn.edu


Try the following simple Applesoft Basic program :


	10 PRINT "HELLO, WORLD"
	20 LIST
	30 GOTO 10

I think this is what you were looking for :-)

-- Kees

|  UUCP	  : keeshu@nikhefk.uucp  or {[wherever]!seismo}!mcvax!nikhefk!keeshu
|  BITNET : keeshu@hasara5.bitnet
|  FIDO   : kees huyser at 28/9 (SagaNet MacBBS) or 500/11 (HCC_Amsterdam_1)
|  SNAIL  : kees huyser, NIKHEF-K, PO Box 4395, 1009 AJ Amsterdam, Netherlands

jaw@ames.UUCP (James A. Woods) (04/24/87)

#  "Sixty minutes of thinking of any kind is bound to
   lead to confusion & unhappiness." -- James Thurber

     A formal discussion may be found in Hartley Rogers' classic text
"Theory of Recursive Functions and Effective Computability", McGraw-Hill,
1967, p. 188-190.  The existence of such programs date back to a theorem
of von Neumann, though the text uses a consequence of the fixpoint
"recursion theorem" of Kleene in proof.

     More leisurely, one might peek at the European Unix User's Group
newsletter (EUUGN vol. 3, no. 4) for the article "Some Self-Reproducing
Programs" by Theo de Ridder.

     Or, for the truly lazy, just compile and run

	p="p=%c%s%c;main(){printf(p,34,p,34);}";main(){printf(p,34,p,34);}

for a demonstration of such introspective behavior.  The 66-byte C version
was the culmination of a lively net.sources discussion in 1984.  However,
some masochists were composing much more elaborate self-reproducing code
in FORTRAN at various institutions during the 1950's.

     -- James A. Woods (ames!jaw)

kees@praxis.UUCP (04/28/87)

In article <3248@bigburd.PRC.Unisys.COM> lang@bigburd.PRC.Unisys.COM (Michel Lang) writes:
>
>   ... self-reproducing programs ...
>

Some time ago there were some self rep palindromic C programs in comp.lang.c (or
whatever it's called). Anyway, here are some things to start with:

BASIC: (without line number but that's easy enough)
a$="a$=:print(left$(a$,3)+chr$(34)+a$+chr$(34)+right$(a$,4))":print(left$(a$,3)+chr$(34)+a$+chr$(34)+right$(a$,4))

Interpreted BASIC: 
10 LIST 10

Algol68:
([]CHARs="([]CHARs="";print(2*s[:10]+2*s[10:]))";print(2*s[:10]+2*s[10:]))

BASIC: (self rep palindromic program)
1 ')$a(tnirp:tnirp:txen:;))1,i,$a($dim(tnirp:701ot1=irof:)4,$a($thgir+)43($rhc+$a+)43($rhc+)6,$a($tfel=$a:"1 ')$a(tnirp:tnirp:txen:;))1,i,$a($dim(tnirp:701ot1=irof:)4,$a($thgir+)43($rhc+$a+)43($rhc+)6,$a($tfel=$a 2"=$a 2
2 a$="2 a$=left$(a$,6)+chr$(34)+a$+chr$(34)+right$(a$,4):fori=1to107:print(mid$(a$,i,1));:next:print:print(a$)' 1":a$=left$(a$,6)+chr$(34)+a$+chr$(34)+right$(a$,4):fori=1to107:print(mid$(a$,i,1));:next:print:print(a$)' 1

I haven't tested the last one yet so there may be inaccuracies.
The idea certainly is correct.

Kees
-- 
---------------------------------+---------------------------------------------
Kees (Dutch Courage) Goossens    | "En nu lieve kijkbuis kinderen: Oogjes dicht
kees@praxis.uucp or:             | en snaveltjes toe. Slaap lekker!"
...!seismo!mcvax!ukc!praxis!kees | -- Meneer de Uil.

lwall@sdcrdcf.UUCP (Larry Wall) (05/06/87)

Keywords:


#!/bin/sh

# Okay, as long as we're back into self-reproducing programs, here's the
# shortest self-reproducing nroff script (that doesn't cheat) that I have
# been able to come up with.

# (Cheating is to use no . or ' commands, or to .so your input file.)

# If you come up with a shorter one, I want to see it!

echo Extracting self.n
sed 's/X//' >self.n <<'!STUFFY!FUNK!'
X.ec8
X.emZZ
X.nryy1000-12
X.nrzz100-1
X.nf
X.deXX
X.tr88n(yy
X88!88!88$1
X.tr88n(zz
X.amZZ..
X88!88!.XX88$1
X.nrnl0-1
X...
X..
X.XX.ec9
X.XX.emZZ
X.XX.nryy1000-12
X.XX.nrzz100-1
X.XX.nf
X.XX.deXX
X.XX.tr99n(yy
X.XX99!99!99$1
X.XX.tr99n(zz
X.XX.amZZ..
X.XX99!99!.XX99$1
X.XX.nrnl0-1
X.XX...
X.XX..
!STUFFY!FUNK!
exit

Larry Wall
{allegra,burdvax,cbosgd,hplabs,ihnp4,sdcsvax}!sdcrdcf!lwall