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