summaryrefslogtreecommitdiff
blob: ee86b809444e867e45ae915a0dbface77b1621da (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
---
title: Conditionals
---
This page presents the computation operators that allow a choice depending on
some condition. All possible returned values must be of the same type.

### IF-ELSE
{{< fatecode >}}(if_else [BOOL] [C0 = COMPUTATION] [C1 = COMPUTATION]){{< /fatecode >}}

Returns `C0` is `[BOOL]` yields true, `C1` otherwise.

### COND
{{< fatecode >}}(cond
   ([B0 = BOOL] [C0 = COMPUTATION])
   ...
   ([BN = BOOL] [CN = COMPUTATION])
){{< /fatecode >}}

Returns `[CI]`, such that `[BI]` is the first to hold true. If there is not such
`Bi`, returns `[CN]`.

### SWITCH
{{< fatecode >}}(switch [T = COMPUTATION]
   ([V0 = COMPUTATION] [C0 = COMPUTATION])
   ...
   ([VN = BOOL] [CN = COMPUTATION])
   [D = COMPUTATION]
){{< /fatecode >}}a

Returns the first `CI` such that `VI` is equal to `T`. If there is not such
`VI`, returns `[D]`.

## Examples
{{< fatecode >}}(cond
   ((false) (false))
   ((false) (false))
   ((true)
      (cond
         ((false) (false))
         ((true) (not (is_member 3 test_list)))
         ((true) (false))
      )
   )
)
{{< /fatecode >}}

{{< fatecode >}}(switch 3
   (0 (false))
   (1 (false))
   (3 (true))
   (2 (false))
   (false)
)
{{< /fatecode >}}

{{< fatecode >}}(if_else (true)
   (if_else (false)
      (assert (false) FAILED: instruction ifelse E)
      (set test_var (true))
   )
   (assert (false) FAILED: instruction ifelse F)
)
{{< /fatecode >}}