![]() |
|
Navigation |
Synopsis Labelled abstract pattern.
Syntax
Var : Pat
Description A labelled pattern matches the same values as
Pat , but has as side-effect that the matched value is assigned to Var .
Examples
rascal>import IO; ok rascal>data ColoredTree = leaf(int N) >>>>>>> | red(ColoredTree left, ColoredTree right) >>>>>>> | black(ColoredTree left, ColoredTree right); ok rascal>T = red(red(black(leaf(1), leaf(2)), black(leaf(3), leaf(4))), black(leaf(5), leaf(4))); ColoredTree: red( red( black( leaf(1), leaf(2)), black( leaf(3), leaf(4))), black( leaf(5), leaf(4))) rascal>for(/M:black(_,leaf(4)) := T) >>>>>>> println("Match <M>"); Match black(leaf(3),leaf(4)) Match black(leaf(5),leaf(4)) list[void]: []We use an anonymous variable _ at a position where we don't care about the actual value that is matched.
![]() |