On Fri, 2009-08-21 at 12:50 -0700, Kevin Downey wrote:
> user=> (defmulti length empty?)
> #'user/length
> 
> user=> (defmethod length true [x] 0)
> #<MultiFn clojure.lang.mult...@1807ca8>
> 
> user=> (defmethod length false [x] (+ 1 (length (rest x))))
> #<MultiFn clojure.lang.mult...@1807ca8>
> 
> user=> (length [1 2 3 4])
> 4
> 
Très cool! This could be applied to Meikel's post as well -- you *can*
write your own predicate function that in effect test for values. It
will just be -- ugly.

Is there a performance hit with this style (due to using multimethods)
or will this be optimized away in practice?

-- 
Michel

Attachment: signature.asc
Description: This is a digitally signed message part

Reply via email to