Skip to content

Instantly share code, notes, and snippets.

@tomjack
Created October 21, 2010 04:48
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tomjack/2f060dde83ac1bfbe551 to your computer and use it in GitHub Desktop.
Save tomjack/2f060dde83ac1bfbe551 to your computer and use it in GitHub Desktop.
(defmacro let-into [to & bindings]
`(let [~@bindings]
(into ~to ~(vec (for [sym (take-nth 2 bindings)]
[(keyword sym) sym])))))
(comment
(let-into {}
x 1
y (inc x)
z (inc y))
expands to:
(let [x 1
y (inc x)
z (inc y)]
(into {} [[:x x] [:y y] [:z z]]))
returning:
{:x 1 :y 2 :z 3}
with (defrecord Foo [x y]) we get:
(let-into (Foo. 0 0)
x 1
y (inc x))
but having to supply a dummy instance is ugly...)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment