0

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.

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)

patpat
  • 664
  • 1
  • 5
  • 14

1 Answers1

0

I finally got my senses, wrapping a Visit class,
help that the visitor could actually return the final result as a whole Node
instead of its(the Node) unfolding result, giving us an option to abort the visiting process if demand it.

patpat
  • 664
  • 1
  • 5
  • 14