The Value function returns the value of a symbol, and optionally assigns the name a new value. Normally, symbols are accessed within the current procedure scope; including exposed symbols. Alternatively, the Value function accesses symbols in external pools.
You can often use the Value function instead of the Interpret instruction.
result = Value( symbol [, [ newvalue ] [, pool ] ] ) |
Please observe:
v = 'this' symbol.v = 'that' -- SYMBOL.this = that .. but SYMBOL.THIS is undefined say symbol.v -- shows: that say value( 'SYMBOL.'v ) -- shows: SYMBOL.THIS [expected: that] |
Contrast the above with the following, where the part of a compound name's value is 'THIS'.
v = 'THIS' symbol.v = 'that' -- SYMBOL.THIS = that say symbol.v -- shows: that say value( 'SYMBOL.'v ) -- shows: that |
Examples:
/* the following instructions establish the context for the value function calls */ drop a3
/* now study the results of the value function calls */ say Value( 'a'k ) -- shows: A3 .. an unassigned symbol say Value( 'a'k || k ) -- shows: 7 .. the value of symbol a33 say Value( 'fred' ) -- shows: K .. the value of symbol FRED say Value( fred ) -- shows: 3 .. the value of symbol K say Value( fred, 4 ) -- shows: 3 .. then assigns K the value 4 call Value fred, 5 -- assigns K the value 5 say Value( fred ) -- shows: 5 .. shows that indeed K was assigned the value 5 say Value( 'LIST.'k ) -- shows: ? .. the value of list.5
/* this shows how to prevent an invalid call to the Value function */ char = '>' if symbol( char ) = 'BAD' then
else
/* external pool value function requests */ say Value( 'Destination', 'Vienna', 'Vacation' )'_' -- shows: _ .. prior destination is empty, and assigns new destination say Value( 'Destination', 'Belgrade', 'Vacation' ) -- shows: Vienna .. prior destination, and assigns new destination call Value 'Destination', 'Nice', 'Vacation' -- assigns new destination say Value( 'Destination', , 'Vacation' ) -- shows: Nice |