Skip to content

Instantly share code, notes, and snippets.

View pthatcher's full-sized avatar

Peter Thatcher pthatcher

  • Microsoft
View GitHub Profile
;; 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))
;; 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
;; 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.
;;