I used Stuart Sierra's 'fcase' contrib today to good effect. Nice job,
Stuart!
I have an idea for another fcase variant that I think is useful:
(defmacro pred-case
"Case where test values are predicates to be applied to the test
value."
[test-value & clauses]
`(fcase (fn [pred# value#] (pred# value#)) ~test-value [EMAIL PROTECTED]))
Here's an example:
user> (defn classify [x] (pred-case x keyword? :keyword
string? :string number? :number))
#=(var user/classify)
user> (classify 3)
:number
user> (classify :boo)
:keyword
Stuart, would you please consider adding pred-case to
clojure.contrib.fcase?
This also made me wonder if it would be generally useful to have a
name for this function:
(fn [f & args] (apply f args))
Do we already? It's not quite apply. It seems a traditional name would
be "funcall", but "invoke" sounds more Clojurey. Any thoughts?
Having "invoke" would allow the classify example to be written this way:
(defn classify [x] (fcase invoke x keyword? :keyword string? :string
number? :number))
--Steve
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Clojure" group.
To post to this group, send email to [email protected]
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
-~----------~----~----~----~------~----~------~--~---