on 492ae2f help sign in
59 lines 1.5 kB history raw
1# `:defl`, `?+`, "wutlus" `{$deft p/wing q/twig r/(list (pair twig twig))}`
3Switch with default value.
5Identical to `?-` except for that it takes a default case `q` if none of the
6cases in `r` match the type of `p`. More specifically, the labels in `q` must
7match the span of `p`. As with `?-`, the most common type used to switch on is the cube, which begins with `%` followed by text.
9Examples:
11 ?- p
12 p.i.r q.i.r
13 p.i.t.r q.i.t.r
14 p.i.t.t.r q.i.t.t.r
15 * q
16 ==
17 ~zod/try=>
18 =cor |= typ/@ta
19 ?+ typ 0
20 %a 1
21 %b 2
22 ==
23 new var %cor
24 ~zod/try=>
25 (cor 'a')
26 1
27 ~zod/try=>
28 (cor 'c')
29 0
31Here is a simple example of `?+` showing that although the cases must
32match the span of its input, all possible cases don't need to be covered
33since `?+` has a default case. We create a core, `cor` that takes an
34input `typ`, a `@ta`. Calling `cor` selects one of our cases when it is
35covered, or the default.
37 ~zod/try=>
38 ?+ 'a' 0
39 %a 1
40 ==
41 1
42 ~zod/try=>
43 ?+ [0 'a'] 0
44 %a 1
45 ==
46 ! poke-mack-fail
47 ! /~zod/try/~2014.11.2..16.45.31..7b2a:<[1 1].[3 7]>
48 ! mint-vain
49 ! ford: call ~hidper-sommur
50 ! poking %poke-txt
51 ! error in app %shell on ~zod at instance /shell/terminal
52 ~zod/try=>
53 ?+ [0 1] 0
54 [0 %a] 1
55 ==
56 0
58This example shows how `?+` can fail. Our input span must match the span
59of our cases.