7.1 Booleans
annotation | |
#true
#false
#true
expression | |
| |
repetition | |
The || form can also serve as repetitions.
binding operator | |
> fun check_shape(v):
match v
| [x] || [x, y, z]: #true
| ~else: #false
> check_shape([1])
#true
> check_shape([1, 2, 3])
#true
> check_shape([1, 2])
#false
annotation | |
The annotations are checked in other. Either or both of left_annot and right_annot can be a converter annotation, in which case the conversion result of the first satisfied annotation is used.
#true
#true
reducer | ||||||||
| ||||||||
expression | ||||||||
| ||||||||
| ||||||||
|
"5"
i == 10
#false
The any expression form is like ||, but any supports repetition arguments, and it stops iterating through a repetition as soon as a non-#false result is found. When the last expr_or_splice is an expr, it is in tail position.
3
expression | |
| |
repetition | |
The && form can also serve as repetitions.
binding operator | |
See where for a different kind of “and” binding that allows the right-hand side to refer to bindings from the left-hand side.
> class Posn(x, y)
> fun three_xs(v):
match v
| ~else: #false
> three_xs([Posn(1, 2), Posn(3, 4), Posn(5, 6)])
[1, 3, 5]
> three_xs([Posn(1, 2), Posn(3, 4)])
#false
> three_xs([Posn(1, 2), Posn(3, 4), "no"])
#false
annotation | |
When left_annot and right_annot are predicate annotations, the static information implied by the annotation is the union of information for left_annot and right_annot, where information from right_annot takes precedence in cases where both supply values for the same static-information key.
If left_annot or right_annot is a converter annotation, the left_annot conversion is applied first, and its result is the input to right_annot, and the result of right_annot is the result for the for the overall annotation created by &&. When the overall annotation is used only for matching, the conversion part of right_annot is skipped, but the conversion part of left_annot must be performed.
#false
> Pair(1, "hello") is_a (Pair.of(Int, Any) && Pair.of(Any, String))
#true
> 1 :: (converting(fun (n): n+1) && converting(fun (n): -n))
-2
reducer | |
| |
expression | |
|
i == 5
#false
"9"
The all expression form is like &&, but all supports repetition arguments, and it stops iterating through a repetition as soon as a #false result is found. When the last expr_or_splice is a expr, it is in tail position.
#false
> !#false
#true
> !#true
#false
> !"false"
#false
> fun
| is_two_list(![x, y]): #false
| is_two_list(_): #true
> is_two_list([1])
#false
> is_two_list([1, 2])
#true
> is_two_list([1, 2, 3])
#false
#false
#true