Skip to content

Instantly share code, notes, and snippets.

@mdemare
Created January 29, 2010 16:11
Show Gist options
  • Save mdemare/289847 to your computer and use it in GitHub Desktop.
Save mdemare/289847 to your computer and use it in GitHub Desktop.
;;; Number of arguments expected: 2 + 4, 3 + 8, 4 + 16
(defmacro multibool [& args]
(let [offset ({6 2, 11 3, 20 4} (count args))]
(assert offset)
`(condp = (+ ~@(map (fn [i] `(if ~(nth args i)
~(bit-shift-left 1 (- (dec offset) i))
0))
(range 0 offset)))
~@(reduce (fn [memo i] (into memo (list (nth args (+ 2 i)) i)))
'()
(range 0 (- (count args) offset))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment