Skip to content

Instantly share code, notes, and snippets.

@polypus74
Created June 28, 2010 23:10
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 polypus74/456523 to your computer and use it in GitHub Desktop.
Save polypus74/456523 to your computer and use it in GitHub Desktop.
(defmacro letp [expr bindings & body]
(let [parted
(partition 3 bindings)
true-bindings
(vec (apply concat
(map #(take 2 %) parted)))
false-bindings
(vec (apply concat
(map #(list (first %) (last %)) parted)))]
`(if ~expr
(let ~true-bindings ~@body)
(let ~false-bindings ~@body))))
(letp true
[x 1 2
y 3 4]
[x y])
@polypus74
Copy link
Author

btw, the above returns [1 3]

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