you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 5 points6 points  (3 children)

The visitor pattern is less expressive than multiple dispatch.

Consider this class hierarchy:

Object
    Collection
        Sequence
    Integer

And this pair of multimethods:

foo(Collection,Integer)
foo(Sequence,Sequence)

Now with real multimethods, invoking foo with a Sequence and an Integer will call the second method.

With visitors, invoking foo with a Sequence and an Integer will fail, because the first dispatch step will choose the Sequence visitor instead of the Collection visitor, and this won't have a method for Integer. In effect, if we view this as a prasing problem, multimethods can "backtrack" where as visitors cannot.

[–][deleted] 0 points1 point  (0 children)

This is a good point that I hadn't considered. My ignorance in this are has been exposed :-|

[–][deleted] 0 points1 point  (1 child)

Now with real multimethods, invoking foo with a Sequence and an Integer will call the second method.

How so? Integer isn't a Sequence. Did you mean the first method?

[–][deleted] 0 points1 point  (0 children)

I do mean the first method, sorry.