Navigation
Synopsis Variable in abstract pattern.
Syntax Var
Description A variable pattern can act in two roles:
  • If Var has already a defined value then it matches with that value.
  • If Var has not been defined before (or it has been declared but not initialized) then it matches any value. That value is assigned to Var. The scope of this variable is the outermost expression in which the pattern occurs or the enclosing If, While, or Do if the pattern occurs in the test expression of those statements.
Examples Initialize variable N
rascal>N = 10;
int: 10
and use N in a pattern; its value is used as value to match with:
rascal>N := 10;
bool: true
rascal>N := 20;
bool: false
Use a non-existing variable in a pattern, it is bound when the match succeeds:
rascal>import IO;
ok
rascal>if(M := 10)
>>>>>>>   println("Match succeeded, M == <M>");
Match succeeded, M == 10
ok
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.