On 01/19/2015 07:45 AM, A. Sundararajan wrote:
Hi,
If the NodeVisitor interface includes default implementation that
calls visitUnknown method, then your scheme could be implemented as
visitUnknown override (i.e., Class->lambda selection logic and
maintaining state etc).
yes,
but the whole idea is to remove the NodeVisitor interface which is not
enough flexible.
Note that the problem of being able to add new visit method and add new
expression node
is not a new problem, Philip Wadler name it the expression problem [1].
And even, the approach to use getClass()/reflection to escape the Java
type system to 'solve' this issue
is not new too [2]. I've written 'solve' between quotes because using a
dynamic cast doesn't solve
anything in theory.
It's just that now we have lambdas, we have a nice way to decouple the
selection of the behavior from the AST hierarchy
so we don't need any Visitor interface anymore.
Also, users can implement few selective visitABC methods - as the rest
have default implementation - which is one of the advantages your
scheme - selectively implement visit for only few types.
You can also solve that by inheriting a default visitor implementation
(or worst default methods on an interface)
but it's always more flexible to use composition over inheritance.
Thanks,
-Sundar
Rémi
[1] http://homepages.inf.ed.ac.uk/wadler/papers/expression/expression.txt
[2] http://www.cs.ucla.edu/~palsberg/paper/compsac98.pdf
On Friday 16 January 2015 04:22 AM, Remi Forax wrote:
On 01/15/2015 11:31 PM, mark.reinh...@oracle.com wrote:
[...]
236: Parser API for Nashorn http://openjdk.java.net/jeps/236
Feedback on these proposals is more than welcome, as are reasoned
objections. If no such objections are raised by 23:00 UTC next
Thursday, 22 January, or if they're raised and then satisfactorily
answered, then per the JEP 2.0 process proposal [1] I'll target
these JEPs to JDK 9.
(This information is also available on the JDK 9 Project Page [2]).
- Mark
for JEP 236, I'm not sure that we need a visitor anymore along with
the AST, now that we have lambdas,
a HashMap AST node -> function to execute, is enough.
see for an example of usage
https://github.com/forax/vmboiler/blob/master/script/src/com/github/forax/vmboiler/sample/script/TypeInferer.java#L46
and the definition of a Visitor
https://github.com/forax/vmboiler/blob/master/script/src/com/github/forax/vmboiler/sample/script/Visitor.java
Note: that this 'new visitor' doesn't need any support method
(usually named 'accept') defined on the AST node.
cheers,
Rémi