7.10.7 Eval function

Prev Up Next Page 224 of 800 Search internet

The base page defines a function named eval ( t , s , c ) which returns the value of the parse tree t for the cache c. The value of s can be used to assign values to free variables in t.

The value of s must be an association list, i.e. a list of form

<< v _ { 1 } :: V _ { 1 } ,, ... ,, v _ { n } :: V _ { n } >>

where v _ { i } is a variable given as a parse tree and V _ { i } is the associated value.

It is usual to invoke the eval function as eval ( t , true , c ), i.e. to invoke it with an empty association list.

A 'variable' is a parse tree whose principal operator does not have a value of its own. In other words, a variable is a parse tree whose principal operator is not a string, not a page symbol, and does not have a value definition according to the codex c. Feel free to include non-variables in the association list s; the eval function will just ignore them.

Unbound variables have value true. This holds both for the eval function and for value definitions which have unbound variables in their right hand side. If you think eval should complain about unbound variables, write your own eval. If you think lgc(1) should whine when it sees an unbound variable in the right hand side of a value definition, write a verifier which detects that problem. As usual, if you want to share your work, publish it on Logiweb.

Variables are compared using tree equality. Thus, variables like v _ { 1 } and v _ { 2 } are distinct variables even though they both have a subscript construct as principal operator. Variables like v _ { 1 } and v _ { 2 } can be used both in the association list s passed to the eval function and in left hand sides of value definitions.

Prev Up Next Page 224 of 800 Search logiweb.eu

Copyright © 2010 Klaus Grue, GRD-2010-01-05