Programmer Guide/Command Reference/EVAL Intro/EVAL: Difference between revisions
No edit summary |
|||
Line 1: | Line 1: | ||
{{DISPLAYTITLE:{{SUBPAGENAME}}}} | {{DISPLAYTITLE:{{SUBPAGENAME}}}} | ||
The <code>EVAL</code> command can be used to evaluate numerical expressions. These expressions can be constants, scalar variables, vectors, matrices or <code>[[Programmer Guide/Command Reference/EVAL/EVAL Subcommands|EVAL]]</code>[[Programmer Guide/Command Reference/EVAL_Intro/EVAL Subcommands| subcommands]]. | The <code>EVAL</code> command can be used to evaluate numerical expressions. These expressions can be constants, scalar variables, vectors, matrices or <code>[[Programmer Guide/Command Reference/EVAL/EVAL Subcommands|EVAL]]</code>[[Programmer Guide/Command Reference/EVAL_Intro/EVAL Subcommands| subcommands]]. | ||
// if the variable #v does not exist then the following command | |||
// assigns a table item to #v. | |||
$#v := eval vv(1,2,3,4) | |||
// if #v is a value item, then #v remains a value item. | |||
== Syntax == | |||
Syntax | |||
An <code>EVAL</code> command uses the following general syntax: | An <code>EVAL</code> command uses the following general syntax: | ||
<code>result := eval expression</code> | |||
<code>result := eval expression</code> | <code>result := evalcheck expression</code> | ||
An expression may be either a numerical expression, e.g. | |||
<code>result := evalcheck expression</code> | <code>result := eval (5 * 10) % 3</code> | ||
An expression | |||
<code>result := eval (5 * 10) % 3</code> | |||
or a subcommand, e.g. | or a subcommand, e.g. | ||
<code>result := eval init(10,1,1)</code> | |||
<code>result := eval init(10,1,1)</code> | |||
or a combination thereof: | or a combination thereof: | ||
<code>result := eval 5+max(fill(6,1,1))</code> | |||
<code>result := eval 5+max(fill(6,1,1))</code> | |||
If the expression is syntactically ill-formed, an error (<code>EVAL</code>) or warning (<code>EVALCHECK</code>) is reported. See the example script <code>expression_check.sts</code> for details. | If the expression is syntactically ill-formed, an error (<code>EVAL</code>) or warning (<code>EVALCHECK</code>) is reported. See the example script <code>expression_check.sts</code> for details. | ||
Numerical | === Numerical Comparison Operators === | ||
The <code>EVAL</code> command supports the following numerical comparison operators: | |||
{| | {| | ||
|- | |- | ||
Line 56: | Line 44: | ||
Note that two numbers/vectors/matrices are considered equal if (and only if) | Note that two numbers/vectors/matrices are considered equal if (and only if) | ||
# their dimensions are the same; and | |||
# all elements are numerically equal. | |||
=== Logical Operators === | |||
The <code>EVAL</code> command supports the following logical operators: | |||
{| | {| | ||
|- | |- | ||
Line 75: | Line 63: | ||
A C<nowiki>-</nowiki>like '<code>? :'</code> operator is also supported: | A C<nowiki>-</nowiki>like '<code>? :'</code> operator is also supported: | ||
<code>result := eval 1 < 2 ? 1+2 : 1-2 // result is 3</code> | |||
<code>result := eval 1 < 2 ? 1+2 : 1-2 // result is 3</code> | |||
Note that unlike C, nested uses of this operator must be surrounded by brackets, e.g.: | Note that unlike C, nested uses of this operator must be surrounded by brackets, e.g.: | ||
<code>result := eval 1 > 2 ? (5 == 5 ? 5 : 0) : (4 == 5 ? 3 : 4) // returns 4</code> | |||
=== Examples === | |||
See the script <code>eval_examples.sts</code> for an extensive list of examples. | See the script <code>eval_examples.sts</code> for an extensive list of examples. | ||
=== Version History === | |||
The <code>EVAL</code> command was added to the S_TOOLS-STx language in version 3.7.0. The <code>EVAL</code> command replaces and extends the <code>EVALUATE</code> command. If the <code>EVAL</code> command is not assigning to an existing item, a table is assigned. Note that the current maximum number of arguments is 64 (S_TOOLS-STx version 3.8.0). As of version 3.7.0, S_TOOLS-STx has more [[Programmer Guide/Command Reference/EVAL/Numerical objects|numerical objects]] than just the scalars <code>INT</code> and <code>NUM</code>. | The <code>EVAL</code> command was added to the S_TOOLS-STx language in version 3.7.0. The <code>EVAL</code> command replaces and extends the <code>EVALUATE</code> command. If the <code>EVAL</code> command is not assigning to an existing item, a table is assigned. Note that the current maximum number of arguments is 64 (S_TOOLS-STx version 3.8.0). As of version 3.7.0, S_TOOLS-STx has more [[Programmer Guide/Command Reference/EVAL/Numerical objects|numerical objects]] than just the scalars <code>INT</code> and <code>NUM</code>. | ||
{| | {| | ||
|- | |- | ||
| | | | ||
|} | |} |
Revision as of 20:56, 22 March 2011
The EVAL
command can be used to evaluate numerical expressions. These expressions can be constants, scalar variables, vectors, matrices or EVAL
subcommands.
// if the variable #v does not exist then the following command // assigns a table item to #v. $#v := eval vv(1,2,3,4) // if #v is a value item, then #v remains a value item.
Contents
Syntax
An EVAL
command uses the following general syntax:
result := eval expression
result := evalcheck expression
An expression may be either a numerical expression, e.g.
result := eval (5 * 10) % 3
or a subcommand, e.g.
result := eval init(10,1,1)
or a combination thereof:
result := eval 5+max(fill(6,1,1))
If the expression is syntactically ill-formed, an error (EVAL
) or warning (EVALCHECK
) is reported. See the example script expression_check.sts
for details.
Numerical Comparison Operators
The EVAL
command supports the following numerical comparison operators:
>
|
less than |
<
|
greater than |
<=
|
less than or equal to |
>=
|
greater than or equal to |
==
|
equal to |
!=
|
not equal to |
Note that two numbers/vectors/matrices are considered equal if (and only if)
- their dimensions are the same; and
- all elements are numerically equal.
Logical Operators
The EVAL
command supports the following logical operators:
|
logical or | |
&&
|
logical and | |
!
|
unary not |
A C-like '? :'
operator is also supported:
result := eval 1 < 2 ? 1+2 : 1-2 // result is 3
Note that unlike C, nested uses of this operator must be surrounded by brackets, e.g.:
result := eval 1 > 2 ? (5 == 5 ? 5 : 0) : (4 == 5 ? 3 : 4) // returns 4
Examples
See the script eval_examples.sts
for an extensive list of examples.
Version History
The EVAL
command was added to the S_TOOLS-STx language in version 3.7.0. The EVAL
command replaces and extends the EVALUATE
command. If the EVAL
command is not assigning to an existing item, a table is assigned. Note that the current maximum number of arguments is 64 (S_TOOLS-STx version 3.8.0). As of version 3.7.0, S_TOOLS-STx has more numerical objects than just the scalars INT
and NUM
.