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:”</p>

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)

4

1 回答 1

0

我终于明白了,包装一个Visit类,
帮助访问者实际返回最终结果作为整个节点
而不是它的(节点)展开结果,如果需要,我们可以选择中止访问过程。

于 2017-11-08T04:20:53.527 回答