Skip to content

Instantly share code, notes, and snippets.

@aamedina
Created November 20, 2013 17:41
Show Gist options
  • Select an option

  • Save aamedina/7567601 to your computer and use it in GitHub Desktop.

Select an option

Save aamedina/7567601 to your computer and use it in GitHub Desktop.
(defmacro simple-let
[bindings & body]
`((fn ~(->> (partition-all 2 bindings) (map first) (vec))
~@body)
~@(->> (partition-all 2 bindings) (map second))))
(simple-let [x true]
(= false x))
;; returns false, because x is bound to true
;; what's cool is how the author points out that let is actually a type of lambda expression (anonymous function)
;; so this macro i wrote illustrates that explicitly by macroexpanding the let form into a lambda form
;; we can verify that this macro works correctly by macroexpanding the quoted form (we quote so that the reader
;; treats the form as a list of code, and not a list to be evaluated)
(macroexpand
'(simple-let [x true]
(= false x)))
;; returns
((clojure.core/fn [x] (= false x)) true)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment