This is the program that doesn't end...
Does anyone remember that song, The Song That Never Ends? I remember it from the end credits of Lamb Chop's Play Along when I was a kid. That was the first thing I thought of when I heard of a quine. Although, a quine is a whole lot easier to tolerate!
Of course, once I heard about these programs I started looking round for quines in my favourite languages. Of course there are plenty written in C. However, I was only able to come up with this one for PL/I. Unfortunately, according to the comments it will only compile using the OS PL/I V2.3.0 compiler with certain options set. Whatever the requirements, it wouldn't compile on OpenVMS. It also, erroneously, claims to be the smallest possible PL/I quine. So, in the spirit of innovation (at least that's what I'm going to call it), here is my contribution.
It will compile straight out of the box using the Kednos PL/I compiler on VAX and Alpha. It may compile using other PL/I compilers. The BYTE built-in function is an extension to the ANSI General Purpose Subset (ANSI X3.74-1987 (R1998)) so it may not work everywhere. Although the documentation for the IBM compilers indicates they support it.
The following is an expanded version to make it easier to understand what is going on. I should point out that this next sample is not a quine, it's just easier to read than the muddle of characters above.
dcl s char(94) init('q:proc;'
|| 'dcl s char(94) init(); '
|| 'put list(substr(s, 1, 26) || byte(39) || s || byte(39) || substr(s, 27));'
|| 'end;');
put list(substr(s, 1, 26) || byte(39) || s || byte(39) || substr(s, 27));
end;
It works by storing most of the program as an initial value to the character string s. The only thing missing from this initial value is s itself and its surrounding quotes, which are inserted during execution with the concatenated input to PUT LIST.
Ahh, don't ya just love a good ol' fashioned waste of time?
Further Reading
For more mind-numbing quine madness have a look at these pages.
- Gary P. Thompson II's The Quine Page (self-reproducing code)
- The Wikipedia entry for Quine
- Quines at Answers.com
![print this page [PRINT]](/_blog/print.png)
![print this and sub-pages [PRINT]](/_blog/print_plus.png)