2019-09-21 14:59:48 -07:00
|
|
|
// Test the pattern matching functionality of PascaLIGO
|
|
|
|
|
2019-05-12 20:56:22 +00:00
|
|
|
function match_bool (const i : int) : int is
|
2020-02-10 19:27:58 +01:00
|
|
|
block {
|
|
|
|
var result : int := 23;
|
2019-11-18 16:10:48 +01:00
|
|
|
case i = 2 of
|
2020-02-10 19:27:58 +01:00
|
|
|
True -> result := 42
|
2019-11-18 16:10:48 +01:00
|
|
|
| False -> result := 0
|
|
|
|
end
|
2020-02-10 19:27:58 +01:00
|
|
|
} with result
|
2019-05-12 20:56:22 +00:00
|
|
|
|
2020-02-10 19:27:58 +01:00
|
|
|
function match_option (const o : option (int)) : int is
|
|
|
|
block {
|
|
|
|
var result : int := 23;
|
2019-11-18 16:10:48 +01:00
|
|
|
case o of
|
2020-02-10 19:27:58 +01:00
|
|
|
None -> skip
|
2019-11-18 16:10:48 +01:00
|
|
|
| Some (s) -> result := s
|
|
|
|
end
|
2020-02-10 19:27:58 +01:00
|
|
|
} with result
|
2019-05-12 20:56:22 +00:00
|
|
|
|
|
|
|
function match_expr_bool (const i : int) : int is
|
|
|
|
case i = 2 of
|
2020-02-10 19:27:58 +01:00
|
|
|
True -> 42
|
2019-05-12 20:56:22 +00:00
|
|
|
| False -> 0
|
|
|
|
end
|
|
|
|
|
2020-02-10 19:27:58 +01:00
|
|
|
function match_expr_option (const o : option (int)) : int is
|
2019-05-12 20:56:22 +00:00
|
|
|
case o of
|
2020-02-10 19:27:58 +01:00
|
|
|
None -> 42
|
2019-06-13 16:57:40 +02:00
|
|
|
| Some (s) -> s
|
2019-05-12 20:56:22 +00:00
|
|
|
end
|
2019-09-21 11:30:41 +02:00
|
|
|
|
2020-02-10 19:27:58 +01:00
|
|
|
function match_expr_list (const l : list (int)) : int is
|
2019-09-21 11:30:41 +02:00
|
|
|
case l of
|
2020-02-10 19:27:58 +01:00
|
|
|
nil -> -1
|
2019-09-21 11:30:41 +02:00
|
|
|
| hd # tl -> hd
|
|
|
|
end
|