Skip to content

Instantly share code, notes, and snippets.

@mecdemort
Created April 30, 2011 00:43
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 mecdemort/949291 to your computer and use it in GitHub Desktop.
Save mecdemort/949291 to your computer and use it in GitHub Desktop.
(def *multi-value* false)
(defmacro with-values [vars expr body]
`(binding [*multi-value* true]
(let [[~@vars] ~expr]
~body)))
(defn values [& vals]
(if *multi-value*
vals
(first vals)))
(values 1 2 3)
;;=> 1
(values)
;;=> nil
(with-values [a b c]
(values 1 2 3 4 5) [a b c])
;;=> [1 2 3]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment