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
|
---
title: Collections
---
Fate supports two types of collections: `[LIST]`, which are basic, unordered
lists; and `[SET]`, which are ordered lists, but only useable with
`[COMPARABLE]` elements.
### ADDING A MEMBER
{{< fatecode >}}(add_element! [COMPUTATION*] [COLLECTION VAR]){{< /fatecode >}}
Adds `[COMPUTATION*]` to `[COLLECTION VAR]`. If `[COLLECTION VAR]` is a
`[LIST]`, the new member is added at the end of the list. Note that
`[COMPUTATION*]` does not support use of the variable shorthand.
### ADDING A MEMBER AT INDEX
{{< fatecode >}}(add_element_at! [INT] [COMPUTATION*] [LIST VAR]){{< /fatecode >}}
Adds `[COMPUTATION*]` to `[LIST VAR]` at index `[INT]`. If `[INT]` is less than
0, the element is added at the start of the list, and if `[INT]` is greater or
equal to the size of the list, the element is added at the end of the list. Note
that `[COMPUTATION*]` does not support use of the variable shorthand.
### ADDING MEMBERS
{{< fatecode >}}(add_all_elements! [COLLECTION] [COLLECTION VAR]){{< /fatecode >}}
Adds all the elements of `[COLLECTION]` to `[COLLECTION VAR]`. If
`[COLLECTION VAR]` is a `[LIST]`, the new members are added at the end of the
list.
### EMPTYING COLLECTIONS
{{< fatecode >}}(clear [COLLECTION]){{< /fatecode >}}
Removes all members of `[COLLECTION]`.
### REMOVING MEMBER
{{< fatecode >}}(remove [COMPUTATION] [COLLECTION]){{< /fatecode >}}
Removes the first member of `[COLLECTION]` equal to `[COMPUTATION]`.
### REMOVING MEMBERS
{{< fatecode >}}(remove_all [COMPUTATION] [COLLECTION]){{< /fatecode >}}
Removes all instances of `[COMPUTATION]` from `[COLLECTION]`.
### REMOVING AT INDEX
{{< fatecode >}}(remove_at [INT] [COLLECTION]){{< /fatecode >}}
Removes the element of `[COLLECTION]` at `[INT]`.
### REVERSING LISTS
{{< fatecode >}}(reverse [LIST]){{< /fatecode >}}
Reverses the order of the members of `[LIST]`.
### FILTER ELEMENTS
{{< fatecode >}}(filter! <LAMBDA BOOL (X)> [X COLLECTION VAR]){{< /fatecode >}}
{{< fatecode >}}(filter! <LAMBDA BOOL (X Y0 ... YN)> [X COLLECTION VAR] [Y0 COMPUTATION*] ... [YN COMPUTATION*]){{< /fatecode >}}
Modifies `[X COLLECTION VAR]` so that only the elements for which
`<LAMBDA BOOL (X)>` returns `true` remain. If the lambda function needs extra
parameters, use the second syntax, which adds those parameters at the end of the
`(filter! ...)` call. Note that the variable shorthand cannot be used for these
extra parameters.
### FILTER ELEMENTS (INDEXED)
{{< fatecode >}}(indexed_filter! <LAMBDA BOOL (INT X)> [X COLLECTION VAR]){{< /fatecode >}}
{{< fatecode >}}(indexed_filter! <LAMBDA BOOL (INT X Y0 ... YN)> [X COLLECTION VAR] [Y0 COMPUTATION*] ... [YN COMPUTATION*]){{< /fatecode >}}
Modifies `[X COLLECTION VAR]` so that only the elements for which
`<LAMBDA BOOL (INT X)>` (with the `INT` being the element's index) returns
`true` remain. If the lambda function needs extra parameters, use the second
syntax, which adds those parameters at the end of the `(indexed_filter! ...)`
call. Note that the variable shorthand cannot be used for these extra
parameters.
|