Skip to main content Skip to navigation

Operators

Arithmetic Operators

Expressions with binary operators group left-to-right. The usual arithmetic conversions are performed.

arithmetic-expression:
        expression + expression
        expression - expression
        expression * expression
        expression / expression
        expression % expression
        - expression

The result of the + operator is the sum of the operands.

The result of the - operator is the difference of the operands.

The binary * operator indicates multiplication.

The binary / operator indicates division.

The binary % operator yields the remainder from the division of the first expression by the second. The two operands must be of integral type (i.e. integers or characters).

The unary - operator is the negative of its operand.

All arithmetic operators are strict, i.e. they return @ if either operand is @.

If both operands of an arithmetic expression are of integral type, the result is always an integer. If any operand is a floating point, the result is a floating point (except for the % operator which takes integral operands only).

String and List Operators

string-expression:
        expression // expression

list-formation-expression:
        expression // expression
        [ expression-listopt ]

expression-list:
        expression
        expression , expression-list

integer-expression:
        expression #

If the operands of // are of string or character type, the result will be a string which is the concatenation of the two operands. If the operands are of list type, the result will be a list which is the concatenation of the two operands. If either or both of the operands is @, the result will be @ (see pre-defined functions substr and sublist). The [] operator groups the values of the expressions into a list. The expression list is a list of expressions separated by commas. If the expression list is omitted the list returns a null list.

Pointer Operator

pointer-expression:
        & lvalue

The result of the unary & operator is a pointer to the object referred to by the lvalue.

Relational Operators

The relational operators group left-to-right, but this fact is not very useful; a<b<c (meaning (a<b)<c) does not mean what it seems to be ((a<b) and (b<c)), as in a normal mathematical expression.

relational-expression:
        expression < expression
        expression > expression
        expression <= expression
        expression >= expression

The operators < (less than), > (greater than), <= (less than or equal to) and >= (greater than or equal to) all yield 0 if the specified relation is false and 1 if it is true. The type of the result is integer. The usual arithmetic conversions are performed.

Two strings may be compared. Single characters are compared from the left to the right according to their codes in the machine's character set. Note that a string is always terminated by \0, so the shortest string is considered the smaller. Strings are equal only if their lengths as well as their contents are identical.

It is an error if the two operands are of different types, but if either argument in an relational expression is @ then the value is @. Lists and pointers cannot be compared using the relational operators.

Equality Operators

equality-expression:
        expression == expression
        expression != expression

The == (equal to) and != (not equal to) operators are exactly analogous to the relational operators except for their lower precedence (thus a<b == c<d is 1 whenever a<b and c<d have the same truth-value).

Note that two lists can be compared for equality. Lists are equal only if their lengths as well as their contents are identical. Two pointers can be compared for equality. Pointers are equal only if they points to the same object.

Logical Operators

logical-expression:
        expression && expression
        expression and expression
        expression || expression
        expression or expression
        ! expression
        not expression

Eden operates in 3-value logic (true, false and @). Any non-zero value means true; zero means false. In addition to the lazy operators (as in C, left-to-right evaluation, the second operand is evaluated only if necessary), eager operators - and, or, not - are also defined. Notice that the truth tables for the lazy and the corresponding eager operators are not identical.

@ && @ = @@ and @ = @@ || @ = @@ or @ = @
@ && F = @@ and F = @@ || F = @@ or F = @
@ && T = @@ and T = @@ || T = @@ or T = @
F && @ = FF and @ = @F || @ = @F or @ = @
F && F = FF and F = FF || F = FF or F = F
F && T = FF and T = FF || T = TF or T = T
T && @ = @T and @ = @T || @ = TT or @ = @
T && F = FT and F = FT || F = TT or F = T
T && T = TT and T = TT || T = TT or T = T
! @ = Tnot @ = @
! F = Tnot F = T
! T = Fnot T = F

Truth Tables for operators: &&, and, ||, or, !, not.

Conditional Operators

conditional-expression:
        expression ? expression : expression

Conditional expressions group right-to-left. The first expression is evaluated and if it is true, the result is the value of the second expression, otherwise (i.e. false or @) that of third expression. The second and third expressions need not have the same type; moreover only one of them is evaluated.

Assignment Operators

assignment-expression:
        lvalue = expression
        lvalue += expression
        lvalue -= expression
        ++ lvalue
        lvalue ++
        -- lvalue
        lvalue --

There are three binary assignment operators, =, +=, and -=, all of which group right-to-left. All require an lvalue as their left operand. The right operand is evaluated and the value stored in the left operand after the assignment has taken place.

In the simple assignment with =, the value of the expression replaces that of the object referred to by the lvalue.

The behaviour of an expression of the form E1 op= E2 may be inferred by taking it as equivalent to E1 = E1 op (E2); however, E1 is evaluated only once. Both of the operands must be of integral types.

The object referred to by the lvalue operand of prefix ++ is incremented. The value is the new value of the operand, but is not an lvalue. The expression ++x is equivalent to x+=1.

When postfix ++ is applied to an lvalue the result is the value of the object referred to by the lvalue. After the result is noted, the object is incremented in the same manner as for the prefix ++ operator. The type of the result is the same as the type of the lvalue expression.

The lvalue operands of the prefix and postfix -- is decremented analogously to the prefix and postfix ++ operators respectively.

All the objects referred to by the lvalues of these assignment operators must be read/write variables, not formula variables.

Precedence and Order of Evaluation

The table below summarizes the rules for precedence and associativity of all operators. Operators on the same line have the same precedence; rows are in order of decreasing precedence, so, for example, *, /, and % all have the same precedence which is higher than that of + and -.

OperatorPrecedence
() [] ``left to right
! not ++ -- - * & #right to left
* / %left to right
+ - //left to right
< <= > >=left to right
== !=left to right
&& andleft to right
|| orleft to right
?:right to left
= += -=right to left