On Sunday, December 29, 2013 7:05:28 PM UTC+1, Cedric Greevey wrote: > > On Sun, Dec 29, 2013 at 12:27 PM, Massimiliano Tomassoli < > kiuh...@gmail.com <javascript:>> wrote: > >> What's the difference between protocols and simple overloading? >> > > Dynamic dispatch. Overloading uses just the static type for dispatch, so > this Java code: > > aBase = new Base(); > aDerived = new Derived(); > aBase2 = aDerived; > something.foo(aBase); > something.foo(aBase2); > something.foo(aDerived); > > will call the same version of foo the first two times, though the third > time it might call a different overload of foo (if there's a separate > foo(Derived x) method in the class of "something"). > > Dynamic dispatch uses the runtime type. In Java you get this when you call > > aBase.bar(); > aBase2.bar(); > aDerived.ber(); > > and (if Derived overrides bar) get the Derived version of bar called for > the second as well as the third calls, because aBase2's runtime type is > Derived. >
OK. I was reading about the "Expression Problem" and how it can supposedly be easily solved in Clojure. That should mean that Clojure is a very powerful language. But I can do the same thing in C++. If I use simple structures or classes without methods, I can solve the "Expression Problem" the same way as Clojure does. Moreover, I can build dynamic dispatching into C++ just by including a property "type" in each structure and by using templates and maybe a few macros to add some syntactic sugar. Doesn't this prove that C++ is at least as powerful as Clojure w.r.t. the "Expression Problem"? > -- -- 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 unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.