@@ -395,8 +395,8 @@ We'll consider postorder traversal first, as it's the easier to implement.
395
395
tree: TreeNode
396
396
The tree to be visited.
397
397
fn: function(node, *fn_children)
398
- A function to be applied at each node. The function should take the
399
- node to be visited as its first argument, and the results of
398
+ A function to be applied at each node. The function should take
399
+ the node to be visited as its first argument, and the results of
400
400
visiting its children as any further arguments.
401
401
"""
402
402
return fn(tree, *(postvisitor(c, fn) for c in tree.children))
@@ -480,8 +480,8 @@ call :func:`previsitor` on the child nodes.
480
480
tree: TreeNode
481
481
The tree to be visited.
482
482
fn: function(node, fn_parent)
483
- A function to be applied at each node. The function should take the
484
- node to be visited as its first argument, and the result of
483
+ A function to be applied at each node. The function should take
484
+ the node to be visited as its first argument, and the result of
485
485
visiting its parent as the second.
486
486
"""
487
487
fn_out = fn(tree, fn_parent)
@@ -776,7 +776,8 @@ function.
776
776
Any keyword arguments required to evaluate specific types of
777
777
expression.
778
778
symbol_map: dict
779
- A dictionary mapping Symbol names to numerical values, for example:
779
+ A dictionary mapping Symbol names to numerical values, for
780
+ example:
780
781
781
782
{'x': 1}
782
783
"""
@@ -819,24 +820,24 @@ function.
819
820
return o[0] ** o[1]
820
821
821
822
Next we turn our attention to the implementation of evaluation for the different
822
- expression types. Look first at lines 27-29 , which provide the evaluation of
823
+ expression types. Look first at lines 28-30 , which provide the evaluation of
823
824
:class: `Number ` nodes. The function body is trivial: the evaluation of a
824
825
:class: `Number ` is simply its value. The function interface is more interesting.
825
826
Notice that the function name is given as `_ `. This is the Python convention for
826
827
a name which will never be used. This function will never be called by its
827
- declared name. Instead, look at the decorator on line 27 . The single dispatch
828
+ declared name. Instead, look at the decorator on line 28 . The single dispatch
828
829
function :func: `~example_code.expression_tools.evaluate ` has a :term: `method `
829
830
:meth: `register `. When used as a decorator, the :meth: `register ` method of a
830
831
single dispatch function registers the function that follows as implementation
831
832
for the :keyword: `class ` given as an argument to :meth: `register `. On this
832
833
occasion, this is :class: `expressions.Number `.
833
834
834
- Now look at lines 32-34 . These contain the implementation of
835
+ Now look at lines 33-35 . These contain the implementation of
835
836
:func: `~example_code.expression_tools.evaluate ` for :class: `expressions.Symbol `.
836
837
In order to evaluate a symbol, we depend on the mapping from symbol names to
837
838
numerical values that has been passed in.
838
839
839
- Finally, look at lines 37-39 . These define the evaluation visitor for addition.
840
+ Finally, look at lines 38-40 . These define the evaluation visitor for addition.
840
841
This works simply by adding the results of evaluating the two operands of
841
842
:class: `expressions.Add `. The evaluation visitors for the other operators
842
843
follow in an analogous manner.
@@ -869,8 +870,8 @@ function.
869
870
expr: Expression
870
871
The expression to be visited.
871
872
fn: function(node, *o, **kwargs)
872
- A function to be applied at each node. The function should take the
873
- node to be visited as its first argument, and the results of
873
+ A function to be applied at each node. The function should take
874
+ the node to be visited as its first argument, and the results of
874
875
visiting its operands as any further positional arguments. Any
875
876
additional information that the visitor requires can be passed in
876
877
as keyword arguments.
0 commit comments