On Thursday, October 25, 2012 11:44:50 AM UTC-7, Jim foo.bar wrote:
>
>  On 25/10/12 19:38, Brian Craft wrote:
>  
> Multimethods seem like a convenience layer over duck typing: probe the 
> object to see what it is, then dispatch. Is that a fair description?
>
>
> Not exactly...MUlti-methods have no limitations with regarding dispatch. 
> You can dispatch on anything...I mean ANYTHING!!! To give you an idea, my 
> canva-react mulit-method dispatches on the type of game being played at the 
> moment which is not part of the parameters passed in!!! In other words the 
> dispatch function completely ignores the arguments! Nothing to do with 
> types/classes etc etc. You dispatch on some function - that is it!!!
>
> similarly:
>
> (defmulti halt
> (fn [_ _]  ;dispatch-function checks for OS - ignores args
>  (let [os (System/getProperty "os.name")]
>   (if (.startsWith os "Mac OS") :Linux  (keyword os)))))
>  
> ;;for Linux and Mac machines    
> (defmethod halt :Linux [root-pwd minutes-after] 
>    (clojure.java.shell/sh
>    "sudo" "-S" "shutdown" (str "+" minutes-after) :in (str root-pwd "\n"))
> )
>  
> ;;for Windows machines
> (defmethod halt :Windows [_ minutes-after]
>    (clojure.java.shell/sh "shutdown" "-s" "-t"  (str minutes-after)))
>  
> ;;for Solaris machines
> (defmethod halt :Solaris [root-pwd seconds-after]
>    (clojure.java.shell/sh
>    "shutdown" "-S" "-y" (str "-g" seconds-after) "-i" "S" :in (str 
> root-pwd "\n")))
>  
> ;;in case nothing fires
> (defmethod halt :default [] (throw (UnsupportedOperationException. 
> "Unsupported 
> operating system!")))
>
>
heh. I see. Thanks! 

-- 
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

Reply via email to