October 2015
Beginner to intermediate
400 pages
14h 44m
English
Display, a Recursive Value Printer
Next we’ll take a look at how to improve the display of composite
types. Rather than try to copy fmt.Sprint exactly,
we’ll build a debugging utility function called Display that,
given an arbitrarily complex value x, prints the complete
structure of that value, labeling each element
with the path by which it was found.
Let’s start with an example.
e, _ := eval.Parse("sqrt(A / pi)")
Display("e", e)
In the call above, the argument to Display is a syntax
tree from the expression evaluator in Section 7.9.
The output of Display is shown below:
Display e (eval.call): e.fn = "sqrt" e.args[0].type = eval.binary e.args[0].value.op = 47 e.args[0].value.x.type ...