Created
August 31, 2016 22:43
-
-
Save gfredericks/2369143507f032f4190d37e0185e9908 to your computer and use it in GitHub Desktop.
A counting quine in Clojure
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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