home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!mcsun!uknet!warwick!dcs.warwick.ac.uk!sunserver1.aston.ac.uk!cs_mac35.aston.ac.uk!user
- From: elsworthef@aston.ac.uk (Ted Elsworth)
- Newsgroups: comp.lang.ada
- Subject: Re: Shortest Self-Generating Ada Program
- Message-ID: <elsworthef-220792115757@cs_mac35.aston.ac.uk>
- Date: 22 Jul 92 11:09:01 GMT
- Sender: usenet@aston.ac.uk (Usenet administrator)
- Followup-To: comp.lang.ada
- Organization: Computer Science, Aston University
- Lines: 77
- Nntp-Posting-Host: cs_mac35
-
- This was my *must-be-as-one-line* Ada self-replicating program:
-
- with text_io;use text_io;procedure r is s:string(1..115):=
- "with text_io;use text_io;procedure r is s:string(1..115):="";
- begin put(s(1..59)&s(1..59)&s(59..115)&s(59..115));end;";
- begin put(s(1..59)&s(1..59)&s(59..115)&s(59..115));end;
-
- If you or your compiler don't like the above, here is another (57-line)
- self-replicating program with maximum line length 78 chars
- and using (hopefully) reasonably clear layout and identifiers.
- Also, it doesn't need the programmer to do any character counting.
-
- Ted Elsworth.
-
- ===================================================================
-
- with text_io; use text_io;
- procedure rep is
- s : constant string :=
- "with text_io; use text_io;\"&
- "procedure rep is\"&
- " s : constant string :=\"&
- """\"&
- " procedure put_s(pass : integer) is\"&
- " skipping_part1 : boolean := pass=3 or pass=4;\"&
- " begin\"&
- " for i in 1..s'last loop\"&
- " if s(i) = ascii.quotation then skipping_part1 := false; end if;\"&
- " if not skipping_part1 then\"&
- " if s(i) = ascii.back_slash then\"&
- " if pass=2 or pass=3 then\"&
- "
- put(ascii.back_slash);put(ascii.quotation);put(ascii.ampersand);\"&
- " end if;\"&
- " new_line;\"&
- " if pass=2 or pass=3 then put(ascii.quotation); end if;\"&
- " else\"&
- " put(s(i));\"&
- " end if;\"&
- " if s(i)=ascii.quotation and (pass=1 or pass=2) then exit; end
- if;\"&
- " end if;\"&
- " end loop;\"&
- " end;\"&
- "begin\"&
- " put_s(1);\"&
- " put_s(2);\"&
- " put_s(3);\"&
- " put_s(4);\"&
- "end;";
- procedure put_s(pass : integer) is
- skipping_part1 : boolean := pass=3 or pass=4;
- begin
- for i in 1..s'last loop
- if s(i) = ascii.quotation then skipping_part1 := false; end if;
- if not skipping_part1 then
- if s(i) = ascii.back_slash then
- if pass=2 or pass=3 then
- put(ascii.back_slash);put(ascii.quotation);put(ascii.ampersand);
- end if;
- new_line;
- if pass=2 or pass=3 then put(ascii.quotation); end if;
- else
- put(s(i));
- end if;
- if s(i)=ascii.quotation and (pass=1 or pass=2) then exit; end if;
- end if;
- end loop;
- end;
- begin
- put_s(1);
- put_s(2);
- put_s(3);
- put_s(4);
- end;
-
- =============================================================================
-