Sent from a smartphone, please excuse the brevity/typos.

Le 25 oct. 2012 à 20:44, "Jim - FooBar();" <jimpil1...@gmail.com> a écrit :

 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!


Wow, this kind of decision is not for the faint of heart.
Not to be taken lightly, that's for sure! Because then, your code becomes
non pure, harder to test, etc.
not saying that it was not appropriate in your case, but rather than used
as a demonstration of how 'powerful' (as in easy to shoot one selves in the
foot), this should certainly not be a habit to start using this kind of
trick at first...

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!")))


Jim




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