next up previous contents index
Next: Manipulating Variable Argument Lists Up: Predefined Functions and Variables Previous: Manipulating Symbols

eval Function

    The eval function is used to evaluate a string as a glish statement and return the result. This is probably most useful for things like allowing users to enter Glish commands from a GUI. Here is an example of how eval is used:

    x := 10
    y := 18
    print eval("y +:= 2", "x * y")
In this example, the output will be 200, and y will equal 20. Currently, the strings passed to eval are always evaluated in the global scope. This is true even if eval is called from a function; this is a bug. The result is the following unexpected behavior:  
    x := 10
    y := 18
    func foo() { y := 2; return eval("y +:= 2", "x * y") }
    print foo()
This example results in output of 200 and the global y equal to 20 (the same as the previous example). This will hopefully be fixed in a later release.  

Thu Nov 13 16:44:05 EST 1997