Monday, October 09, 2006

YALQ - Yet Another Lisp Quine

Here is a format-based Lisp quine:

(let ((p "(let ((p ") (s "(format t \"~A~S) (s ~S)) ~A)\" p p s s)")) (format t "~A~S) (s ~S)) ~A)" p p s s))

Please note that the above code should be written on a single line, and there should be a space before the last ~A, before the end of the string.

While I thought it was pretty original at the time it was written, I now discovered the quine by Dave Seaman (ags@seaman.cc.purdue.tom.edu MINUS cat) on the Lisp section of the Quine Page:

(let ((p "(let ((p ~s)) (format t p p))")) (format t p p))

This one is smarter and shorter, since p is used as a format-string for printing itself, without needing both a prefix and a suffix, but it is clearly in the same vein.

No comments: