Quine (Clojure)
From LiteratePrograms
- 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 Clojure is a Lisp, it is especially well suited to writing Quines. This is a valid Quine in Clojure.
Concept
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.
<<quine.clj>>= ((fn [x] (list x (list (quote quote) x))) (quote (fn [x] (list x (list (quote quote) x)))))
output:
((fn [x] (list x (list (quote quote) x))) (quote (fn [x] (list x (list (quote quote) x)))))
Download code |