On Oct 13, 11:01 pm, CuppoJava <[EMAIL PROTECTED]> wrote:
> Is there anyway to do the following with the existing multi-method
> facilities?
>
> There is a general multi-method length(object) that splits off to
> different methods depending on the :class of the object.
>
> And then specifically for objects with :class = :stateMachine, I want
> to define it's method to split off further depending on the :state of
> the object.
>
> (defmulti length :class)
> (defmethod-multi length :stateMachine :state)
>
> (defmethod length :stateMachine :walking
> (println "Short distance"))
>
> (defmethod length :stateMachine :running
> (println "Long distance"))
>
The answer is right in your title - use more than one multimethod and
nest them:
(defmulti length :class)
(defmulti sm-length :state)
(defmethod length :stateMachine [x]
(sm-length x))
(defmethod sm-length :walking [_]
(println "Short distance"))
(defmethod sm-length :running [_]
(println "Long distance"))
(length {:class :stateMachine :state :running})
-> Long distance
Rich
--~--~---------~--~----~------------~-------~--~----~
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
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
-~----------~----~----~----~------~----~------~--~---