Path: utzoo!mnetor!uunet!mcvax!prlb2!kulcs!luc From: luc@kulcs.UUCP (Luc Van Braekel) Newsgroups: comp.lang.pascal Subject: Re: Self-replicating programs Message-ID: <1092@kulcs.UUCP> Date: 28 Dec 87 22:22:28 GMT References: <52@qucis.UUCP> <188@goofy.megatest.UUCP> Organization: Kath.Univ.Leuven, Comp. Sc., Belgium Lines: 36 Summary: here is a machine-independant self-replicating pascal program In article <188@goofy.megatest.UUCP>, djones@megatest.UUCP (Dave Jones) writes: > The "quotemark" problem is the only hard problem. How do you make > this program character-set independant? (The one I posted will > work just as well on an EBCDIC machine as on an ASCII machine. > This posting does not contain everything I want ot know on > self-replicating programs. The quotemark problem is not so difficult to solve. Here is a slightly modified version of the program I posted some time ago. This version is character-set independant. Again, this is an ugly but very short Pascal program that doesn't use external files etc. At least one thing that's shorter in Pascal than in C ! :-) program self (output); const q = ''''; var i,j: integer; a: array[1..8] of packed array[1..59] of char; begin a[1] := 'program self (output); const q = ''''''''; '; a[2] := 'var i,j: integer; '; a[3] := ' a: array[1..8] of packed array[1..59] of char; begin '; a[4] := 'for i := 1 to 3 do writeln(a[i]); '; a[5] := 'for i := 1 to 8 do begin write('' a['',i:0,''] := '',q); '; a[6] := 'for j := 1 to 59 do begin write(a[i][j]);if a[i][j]=q '; a[7] := 'then write(a[i][j]) end; writeln(q,'';'') end; '; a[8] := 'for i := 4 to 8 do writeln(a[i]) end. '; for i := 1 to 3 do writeln(a[i]); for i := 1 to 8 do begin write(' a[',i:0,'] := ',q); for j := 1 to 59 do begin write(a[i][j]);if a[i][j]=q then write(a[i][j]) end; writeln(q,';') end; for i := 4 to 8 do writeln(a[i]) end. +-----------------------------------+------------------------------------+ | Name : Luc Van Braekel | Katholieke Universiteit Leuven | | UUCP : luc@kulcs.UUCP | Department of Computer Science | | BITNET : luc@blekul60.bitnet | Celestijnenlaan 200 A | | Phone : +(32) 16 20 0656 x3563 | B-3030 Leuven (Heverlee) | | Telex : 23674 kuleuv b | Belgium | +-----------------------------------+------------------------------------+