|
|
|
|
|
by drmeister
2662 days ago
|
|
It's things like the visitor pattern that led me to implement Clasp - a Common Lisp that interoperates with C++ and uses llvm as the backend (github.com/clasp-developers/clasp.git).
Common Lisp has generic functions and multiple dispatch - so it doesn't need the wretched visitor pattern.
Try writing a compiler using the visitor pattern - I dare you. :-) |
|
So that is to say, we can still have a situation where we have a tree of objects T with nodes N of different classes (expression, if-statement, ...) and visitor objects of different classses (pretty-printer, evaluator, ...).
Then given some generic function G and visitor object V, we walk the nodes of the tree, and simply (funcall G N V) for each node N that we encounter.
The remaining verbiage is then in all the method specializations we have to write for G for all the N V combinations that occur.
For all the framework brevity, we yet have an additional flexibility relative to the Visitor Pattern: namely, we can not only vary the choice of visitor object V, but also of G. The Visitor Pattern fixes the generic function in terms of some hard-coded some visit()/accept() protocol.