On 25/10/12 20:33, Laurent PETIT wrote:
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...

Yes you're right...suddenly the multi-method depends on some state, however the GUI is already pretty stateful and if you want to let the user write the logic of a game and suddenly show it up with graphics on the screen without writing any code, I don't see how else it can be done...It's not critical code, it's extensible, it's powerful...

The point I was trying to make and perhaps I was a bit extreme, is that there is no type, there is no class, there is no object - it's just a function! Usually you dispatch on some fn of the arguments or some of arguments or if you really want to some other irrelevant var (state). Ignoring the arguments clearly makes the point that (perhaps too hard): "forget anything you knew about single type-based dispatch". Multi-methods are on a whole other level with regards to polymorphism. :-)

Jim

ps: I hope we can agree that there is nothing wrong with the 'halt' multi-method I demonstrated as it depends on some state already and doesn't need to know about passwords and minutes. Because the arity of dispatch-fn has to match the arty of the implementations it is a common thing to ignore some arguments in dispatch-fns isn't it? I've seen quite a few times...


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

Reply via email to