Clojure Protocols & expression problem

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


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

The have discussed it a little here:

You can find some info relative to C++ solutions here too:

More on the same in C++:
It contains a paper from Bjarne Stroustrup too:

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


More information about the Digitalmars-d mailing list