summaryrefslogtreecommitdiff
path: root/docs/tagging.md
blob: b7c0700839f9a69cfeda9e14409aa027f46ef4bc (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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# Tagging

---

## Operators

### Matching

```text
r : # x / y {
    .value {[value] value }
    .error {[error] `log error; 0 }
}
```

### Asserting

If no tag is specified for an operation, `.value` is used

An invalid assertion produces an `Error` with an `.error` tag

```text
r : x /.value y
r : x / y // same as above
```

## Lambdas

If no tag is specified `.value` is used, user defined coroutines don't have to have a `.value` tag

### Returning

```text
add : `{[I64 x; I64 y] `return.value x + y }
add : `{[I64 x; I64 y] .value x + y } // same as above
add : `{[I64 x; I64 y] x + y } // same as above
mu : `{[Bool i]
    ? i {
        .int 1
    } {
        .float 1.1
    }
}
```

### Matching

```text
// using the mu corotuine from above
i : # mu `sync `false {
    .int {[i] i }
    .float {[f] I64 f }
}
```

### Asserting

```text
// using the mu coroutine from aboce
i : mu `sync.int `true
```

## Generators

Generators use a `.done` tag to denote when it is complete

```text
gen : ^{[I64 n]
    @ 1 .. n {[x]
        `yield x
        // above is alias for -> `yield.value x
    }
    `done
}

it : gen `init 10
```

### Matching

```text
v : # `next it {
    .value {[x] x }
    .done { -1 }
}
```

### Asserting

```text
v : `next.value it
v : `next it // same as above
```

## Tables

### Creating

```text
table : Table (.a 1; .b 1.1)
```

### Accessing

```text
`log table.a
```

## Loops

### Break

```text
@.outer condtion {
    @ condition {
        `break.outer
    }
}
```

### Continue

```text
@ (x : 0; x < 10; x +: 2) {
    ? x < 5 { `continue }
    ...
}
```