66 lines
1.3 KiB
Plaintext
66 lines
1.3 KiB
Plaintext
// Literal
|
|
rascal>123 := 123
|
|
bool: true
|
|
|
|
// VariableDeclaration
|
|
rascal>if(str S := "abc")
|
|
>>>>>>> println("Match succeeds, S == \"<S>\"");
|
|
Match succeeds, S == "abc"
|
|
ok
|
|
|
|
// MultiVariable
|
|
rascal>if([10, N*, 50] := [10, 20, 30, 40, 50])
|
|
>>>>>>> println("Match succeeds, N == <N>");
|
|
Match succeeds, N == [20,30,40]
|
|
ok
|
|
|
|
// Variable
|
|
rascal>N = 10;
|
|
int: 10
|
|
rascal>N := 10;
|
|
bool: true
|
|
rascal>N := 20;
|
|
bool: false
|
|
|
|
// Set and List
|
|
rascal>if({10, set[int] S, 50} := {50, 40, 30, 20, 10})
|
|
>>>>>>> println("Match succeeded, S = <S>");
|
|
Match succeeded, S = {30,40,20}
|
|
ok
|
|
|
|
rascal>for([L1*, L2*] := [10, 20, 30, 40, 50])
|
|
>>>>>>> println("<L1> and <L2>");
|
|
[] and [10,20,30,40,50]
|
|
[10] and [20,30,40,50]
|
|
[10,20] and [30,40,50]
|
|
[10,20,30] and [40,50]
|
|
[10,20,30,40] and [50]
|
|
[10,20,30,40,50] and []
|
|
list[void]: []
|
|
|
|
// Descendant
|
|
rascal>T = red(red(black(leaf(1), leaf(2)), black(leaf(3), leaf(4))), black(leaf(5), leaf(4)));
|
|
rascal>for(/black(_,leaf(4)) := T)
|
|
>>>>>>> println("Match!");
|
|
Match!
|
|
Match!
|
|
list[void]: []
|
|
|
|
rascal>for(/black(_,leaf(int N)) := T)
|
|
>>>>>>> println("Match <N>");
|
|
Match 2
|
|
Match 4
|
|
Match 4
|
|
list[void]: []
|
|
|
|
rascal>for(/int N := T)
|
|
>>>>>>> append N;
|
|
list[int]: [1,2,3,4,5,4]
|
|
|
|
// Labelled
|
|
rascal>for(/M:black(_,leaf(4)) := T)
|
|
>>>>>>> println("Match <M>");
|
|
Match black(leaf(3),leaf(4))
|
|
Match black(leaf(5),leaf(4))
|
|
list[void]: []
|