Quine (Lisp)

From LiteratePrograms

Jump to: navigation, search
Other implementations: BASIC | Clojure | dc | Erlang | Forth | JavaScript / URI | Lisp | Oz | Perl | Python | Smalltalk

A Quine[1] is a program that produces its complete source code as its only output. Because of the nature of the Lisp programming language, it is especially well suited to writing Quines. This is a valid Quine in Common Lisp and Scheme (and probably other Lisps as well)


Anonymous lambda expressions are more compact to write than a combined function definition and function call, so we will use those. The general idea for the program is that there are two copies of the same lambda expression. The first is the program and the second is data.

((lambda (x) (list x (list 'quote x))) '(lambda (x) (list x (list 'quote x))))


((lambda (x) (list x (list 'quote x))) '(lambda (x) (list x (list 'quote x))))

I suggest you jump over your shadow and give Common Lisp a go. It's a quite different but also very interesting language.

Download code