Navigation
Synopsis Variable declaration in abstract pattern.
Syntax Type Var
Description A variable declaration
Type Var
can be used as abstract pattern. A variable declaration introduces a new variable Var that matches any value of the given type Type. That value is assigned to Var when the whole match succeeds.

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 Let's first perform a match that succeeds: As mentioned above: S is only bound in the scope of the match expression! Let's explore how bindings work in an if statement:
rascal>import IO;
ok
rascal>if(str S := "abc")
>>>>>>>   println("Match succeeds, S == \"<S>\"");
Match succeeds, S == "abc"
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.