Re: Idiomatic equivalent for double dispatch in clojure?

2012-11-20 Thread Thomas Goossens
Thanks. Two months ago I bought that book. So I'll take a look at it ! -- 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

Re: Idiomatic equivalent for double dispatch in clojure?

2012-11-20 Thread Thomas Goossens
I think it is a bit dull that for every combination [type1 type2] you have to define an equivalent method for [type2 type1] Is there a way to address this problem? perhaps with sets? i need to think about this one :D On Monday, November 19, 2012 4:32:15 PM UTC+1, Brian Marick wrote: Here's

Re: Idiomatic equivalent for double dispatch in clojure?

2012-11-20 Thread Brian Marick
On Nov 20, 2012, at 10:22 AM, Thomas Goossens wrote: I think it is a bit dull that for every combination [type1 type2] you have to define an equivalent method for [type2 type1] Is there a way to address this problem? perhaps with sets? According to http://clojure.org/multimethods only

Re: Idiomatic equivalent for double dispatch in clojure?

2012-11-20 Thread Thomas Goossens
Then probably something like this will help me out (defn defmutualmethods [multifn dispatch-val fn-tail] (defmethod multifn dispatch-val fn-tail) (defmethod multifn (reverse dispatch-val) fn-tail)) Nevertheless i'm making things more complex now because it does two things now! But it

Idiomatic equivalent for double dispatch in clojure?

2012-11-19 Thread Thomas Goossens
In a java project last year we had to create a board game. A Board had Piece objects. Some pieces can share position. Some don't. The way i solved this in Java was using double dispatch. http://pastebin.com/brrRtqsS (I just extracted the methods out of their respective classes) But i think it

Re: Idiomatic equivalent for double dispatch in clojure?

2012-11-19 Thread Stuart Sierra
A long time ago I posted some macros to do double-dispatch with protocols and records. The link was http://paste.lisp.org/+2023 but it no longer works. The basic idea is you dispatch on the first argument to an intermediate type that then dispatches on the second argument. It's complicated,

Re: Idiomatic equivalent for double dispatch in clojure?

2012-11-19 Thread Brian Marick
Here's an example of using multimethods. (Note: I overrode the Clojure defmulti/defmethod macros with my own that play more nicely with the repl, and for other purposes. It's a straightforward translation.) You can see all the code here:

Re: Idiomatic equivalent for double dispatch in clojure?

2012-11-19 Thread Thomas Goossens
Yes indeed. with multimethods you can doue multi-argument dispatch. But that means that for every possible collision. I have to specify a method? Would it be a good idea to introduce taxonomies here? On Monday, November 19, 2012 4:02:18 PM UTC+1, Stuart Sierra wrote: A long time ago I

Re: Idiomatic equivalent for double dispatch in clojure?

2012-11-19 Thread Jim - FooBar();
for what its worth, I'm building a highly polymorphic board-game engine [1] and I've stayed away from multimethods...I've used every single polymorphism capabillity that clojure provides (records/protocols, map-based, HOFs etc) except multi-methods. Performance is acritical matter for this

Re: Idiomatic equivalent for double dispatch in clojure?

2012-11-19 Thread Brian Marick
On Nov 19, 2012, at 9:32 AM, Thomas Goossens wrote: Yes indeed. with multimethods you can doue multi-argument dispatch. But that means that for every possible collision. I have to specify a method? If you read along in `asteroids.clj` file I showed, you'll see an example of a taxonomy. A