You say that from the safe standpoint of being able to enumerate all
OSes in advance...I can imagine a world where anyone can have his own
OS. :-)
Seriously now, this is not production code obviously! just a demo...
Jim
On 25/10/12 21:04, Brandon Bloom wrote:
|(||fn||[||_ _||]||;dispatch-function checks for OS - ignores args|
|(||let||[||os||(||System/getProperty||"os.name
<http://os.name>"||)||]|
|||(||if||(||.startsWith os||"Mac OS"||)||:Linux
||(||keyword||os||)||)||)||)||)|
This seems like a very poor use of multi-methods. Multi-methods exist
to provide both dynamic and open dispatch. In this case, the dispatch
function is completely static.
If you don't need dynamism or openness, then you're better off with a
simple case form at the top level:
(case platform
:linux (def halt [root-pwd minutes-after] ...)
:windows ...
...
(def halt [& args] (throw ...)))
If you prefer the appearance of top-level forms, or need the openness,
you could pretty easily implement a static version of defmulti &
defmethod which ensure you only pay the dispatch cost once at startup,
rather than on every invocation.
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient
with your first post.
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
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
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