torsdag 26. mai 2011 Clojure WTF
Det er ikke fredag i dag, men likevel, jeg gir dere “Universet, første alpha-versjon”…
(ns genesis "Book of Genesis, Version 0.0.1-SNAPSHOT") ; Some universal plumbing.. (def darkness 0) (def light (inc darkness)) (def be identity) ; The main character.. (def God (fn [miracle something] (condp = miracle :create (symbol (name something)) :see (if (= something light) :good :evil) :say (println "GOD:" something)))) ; In the beginning (defn in-the-beginning [darkness god] ; God created the heaven and the earth. (let [heaven (god :create :heaven) earth (god :create :earth) ] (assert (and (= heaven 'heaven) (= earth 'earth))) ; And God said, (god :say (pr-str ; Let there be light: (let [there (be light)] ; and there was light. (assert (= there light)) ; And God saw the light, (assert (= (god :see light) ; and it was good. :good)) ; And God divided the light from the darkness. (try (/ light darkness) (catch java.lang.ArithmeticException ex (god :say (str "Ah, can't devide by zero, " "genesis postponed!"))))))))) (in-the-beginning darkness God) ;=> GOD: Ah, can't devide by zero, genesis postponed! ;=> GOD: nil ;=> nil