This file contains 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
;; clojure's (case ...) macro doesn't allow *constant-vars* in the test cases, which I find really, really annoying. | |
;; So, I wrote a (case-eval ...) macro that wraps (case ...) and evals the test cases. If you like the (case ...) macro | |
;; and want to use *globals*, here's your fix. It works pretty much transparently. | |
(defn count-from [start] | |
(iterate inc start)) | |
; like python | |
(defn zip [& lists] | |
(apply map vector lists)) |
This file contains 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
;; There appears to be a bug in Clojure 1.2's "case" macro. It doesn't work with *global* strings. I'll show some examples and a temporary work around. | |
(def *a* "a") | |
;true | |
(case "a" | |
"a" true | |
false) ;true | |
;true |
This file contains 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
;; the goal is to hash a seq of bytes, like ["ABC", "XYZ"]. | |
;; Ultimately, you'd probably get the seq from a FileReader. | |
;; | |
;; the java libraries are, of course, mutable, with a | |
;; MessageDigest object on which you call .update(bytes) | |
;; until you are done, when you call .digest(). | |
;; I typically implement the loop using reduce, | |
;; but using reduce for mutating feels a little dirty. | |
;; So, I thought I would try cells. | |
;; |