3 ms·
In SICP (where I assume this is taken from) they actually solve this problem. They have a dispatch function (as multi-methods have in Clojure) and a map from di
by rapala 15y ago
In SICP (where I assume this is taken from) they actually solve this problem. They have a dispatch function (as multi-methods have in Clojure) and a map from dispatch values to action functions. In that case you can extend the evaluator by adding new <dispatch value, action function> pairs to the map, which can be done in runtime.
- yoklov 15y agoI see, I had forgotten about that, but it's not exactly polymorphism, right?
- rapala 15y agoIt may not feel like it, but that is pretty much what languages like Java do. At run time, the type of the receiver is evaluated and the correct method is selected based on that. So we have the dispatch function, and a way to map results of that dispatch function to action functions. The only difference is that because of static typing, we cannot extend the <dispatch value, action function> map at run time, because we cannot create types at run time.