You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It is common for the visit_* methods to return void (as opposed to in the example). In that case it is possible to factor out the
traversal code and share it between algorithms (and also to provide noop default methods). In Rust, the common way to do this
is to provide walk_* functions for each datum. For example,
I have a hard time understanding this section. I have a few questions:
What is meant by "each datum" here? I'm guessing an AST node is a datum, but just to clearify.
There is no self parameter in the example walk_expr function following the paragraph. Where would I put this function? At first I thought one would put it on "each datum", but then there is no self so yeah... it can't be a method. It could be an associated function, that might make sense I guess. Also, it does get an Expr as an argument, as a substitution for self i guess. But again just to clearify.
The first parameter visitor is typed as &mut Visitor, however because Visitor is a trait I get a compiler error saying I should use the dyn keyword. This confuses me. Maybe it's just a typo?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Regarding the visitor pattern found under Chapter 3.1.6, Section "Discussion".
I have a hard time understanding this section. I have a few questions:
selfparameter in the examplewalk_exprfunction following the paragraph. Where would I put this function? At first I thought one would put it on "each datum", but then there is noselfso yeah... it can't be a method. It could be an associated function, that might make sense I guess. Also, it does get anExpras an argument, as a substitution forselfi guess. But again just to clearify.visitoris typed as&mut Visitor, however becauseVisitoris atraitI get a compiler error saying I should use thedynkeyword. This confuses me. Maybe it's just a typo?Thanks!
Beta Was this translation helpful? Give feedback.
All reactions