Skip to content

Instantly share code, notes, and snippets.

Last active December 25, 2015 07:49
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
(defmacro my-let
[bindings & body]
(assert (-> bindings count even?) "Bindings count can only be even.")
`((fn [~@(take-nth 2 bindings)]
~@(take-nth 2 (rest bindings))))
Copy link

One of the ways to implement let is to create a temporary function scope that will have required
bindings, and call this function with params that represent arguments.

For example, if you have bindings like [a 1 b 2], you'll take a and b as variable names (bindings),
and 1 and 2 as values, that you'll call function with.

This means that our let will expand:

(let [a 1
      b 2]
  (println (+ a b)))


((fn [a b]
    (println (+ a b)))
 1 2)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment