Navigation
Synopsis The Rascal operators.
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.



















Rascal Operators (from highest to lowest precedence)
Operator See Short Description
Exp . Name Location/FieldSelection, DateTime/FieldSelection, Tuple/FieldSelection, Relation/FieldSelection Select named field from structured value
Exp1 [ Name = Exp2 ] FieldAssignment Change value of named field of structured value
Exp < field1, ... > FieldProjection Select fields from relation or structured value
Exp is Name ParseTree, ConcreteSyntax, AlgebraicDataType Returns true if and only if the constructor name of the value produced by Exp is equal to $Name
Exp has Name ParseTree, ConcreteSyntax, AlgebraicDataType Returns true if and only if the constructor (node or parse tree) of the value produced by Exp has any field labeled $Name
Exp1 [ Exp2 , Exp3, .... ] List/Subscription, Map/Subscription, Tuple/Subscription, Relation/Subscription Retrieve values for given index/key from list, map, tuple or relation.
Exp1 [ Exp2 , Exp3 .. Exp4 ] Values/List/Slice, String/Slice, Node/Slice Retrieve a slice from a list, string, or node.
Exp? Boolean/IsDefined Test whether an expression has a defined value
!Exp Boolean/Negation Negate a Boolean value
- Exp Number/Negation Negation of numbers
Exp + Relation/TransitiveClosure ListRelation/TransitiveClosure Transitive closure on relation or list relation
Exp * Relation/ReflexiveTransitiveClosure ListRelation/ReflexiveTransitiveClosure Reflexive transitive closure on relation or list relation
Exp @ Name Expressions/Selection Value of annotation Name of Exp's value
Exp1 [@ Name = Exp2] Expressions/Replacement Assign value of Exp2 to annotation Name of Exp1's value
Exp1 o Exp2 Relation/Composition, Map/Composition Exp1 and Exp2 should evaluate to a relation or map; return their composition. Note: the letter "o" is thus a keyword!
Exp1 / Exp2 Number/Division Divide two numbers
Exp1 % Exp2 Number/Remainder Remainder on numbers
Exp1 * Exp2 Number/Multiplication, List/Product, Set/Product, Relation/CartesianProduct Multiply numbers; product of list, set, or relation
Exp1 & Exp2 List/Intersection, Set/Intersection, Map/Intersection Intersection of list, set (including relation), or map
Exp1 + Exp2 Number/Addition, String/Concatenation, List/Concatenation, List/Insert,List/Append, Tuple/Concatenation, Expressions/Values/Set/Union, Expressions/Values/Map/Union, Location/AddSegment Add numbers; concatenate string, list or tuple; union on set (including relation), or map; concatenate location and string
Exp1 - Exp2 Number/Subtraction, List/Difference, Set/Difference, Map/Difference Subtract numbers; difference of list, set (including relation), or map
Exp1 join Exp2 Relation/Join Join on relation
Exp1 in Exp2 List/in, Set/in, Map/in Membership test for element in list, map, set (including relation)
Exp1 notin Exp2 List/notin, Set/notin, Map/notin Negated membership test for element in list, map, set (including relation)
Exp1 <= Exp2 Number/LessThanOrEqual, String/LessThanOrEqual, Location/LessThanOrEqual, DateTime/LessThanOrEqual, List/SubList, Set/SubSet, Map/SubMap Less than or equal on all values
Exp1 < Exp2 Number/LessThan, String/LessThan, Location/LessThan, DateTime/LessThan, List/StrictSubList, Set/StrictSubSet, Map/StrictSubMap Less than on all values
Exp1 >= Exp2 Number/GreaterThanOrEqual, String/GreaterThanOrEqual, Location/GreaterThanOrEqual, DateTime/GreaterThanOrEqual, List/SuperList, Set/SuperSet, Map/SuperMap Greater than or equal on all values
Exp1 > Exp2 Number/GreaterThan, String/GreaterThan, Location/GreaterThan, DateTime/GreaterThan, List/StrictSuperList, Set/StrictSuperSet, Map/StrictSuperMap Greater than on all values.
Pat := Exp Boolean/Match Pattern matches value of expression
Pat !:= Exp Boolean/NoMatch Pattern does not match value of expression
Exp1 == Exp2 Number/Equal, String/Equal, Location/Equal, DateTime/Equal, List/Equal, Set/Equal, Map/Equal Equality on all values
Exp1 != Exp2 Number/NotEqual, String/NotEqual, Location/NotEqual, DateTime/NotEqual, List/NotEqual, Set/NotEqual, Map/NotEqual Inequality on all values
Exp1 ? Exp2 Boolean/IfDefinedElse Value of expression when it is defined, otherwise alternative value
Exp1 ? Exp2 : Exp3 Value/Conditional Conditional expression for all types
Exp1 ==> Exp2 Boolean/Implication Implication on Boolean values
Exp1 <==> Exp2 Boolean/Equivalence Equivalence on Boolean values
Exp1 && Exp2 Boolean/And And on Boolean values
Exp1 || Exp2 Boolean/Or Or on Boolean values
Is this page unclear, or have you spotted an error? Please add a comment below and help us to improve it. For all other questions and remarks, visit ask.rascal-mpl.org.