On Sat, Apr 20, 2013 at 5:15 AM, Ken Scambler <[email protected]>wrote:
> Hi there,
> I'm getting started with Clojure, and found myself really missing
> Scala-style pattern matching. Now I know about Matchure and core.match,
> but all I really needed was a cond using test predicates rather than
> boolean expressions, like this:
>
> (condval value
> foo-pred? (foo-result)
> bar-pred? (bar-result)
> else? (default-result))
>
> (Where 'else? is a predicate that ignores the argument and returns true)
>
> Lisp being Lisp, I rolled my own and it works fine.
>
How different was what you came up with from this?
(def else? (constantly true))
(defmacro condval [vname & body]
`(cond
~@(interleave (map (fn [p] `(~p ~vname)) (take-nth 2 body))
(take-nth 2 (rest body)))))
Just out of curiosity. :)
--
--
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/groups/opt_out.