# Operators

rascal-0.30.1

#### Synopsis

The Rascal operators.

#### Syntax

Some example operators:

`Exp + Exp`

Exp [ Exp ]

! Exp

Exp in Exp

#### Description

An *operator expression* consists of an operator and one or more operands. The evaluation order of the operands depends on the operator.
The operator is applied to the operands and the resulting value (or values in some cases) is the result of the operator expression.

All operators are summarized in the following table. They are listed from highest precedence to lowest precedence. In other words, operators listed earlier in the table bind stronger.

Operator | See | Short Description |
---|---|---|

`Exp . Name` | Select named field from structured value | |

Location fields | ||

DateTime fields | ||

Tuple fields | ||

Relation columns | ||

`Exp₁ [ Name = Exp₂ ]` | FieldAssignment FieldAssignment FieldAssignment | Change value of named field of structured value |

`Exp < field₁, ... >` | FieldProjection, FieldProjection | Select fields from relation or structured value |

`Exp is Name` | Check if `Exp` has name `Name` | |

Parse Tree, | ||

ConcreteSyntax, | ||

Algebraic Data Type | ||

`Exp has Name` | Check if a field with `Name` is present on `Exp` | |

Parse Tree | ||

ConcreteSyntax | ||

Algebraic Data Type | ||

`Exp₁ [ Exp₂ , Exp₃, .... ]` | Project values for given key from list, map, tuple or relation. | |

list | ||

map | ||

tuple | ||

relation | ||

`Exp₁ [ Exp₂ , Exp₃ .. Exp₄ ]` | Retrieve a slice from a list, string, or node. | |

list | ||

string | ||

node | ||

`Exp?` | IsDefined | Test whether an expression has a defined value |

`!Exp` | Negation | Negate a Boolean value |

`- Exp` | Negation | Negation of numbers |

`Exp +` | Transitive closure on relation or list relation | |

Relation + | ||

List + | ||

`Exp *` | Reflexive transitive closure on relation or list relation | |

Relation *, | ||

List * | ||

`Exp₁ o Exp₂` | Exp₁ and Exp₂ should evaluate to a relation or map; return their composition. Note: the letter "o" is thus a keyword | |

relation | ||

map | ||

`Exp₁ / Exp₂` | Division | Divide two numbers |

`Exp₁ % Exp₂` | Remainder | Remainder on numbers |

`Exp₁ * Exp₂` | Products | |

number | Multiply numbers | |

list | Cartesian product on lists | |

set | Cartesian product on sets | |

relation | Cartesian product on relations | |

`Exp₁ & Exp₂` | Intersection | |

list intersection | ||

set intersection | ||

map intersection | ||

`Exp₁ + Exp₂` | Sums | |

Addition | Add numbers | |

Concatenation | Concatenate strings | |

Concatenation | Concatenate lists | |

Insert Append | Insert and Append list elements | |

Concatenation | Concatenate tuples | |

Union | Set union | |

Union | Map "union" | |

AddSegment | Adding path segments to locations | |

`Exp₁ - Exp₂` | Subtraction | |

numbers | subtraction of numbers | |

lists | difference on lists | |

sets | set difference | |

maps | map difference | |

`Exp₁ join Exp₂` | Join Join on relation | |

`Exp₁ in Exp₂` | test membership | |

list | list membership | |

set | set membership | |

map | map key membership | |

`Exp₁ notin Exp₂` | inverse membership | |

list | list membership | |

set | set membership | |

map | map key membership | |

`Exp₁ <= Exp₂` | reflexive less-than | |

number | numbers | |

string | strings | |

location | locations | |

datetime | datetime | |

list | list | |

set | set | |

map | map | |

`Exp₁ < Exp₂` | irreflexive less-than | |

number | numbers | |

string | strings | |

location | locations | |

datetime | datetime | |

list | list | |

set | set | |

map | map | |

`Exp₁ >= Exp₂` | reflexive greater-than | |

number | numbers | |

string | strings | |

location | locations | |

datetime | datetime | |

list | list | |

set | set | |

map | map | |

`Exp₁ > Exp₂` | irreflexive greater-than | |

number | numbers | |

string | strings | |

location | locations | |

datetime | datetime | |

list | list | |

set | set | |

map | map | |

`Pat := Exp` | Match | Pattern matches value of expression |

`Pat !:= Exp` | NoMatch | Pattern does not match value of expression |

`Exp₁ == Exp₂` | Equality | |

numbers | ||

strings | ||

locations | ||

datetime | ||

lists | ||

sets | ||

maps | ||

`Exp₁ != Exp₂` | Inequality | |

numbers | ||

strings | ||

locations | ||

datetime | ||

lists | ||

sets | ||

maps | ||

`Exp₁ ? Exp₂` | IfDefinedElse | Value of expression when it is defined, otherwise alternative value |

`Exp₁ ? Exp₂ : Exp₃` | Conditional | Conditional expression for all types |

`Exp₁ ==> Exp₂` | Implication | Implication on Boolean values |

`Exp₁ <==> Exp₂` | Equivalence | Equivalence on Boolean values |

`Exp₁ && Exp₂` | And | And on Boolean values |

`Exp₁ \|\| Exp₂` | Or | Or on Boolean values |