3 ms·
the overhead of of generic call will grow linearly with the number of methods As far as I know, no. I could be wrong, but I think how it works is this: each me
by dkersten 16y ago
the overhead of of generic call will grow linearly with the number of methods
As far as I know, no. I could be wrong, but I think how it works is this: each method is added to a map for that multimethod. When dispatching, the dispatch function is applied to the arguments and the result is used as the key into the map of methods. I'm pretty sure that the compiler could optimise the lookup too, though I don't know if Clojure does or not.
Thats just what I would do if I wrote Clojure - I don't actually know how Clojure manages it in real life (and am too lazy to check).
Yeah. I've always wished that languages like C++ had two things: multimethods and ML-style pattern matching (well, three things - I guess you'd want ML-style parametric types to go with the pattern matching).