Created
April 5, 2011 08:51
-
-
Save ray1729/903268 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn parse-flags | |
"Parse a list of flags. Each flag name must be a keyword, and the | |
value must not be a keyword. If the value is omitted, true is | |
assumed. Returns a map. | |
e.g. (parse-flags [:i :j 1 :k \"two\"]) | |
=> {:i true, :j 1, :k \"two\"}" | |
[flags] | |
(loop [flags (seq flags) accum {}] | |
(if flags | |
(let [k (first flags)] | |
(if (and (next flags) (not (keyword? (second flags)))) | |
(recur (nnext flags) (assoc accum k (second flags))) | |
(recur (next flags) (assoc accum k true)))) | |
accum))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment