Clojure Protocols & expression problem

bearophile bearophileHUGS at lycos.com
Wed Apr 28 10:22:53 PDT 2010


BCS:

>Could you elaborate on what exactly the expression problem is?<

I am far from being an expert on such matters, I will do what I can to answer.
It's not an esoteric problem, if you program with an OO language you have probably faced it sometime.

I think it's one of the two most important OOP problems not yet solved by D. And I think it deserves some thinking. But it can be work for the design of the D3 language.

Curiously one of the original design goals of Scala was to "solve" the expression problem.

(The other basic OO problem not currently solved by D2 is the variance/covariance of collections that contain objects (like arrays). There is a well known bug report about this. C# has introduced only in its 4.0 release syntax to face this problem, and recently I've sent Andrei the URL of an article that shows how Scala faces and solves this problem in its collections.)

You can see a canonical example of this problem in the D and Python code I've shown in my original post. In OO languages simpler than Scala and CLisp+CLOS the expression problem is sometimes solved using this pattern, the same I've used in the D code:
http://en.wikipedia.org/wiki/Visitor_pattern

The have discussed it a little here:
http://lambda-the-ultimate.org/node/2232

You can find some info relative to C++ solutions here too:
http://www.mpi-inf.mpg.de/~kettner/courses/lib_design_03/notes/advanced.html#DoubleDispatch

More on the same in C++:
http://lambda-the-ultimate.org/node/2590
It contains a paper from Bjarne Stroustrup too:
http://www.research.att.com/~bs/multimethods.pdf

In the Python code I have used multiple (double) dispatch to solve it, hopefully better.

Bye,
bearophile



More information about the Digitalmars-d mailing list