Hi,
Is there a better way to write
(cond
(neg? 1) "neg"
(zero? 1) "zero"
(pos? 1) "pos"
:default "default")
I came up with this:
(condp #(%1 %2) 1
neg? "neg"
zero? "zero"
pos? "pos"
= "default")
Which I wouldn't so much mind if I knew the name for #(%1 %2)
And this:
(defmacro condb [value & [pred result & more]]
(when pred
(list 'if (list pred value)
(if result
result
(throw (IllegalArgumentException.
"condb requires an odd number of forms")))
(cons 'scratch/condb (cons value more)))))
(condb 1
neg? "neg"
zero? "zero"
pos? "pos"
= "default")
But I think I'm missing a more idiomatic approach.
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
---
You received this message because you are subscribed to the Google Groups
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.