From: Sayan Bhattacharyya
Subject: Quining in Lisp?
Date: 
Message-ID: <9VV36.7$0c.55@srvr1.engin.umich.edu>
Willard van Orman Quine, the distinguished logician and 
philosopher, died last week at the age of 92. 

Reading his obituary in the New York Times, I came across
an interesting sentence: it was mentioned that, according to
the Hacker's Dictionary (I guess this is the published version
of Eric Raymond's edition of the Jargon File), the verb 
"to quine" is defined as writing a  program that will print,
as output, a listing of _itself_. 

I don't think I know enough Lisp to be able to see how
one could do this (I'm still learning Lisp). How would one
go about writing such a program in Lisp? What strategy to
use? Better yet, does anyone have an example of such a 
program? I would be very curious to know.

From: Eli Barzilay
Subject: Re: Quining in Lisp?
Date: 
Message-ID: <sk66jzprrc.fsf@mojave.cs.cornell.edu>
········@engin.umich.edu (Sayan Bhattacharyya) writes:

> Better yet, does anyone have an example of such a 
> program? I would be very curious to know.

To get the whole fun you should really try it yourself.
(also see http://www.nyx.net/~gthompso/quine.htm)


Here's some spoilers...

;; An expression that prints itself
(setf x "(setf x ~S)(format t x x)")(format t x x)

;; A function that prints itself
(defun f ()
  (let ((s "(defun f () (let ((s ~s)) (format t s s)))")) (format t s s)))

;; An expression that returns its own s-expression
((lambda (x) (list x (list 'quote x))) '(lambda (x) (list x (list 'quote x))))

;; A function that returns its own s-expression
(defun f ()
  (let ((x '`(defun f () (let ((x ',x)) ,x))))
    `(defun f () (let ((x ',x)) ,x))))

-- 
          ((lambda (x) (x x)) (lambda (x) (x x)))          Eli Barzilay:
                  http://www.barzilay.org/                 Maze is Life!
From: JP Massar
Subject: Re: Quining in Lisp?
Date: 
Message-ID: <3a504903.206929484@news.mindspring.com>
On Mon, 01 Jan 2001 06:59:17 GMT, ········@engin.umich.edu (Sayan
Bhattacharyya) wrote:
 
>
>I don't think I know enough Lisp to be able to see how
>one could do this (I'm still learning Lisp). How would one
>go about writing such a program in Lisp? What strategy to
>use? Better yet, does anyone have an example of such a 
>program? I would be very curious to know.
>

;;; This works in Allegro 5.1, as long as FOO is not compiled.
;;; If it is compiled, function-lambda-expression returns NIL
 
  (defun foo ()
    (let ((x (function-lambda-expression #'foo)))
      (pprint (list 'defun 'foo nil (third (third x))))))
FOO
> (foo)

(DEFUN FOO ()
  (LET ((X (FUNCTION-LAMBDA-EXPRESSION #'FOO))) 
    (PPRINT (LIST 'DEFUN 'FOO NIL (THIRD (THIRD X))))))