This should circumvent the issue with "and":
(defmacro dispatch-on [ch & cases]
(let [argssym (gensym "args__")
keysym (gensym "key__")
ressym (gensym "res__")
default-case (when (odd? (count cases)) (last cases))
default-case (when default-case
(let [[[res] & body] default-case]
`(cljs.core/let [~res ~ressym] ~@body)))
cases (if default-case (butlast cases) cases)
case-body (apply concat (for [[key [args & body]] (partition 2 cases)]
[key `(cljs.core/let [~args ~argssym]
~@body)]))
case-body (if default-case
(conj (vec case-body) default-case)
case-body)]
`(cljs.core/let [ch# ~ch
~ressym (cljs.core.async/<! ch#)
isvec# (cljs.core/vector? ~ressym)]
(if (cljs.core/and isvec# (cljs.core/seq ~ressym))
(cljs.core/let [~keysym (cljs.core/first ~ressym)
~argssym (cljs.core/next ~ressym)]
(cljs.core/condp = ~keysym ~@case-body))
~default-case))))
--
Note that posts from new members are moderated - please be patient with your
first post.
---
You received this message because you are subscribed to the Google Groups
"ClojureScript" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/clojurescript.