Clojure Protocols & expression problem

bearophile bearophileHUGS at lycos.com
Wed Apr 28 10:31:41 PDT 2010


Maybe it's better if I actually give a bit of answer too to your question.

If you take a look at my D code, you can see there are many kinds of car parts, and two different kind of "visits" of them, that perform different operations on them.

The problem is, what does it happen in the code if I want to define one (or more) new car parts? What does it happen if I want to add one (or more) more kind of visits? You can slice the design of all this program "vertically" or "horizontally". One design makes it easy to add more car parts, the other design makes it more easy to add "visits".

In the Python code you can see I have used double dispatch. I can define any combination of car part and "visit", they are separated (and in Python there is no need to recompile). CommonLisp has an OO system named CLOS that offers the same power of that python solution.

Bye,
bearophile



More information about the Digitalmars-d mailing list