[comp.windows.news] A PostScript Quine

sjs@spectral.ctt.bellcore.com (Stan Switzer) (09/14/89)

   "'Yields falsehood when preceded by itself in quotes" yields
   falsehood when preceded by itself in quotes." -- W. V. O. Quine
   (paraphrase) 

A "quine" is a program which when evaluated yields its own
representation.  A quine can be formally described as a fixed point of
a language's denotation function.  Trivial evaluations (e.g.:
literals) are excluded and the program cannot require any input data
(e.g.: "cat cat.c").

In my experience, the merit of a language is inversely related to the
length of its shortest quine.  (Though I _am_ prejudiced toward
reflective semantics.)

For the heck of it, let's say a PostScript quine is a procedure
"{...}" which when followed by "n { exec } repeat" yields the same (or
equivalent) value for any non-negative integer value of "n"
(including 0).

The shortest I have found for PostScript is

  {{[ exch /dup load /exec load ] cvx} dup exec}

Compare to Lisp:

  ((lambda(f)(list f (list 'quote f))) '(lambda(f)(list f (list 'quote f))))

or (ASCII) C:

  char*f="char*f=%c%s%c;main(){printf(f,042,f,042,012);}%c";main(){printf(f,042,f,042,012);}

Not that it'll change your life or anything...

Enjoy,

Stan Switzer  sjs@bellcore.com

greid@adobe.com (Glenn Reid) (09/15/89)

In article <17620@bellcore.bellcore.com> sjs@bellcore.com (Stan Switzer) writes:
>For the heck of it, let's say a PostScript quine is a procedure
>"{...}" which when followed by "n { exec } repeat" yields the same (or
>equivalent) value for any non-negative integer value of "n"
>(including 0).
>
>The shortest I have found for PostScript is
>
>  {{[ exch /dup load /exec load ] cvx} dup exec}

I must admit I don't understand quite what this is supposed to
do, but it looks to me like it can get shorter.  Why the 2 instances
of "load", if you're trying to make it short?  Does this not do
the same thing:

  {{exch dup exec} dup exec}

yields the same (or equivalent) value of what?  How about a sample
invocation, just so dim-wits like me can catch on?

Thanks,
 Glenn

greid@adobe.com (Glenn Reid) (09/15/89)

In article <17620@bellcore.bellcore.com> sjs@bellcore.com (Stan Switzer) writes:
> A "quine" is a program which when evaluated yields its own
> representation.  A quine can be formally described as a fixed point of
> a language's denotation function.  Trivial evaluations (e.g.:
> literals) are excluded and the program cannot require any input data
> (e.g.: "cat cat.c").
>
> For the heck of it, let's say a PostScript quine is a procedure
> "{...}" which when followed by "n { exec } repeat" yields the same (or
> equivalent) value for any non-negative integer value of "n"
> (including 0).
> The shortest I have found for PostScript is
>
>  {{[ exch /dup load /exec load ] cvx} dup exec}

Wait--now I get it.  The execution of the procedure has to give
you the same procedure back.  I was lost in the definition of
"quine".  According to the way you've set it up (using "n { exec } repeat"),
the following should qualify:

    {/exec{dup}def}

I guess this doesn't qualify, since it only works if you invoke it
with "exec", and (only after the first invocation :-), but it sure
is short...

Glenn Reid