Operators

Operators are special symbols that perform specific operations on one, two, or three operands, and then return a result.

This page discusses:

Arithmetic operators

operators that perform addition, subtraction, multiplication, and division.

+ Addition operator (also concatenates strings)
- Subtraction operator
* Multiplication operator
/ Division operator
** Exponentiation operator

Assignment Operator

= Can be used with values, enumerates, objects (object A = object B if B is a subtype of A).

Note: This operator is not available in the Set of Equations editor.

Logical Operators

and Logical conjunction on two expressions
or Logical disjunction on two expressions
not A function that takes a boolean in input and returns the other value true false, false true.
Note: Lazy evaluation is implemented.
  • Given the following expression: predicate1 and predicate2, where predicate can be any expression returning a Boolean value. If predicate1 equals false then predicate2 is not evaluated.
  • Given the following expression: predicate1 or predicate2. If predicate1 equals true then predicate2 is not evaluated.

Comparison Operators

<> Not equal to (Applies to values and objects)
== Equal to (Applies to values and objects)
>= Greater or equal to (Applies to values only)
<= Less than or equal to (Applies to values only)
< Less than (Applies to values only)
> Greater than (Applies to values only)

Type Operator

: Equivalent to the set keyword.

Ternary Operator

"predicate ? rightvalue1 ; rightvalue2" Provides EKL users with an abbreviated form of the if ... then ... else syntax. It also lets users introduce conditions in formulas.

Note: rightvalue stands for any expression that can be placed at the right of an assignment.

Example
let x (Integer)
x = (2==2) ? 1 ; 3
Example 2: 
Let p,q,r (Point)
p=point(1mm,2mm,3mm)
q=point(4mm,5mm,6mm)
r = distance(p,q)> 2mm ? point(7mm,8mm,9mm) ; point(10mm,11mm,12mm) 
Notes:
  • The ternary expression is a right-hand side term:
    let x(Integer)
    X= (2==2) ? 3 ; 3
    
  • Lists are not supported by this operator, but you can use a cast:
    let l(list)
    let x(Integer)
    l = List(1,2)
    X= (2==2) ? l->GetItem(1):Integer ; l->GetItem(2):Integer
  • The two right value terms should have a common type. In the following example 1 and 2mm have the real type in common.
    let x(Integer)
    x= (2==2) ? 1 ; 2mm
    

Operators and Strings

You can use the +,-,*,= operators with strings.

+ Operator
String + Real, Real + String, String + Boolean, Boolean + String returns a string.

In the example below, + is also valid for any subtype of Real.

s = "TestString" + 555 // s==”TestString555”
s = "TestString" + 55m_s // s == “TestString55m_s”

- Operator
String - String : Returns a string and removes the occurrences of the second string (right) the first string (left). This operator multiplies the string a number of times equal to the value of the Integer.
s = 5 * "TestString" // s == TestStringTestStringTestStringTestStringTestString
* Operator
Integer * String, String * Integer returns a string.
ss = "TestAAABBBCCCDDDDDTest" – “DDD” // ss == TestAAABBBCCCDDTest
ss = " TestAAABBBCCCDDDAAATest " – “AAA” // ss == TestBBBCCCDDDTest
: Operator
String = Real or String = Boolean. This operation allows your to define a String directly from a Real (or a sub-type of Real) or Boolean without using the toString function.
Let s(String)
s = true // s=="true”
s = 55m_s // s==”55m_s”