BCS wrote:
Correct me if I'm wrong but I thing that D's opApply is a form of the
Visitor pattern where the calling function's stack frame is the visitor
object.
This just occurred to me. Maybe I've been missing something re the
visitor pattern but I think this make for a nice, cool and easy way to
describe it. (Also I don't remember it being described that way)
Er.... no. There's no double-dispatch (at least automatically), there's
only one foreach body delegate. The visitor pattern as far as I know it
uses dynamic dispatch so the visitor object can handle different objects
in the class hierarchy differently. For example, you couldn't use a
foreach to enumerate through a syntax tree and handle expressions and
statements differently (well, you could, but you'd have to do it manually).