Skip to content

Instantly share code, notes, and snippets.

@gfredericks
Created August 31, 2016 22:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gfredericks/2369143507f032f4190d37e0185e9908 to your computer and use it in GitHub Desktop.
Save gfredericks/2369143507f032f4190d37e0185e9908 to your computer and use it in GitHub Desktop.
A counting quine in Clojure
(def regular-quine
"A regular quine. Evals to itself."
'(let [thing '(list 'let ['thing (list 'quote thing)]
thing)]
(list 'let ['thing (list 'quote thing)]
thing)))
(= regular-quine (eval regular-quine)) ;; => true
(def counting-quine
"A counting quine. Does not eval to itself, but produces itself
when iteratively eval'd 1000 times."
'(let [x 0
thing '(list 'let ['x (mod (inc x) 1000)
'thing (list 'quote thing)]
thing)]
(list 'let ['x (mod (inc x) 1000)
'thing (list 'quote thing)]
thing)))
(= counting-quine (eval counting-quine)) ;; => false
(= counting-quine ((apply comp (repeat 1000 eval))
counting-quine)) ;; => true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment