Operators

rascal-0.34.0

Synopsis​

The Rascal operators.

Syntax​

Some example operators:

``Exp + ExpExp [ Exp ]! ExpExp 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 . Name`Select 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 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?`IsDefinedTest whether an expression has a defined value
`!Exp`NegationNegate a Boolean value
`- Exp`NegationNegation 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
ConcatenationConcatenate strings
ConcatenationConcatenate lists
Insert AppendInsert and Append list elements
ConcatenationConcatenate tuples
UnionSet union
UnionMap "union"
`Exp₁ - Exp₂`Subtraction
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 := Exp`MatchPattern matches value of expression
`Pat !:= Exp`NoMatchPattern 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