EVALSCOPE

Purpose:

Evaluates the input expression at a specified scope level.

Syntax:

EVALSCOPE("expr", scope)

"expr"

-

A string, any valid expression.

scope

-

Optional. An integer, the execution scope:

-1 :

lowest scope

0 :

current scope (default)

1 :

global scope

Returns:

A string, series, table, or number.

Example:

evfun(n=1)
{
    evalscope(sprintf("l_var = %d", n), 0);
 
    evalscope(sprintf("g_var = %d", l_var + 1), 1);
}

 

Creates an SPL routine that sets two variables.

 

The first expression creates and sets the local variable l_var because EVALSCOPE executes at local scope.

 

The second expression creates and sets a global variable g_var because EVALSCOPE executes at global scope

 

evfun(12)

 

create the global g_var with a value of 13.

 

Example:

evfun2(n=1)
{
    evalscope(sprintf("l_var = %d", n), 0);
 
    evalscope("g_var = l_var + 1", 1);
}

 

Similar to above, except an error will occur with the execution of the second statement.

 

Even though the local variable l_var is created by the first statement, because the second statement executes entirely at global scope, it does not have access to the local variable and an error is thrown.

 

evfun2(12)

 

produces the error: l_var: Unknown Variable.

Remarks:

Multiple statements separated by semicolons are treated as a single unit in DADiSP. That is, they are evaluated as a group, and all macros on the line are expanded before the statements are evaluated.

 

EVALCSOPE accepts a string as its input argument and evaluates the argument.

 

EVALSCOPE("expression", -1) executes at the lowest scope and does not interfere with the current scope.

 

EVALSCOPE("expression") or EVALSCOPE("expression", 0) is identical to EVAL("expression").

 

EVALSCOPE("expression", 1) operates at global scope.

 

See FEVAL to evaluate a function string with explicit arguments.

 

See EVAL to evaluate an expression at the current scope.

 

See EXECUTE to evaluate a command string in DADiSP as an ActiveX Automation Server.

See Also:

; (SEMICOLON)

EVAL

EVALTOSTR

EXECUTE

FEVAL