-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdocumentation.conf
More file actions
86 lines (67 loc) · 2.83 KB
/
documentation.conf
File metadata and controls
86 lines (67 loc) · 2.83 KB
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
extensionName = "cf"
markdownTemplate = """
# NetLogo ControlFlow extension
This NetLogo extension adds somewhat experimental control-flow primitives. Currently, this extension contains a preview of the future version of the NetLogo primitives `ifelse` and `ifelse-value` that allow more than two branches.
{{> BUILDING.md}}
## Primitives
{{#primitives}}
{{> primTemplate}}
{{/primitives}}
"""
primTemplate = """
### `{{name}}`
```NetLogo
{{#examples}}
{{primitive.fullName}}{{#args}} {{name}}{{/args}}
{{/examples}}
```
{{{description}}}
"""
filesToIncludeInManual = [ "primitives" ]
primitives = [
{
name: ifelse,
type: command,
arguments: [ { name: condition, type: boolean }, { name: consequent, type: command }, { name: conditions/consequents, type: boolean/command }, { name: optional-else, type: command } ],
description: """
Runs the first command block following a true condition:
```NetLogo
let x 3
(cf:ifelse
x < 2 [ print "x is less than 2!" ]
x < 4 [ print "x is less than 4!" ]
x < 6 [ print "x is less than 6!" ]
[ print "x is greater than or equal to 6!" ])
```
The above code will print out `x is less than 4!` since that's the first case with a true condition.
A final command block without a matching condition may be provided, in which case it will run if no other command blocks do. If no such command block is provided and no conditions are true, nothing will happen.
The default number of arguments is 3, so that if you only have one condition, a consequent, and an else block (like a regular NetLogo `ifelse`), you do not need parentheses:
```NetLogo
cf:ifelse 0 < 1 [ print "hi" ] [ print "bye" ]
```
"""
},
{
name: ifelse-value,
type: reporter,
returns: anything,
arguments: [ { name: condition, type: boolean }, { name: consequent, type: reporter }, { name: conditions/consequents, type: boolean/reporter }, { name: else-reporter, type: reporter } ],
description: """
Runs the first reporter following a true condition and reports its value:
```NetLogo
(cf:ifelse-value
x < 2 [ "x is less than 2!" ]
x < 4 [ "x is less than 4!" ]
x < 6 [ "x is less than 6!" ]
[ "x is greater than or equal to 6!" ])
```
The above code will report `x is less than 4!` since that's the first case with a true condition.
Unlike `cf:ifelse`, the else-block is required in `cf:ifelse-value`. If no condition is true, the result of the else block will be reported.
Note that `cf:ifelse-value` has somewhat different associativity than NetLogo's `ifelse`, making it so that you don't need to put parentheses around the conditions, as in the above example.
The default number of arguments is 3, so that if you only have one condition, a consequent, and an else block (like a regular NetLogo `ifelse-value`), you do not need parentheses:
```NetLogo
cf:ifelse-value 0 < 1 [ "hi" ] [ "bye" ]
```
"""
}
]