EVAL

From STX Wiki
Jump to navigationJump to search

The EVAL command can be used to evaluate numerical, vector, and matrix expressions. These expressions may be built up from numerical constants, from scalar, vector, and matrix variables, and from a large number of EVAL subcommands, and operators.

// 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

An EVAL command uses the following general syntax:

result := eval expression

or

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)

  1. their dimensions are the same; and
  2. all elements are numerically equal.

Logical Operators

The EVAL command supports the following logical operators:

|| logical or
&& logical and
! unary not

A C-like '? :' selection 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) // result is 4

Navigation menu

Personal tools