Created
April 16, 2014 19:20
-
-
Save jneen/10922843 to your computer and use it in GitHub Desktop.
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
(defn rec [expr] | |
(match expr | |
[:global] 'GLOBAL | |
[:constant x] x | |
[:variable x] x | |
[:lazy-variable x] `(deref ~x) | |
[:if test if-true if-false] `(if ~(rec test) | |
~(rec if-true) | |
~(rec if-false)) | |
[:delist list index] `(get ~(rec list) ~(rec index)) | |
[:depair pair key] `(get ~(rec pair) ~(match key :first 0 :second 1)) | |
[:list elements] (map rec elements) | |
[:fold-recur index-arg list-sym] `(recur (+ 1 ~index-arg) (rest ~list-sym)) | |
[:zip left right] `(map vector ~(rec left) ~(rec right)) | |
[:filter list arg body] `(filter (fn [~arg] ~(rec body) ~(rec list))) | |
[:len list] `(count ~(rec list)) | |
[:pair first second] [(rec first) (rec second)] | |
[:block arg body] `(fn [~arg] ~(rec body)) | |
[:app f arg] `(~(rec f) ~(rec arg)) | |
[:query e annotations] `(QUERY ~(rec e) ~annotations) | |
[:lookup key] `(LOOKUP ~key) | |
[:let name value expr] `(let [~name ~value] expr) | |
; ... about 15 more | |
)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment