Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

The visitor pattern is relevant in multiple dispatch also; just most of its boilerplate goes away, so that only the visitation remains: traverse the AST (or whatever structure) and invoke the given method with the node and visitor as arguments.

For list in Common Lisp, the ancient mapcar function can do this:

  (mapcar (lambda (node) (visit node visitor)) node-list)
We still have to write method specializations the different combinations of node and visitor types we need, for the generic function visit.

  (defmethoc visit ((left if-statement) (right print-visitor))
    ... logic for printing if statement
    )


It's just less fragmented than the single dispatch version, because we don't have to perform two single dispatches to obtain one.


Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: