Skip to main content

Operators

rascal-0.40.17

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.

OperatorSeeShort Description
Exp . NameSelect named field from structured value
Location fields
DateTime fields
Tuple fields
Relation columns
Exp₁ [ Name = Exp₂ ]FieldAssignment FieldAssignment FieldAssignmentChange value of named field of structured value
Exp < field₁, ... >FieldProjection, FieldProjectionSelect fields from relation or structured value
Exp is NameCheck if Exp has name Name
Parse Tree,
ConcreteSyntax,
Algebraic Data Type
Exp has NameCheck 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?IsDefinedTest whether an expression has a defined value
!ExpNegationNegate a Boolean value
- ExpNegationNegation 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₂DivisionDivide two numbers
Exp₁ % Exp₂RemainderRemainder on numbers
Exp₁ * Exp₂Products
numberMultiply numbers
listCartesian product on lists
setCartesian product on sets
relationCartesian product on relations
Exp₁ & Exp₂Intersection
list intersection
set intersection
map intersection
Exp₁ + Exp₂Sums
AdditionAdd numbers
ConcatenationConcatenate strings
ConcatenationConcatenate lists
Insert AppendInsert and Append list elements
ConcatenationConcatenate tuples
UnionSet union
UnionMap "union"
AddSegmentAdding path segments to locations
Exp₁ - Exp₂Subtraction
numberssubtraction of numbers
listsdifference on lists
setsset difference
mapsmap difference
Exp₁ join Exp₂Join Join on relation
Exp₁ in Exp₂test membership
listlist membership
setset membership
mapmap key membership
Exp₁ notin Exp₂inverse membership
listlist membership
setset membership
mapmap key membership
Exp₁ <= Exp₂reflexive less-than
numbernumbers
stringstrings
locationlocations
datetimedatetime
listlist
setset
mapmap
Exp₁ < Exp₂irreflexive less-than
numbernumbers
stringstrings
locationlocations
datetimedatetime
listlist
setset
mapmap
Exp₁ >= Exp₂reflexive greater-than
numbernumbers
stringstrings
locationlocations
datetimedatetime
listlist
setset
mapmap
Exp₁ > Exp₂irreflexive greater-than
numbernumbers
stringstrings
locationlocations
datetimedatetime
listlist
setset
mapmap
Pat := ExpMatchPattern matches value of expression
Pat !:= ExpNoMatchPattern 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₂IfDefinedElseValue of expression when it is defined, otherwise alternative value
Exp₁ ? Exp₂ : Exp₃ConditionalConditional expression for all types
Exp₁ ==> Exp₂ImplicationImplication on Boolean values
Exp₁ <==> Exp₂EquivalenceEquivalence on Boolean values
Exp₁ && Exp₂AndAnd on Boolean values
Exp₁ \|\| Exp₂OrOr on Boolean values