EVAL() Function - Evaluate Expression

Syntax

EVAL(str{,expr}{,ERR=lineref})

Description

In BBj 16.0 and higher, the EVAL() function can be used to replace the use of EXECUTE for evaluating dynamic expressions of any type (string, numeric, or object). EVAL() returns the value from the expression in str after compiling and executing the str. Error branches in str are not taken in the event of an error while evaluating the expression.

The optional second argument is a default value to be returned in the event of an error evaluating the expression.

Remarks

None.

Examples

READY
>load "eval.src"
 
READY
>/
rem ' eval
begin
print neval("sqr(-1)",0)
print eval("sqr(-1)","oops")
print seval("x$(2,2)","oops")
print eval("x$(2,2)","oops")
print eval("new Integer(42)")
print eval("new Oops()",null())
print eval("new Integer()",err=oops)
stop
oops:
print "correctly hit error handler:"
print errmes(-1),err
end
>run
 0
oops
oops
oops
42
null
correctly hit error handler:
No match for method java.lang.Integer.<init>() 252
 
READY
>

See Also

NEVAL() - Evaluate Numeric Expression

SEVAL() - Evaluate String Expression