Skip to content

Instantly share code, notes, and snippets.

@jido
Created September 20, 2010 22:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jido/588764 to your computer and use it in GitHub Desktop.
Save jido/588764 to your computer and use it in GitHub Desktop.
The "feed" macro inserts what follows in the blank. Very handy. Author: chouser
(use 'clojure.walk)
(defmacro _>_ [& exprs]
(reduce
(fn [inner step]
(clojure.walk/postwalk-replace {'___ inner} step))
(reverse exprs)))
(defn cat [lst, val, cont] #(cont (conj lst val)))
(trampoline (_>_ (cat [] 3 ___) (fn [l] (cat l 9 ___)) (fn [l] (println l))))
;[3 9]
(_>_ (assoc {:a "aa" :b "bda" :f "foo"} :d ___) (assoc [1 2 nil 7] 2 ___) (- (* 56 9) 403))
;{:d [1 2 101 7], :a "aa", :b "bda", :f "foo"}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment