Operators

See WebL Core Operators lists the operatorsof the WebL core language. To illustrate how operators are overloaded, we use a functional notation even though the operators are written in infix, prefix, or right-bracket fix. For example,

op(x: T, y: S): U

 

denotes that an infix operator op takes a first operand of x of type T and a second operand y of type S, and returns a value of type U. Unary operators have only a single argument to specify.

Two special operators are not contained in the operator table, since they have special constraints on when they can be used and hence cannot be specified in the syntax just introduced. The two operators are assignment ("=") and field definition (":=").

The left-hand side of an assignment must denote a variable or an object and field name combination. The left-hand side of a field definition must denote an object and field name combination, eg. obj[field] or obj.field. The value of an assignment or field definition is always the right-hand side of the operator. These two operators also differ in another way from the remainder of the operators, in that they have side-effects, namely the setting of the value of a variable or field of an object to the right-hand side of the operator.

 

WebL Core Operators

Operator

Description

+(x: int, y: int): int
+(x: int, y: real): real
+(x: real, y: int): real
+(x: real, y: real): real

Numeric addition x + y.

+(x: char, y: string): string
+(x: char, y: char): string
+(x: string, y: string): string
+(x: string, y: char): string

String and character concatenation.

+(x: set, y: set): set

Set union.

+(x: list, y: list): list

List concatenation.

-(x: int, y: int): int
-(x: int, y: real): real
-(x: real, y: int): real
-(x: real, y: real): real

Numeric substraction.

-(x: int): int
-(x: real): real

Numeric negation.

-(x: set, y: set): set

Set exclusion.

*(x: int, y: int): real
*(x: int, y: real): real
*(x: real, y: int): real
*(x: real, y: real): real

Numeric multiplication.

*(x: set, y: set): set

Set intersection.

/(x: int, y: int): int
/(x: int, y: real): real
/(x: real, y: int): real
/(x: real, y: real): real

Numeric division.

div(x: int, y: int): int

Whole division.

mod(x: int, y: int): int

x mod y.

C(x: int, y: int): bool
C(x: int, y: real): bool
C(x: real, y: int): bool
C(x: real, y: real): bool

Numerical comparison, where C is one of <, <=, >, or >=.

C(x: string, y: string): bool
C(x: char, y: char): bool

Lexical comparison, where C is one of <, <=, >, or >=.

== (x, y): bool

Value equality test. See Value Equality

!=(x, y): bool

Value in-equality test. See Value Equality

or(x: bool, y: bool): bool
and(x: bool, y: bool): bool

Logical operators (Short-circuit evaluation).

!(x: bool): bool

Logical negation.

.(x: object, y): any

Object field access.

[](x: list, i: int): any
[](x: object, i): any
[](x: string, i: int): char

List, object, and string indexing1. Elements in a list and string are numbered from 0 to Size-1.

member(x, s: set): bool
member(x, l: list): bool
member(x, o: object): bool

Set, list and object2 membership test.


1. Operator is written in the form x[i].

2. Object membership test is based on object field names.


Up Previous Next