I was reading the implementing_the_visitor_pattern_without_recursion from Python Cookbook, Third Edition
The implementation with additional Visit
Class fix the defect in the one without it as it claims.
“One potential danger of this recipe concerns the distinction between yielding Node and non-Node values. In the implementation, all Node instances are automatically traversed. This means that you can’t use a Node as a return value to be propagated. In practice, this may not matter. However, if it does, you might need to adapt the algorithm slightly. For example, possibly by introducing another class into the mix, like this:”
Excerpt From: David Beazley. “Python Cookbook.” iBooks. My question are:
Under what circumstancespotential danger
Here are the questions:
1: Under what circumstance does this potential danger would happen
2: How does the additional Visit
Class come to fix it?
(I don't understand and as far as I can see the Visit
class is merely a useless wrapper on the node
)
(May be just because I am stupid, could someone explain it to me in more detail and with some code probably? Thanx for reading)
Aucun commentaire:
Enregistrer un commentaire