(ns experiments.MultiMethod)
(defmulti fac identity)
(defmethod fac 1 [n] (print "n:" n" <- ") 1)
(defmethod fac :default [n] (*' n (fac (dec n))))
(print (fac 125))

if i am getting this right, defmethod fac <stuff> [<stuff2>] is the
equivalent to a scala or haskell pattern match, where stuff is the "match"
and stuff2 is the complete set of original arguments?

can you provide an example where stuff2 has more information than stuff?
for fac, both are equal....

thx :D


2013/6/22 Dennis Haupt <d.haup...@gmail.com>

> yes. all glory to the repl that makes me figure out the internals via
> experiments :D
> is there a way to just pass the given value along?
>
>
> 2013/6/22 Chris Bilson <cbil...@pobox.com>
>
>> Dennis Haupt <d.haup...@gmail.com> writes:
>>
>> > i am not trying anything, i just want to figure out what happens. this
>> is my output for the "print" version:
>> > user=> (defmulti fac print)
>> > (defmethod fac 1 [_] 1)
>> > (defmethod fac :default [n] (*' n (fac (dec n))))
>> > #'user/fac
>> > #<MultiFn clojure.lang.MultiFn@1afb02d>
>> > #<MultiFn clojure.lang.MultiFn@1afb02d>
>> > user=> (fac 1)
>> >
>> 10-1-2-3-4-5-6-7-8-9-10-11-12-13-14-15-16-17-18-19-20-21-22-23-24-25-26-27-28-....until
>> > stackoverflow
>>
>> Since print produces nil for a dispatch value, and nil is not 1, it
>> always calls your :default method.
>>
>> --
>> --
>> You received this message because you are subscribed to the Google
>> Groups "Clojure" group.
>> To post to this group, send email to clojure@googlegroups.com
>> Note that posts from new members are moderated - please be patient with
>> your first post.
>> To unsubscribe from this group, send email to
>> clojure+unsubscr...@googlegroups.com
>> 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 clojure+unsubscr...@googlegroups.com.
>> For more options, visit https://groups.google.com/groups/opt_out.
>>
>>
>>
>

-- 
-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
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 clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to