Skip to content

Commit 7b64e38

Browse files
Add extension documentation plugin, generate initial README
1 parent 3ef0020 commit 7b64e38

7 files changed

Lines changed: 224 additions & 7 deletions

File tree

BUILDING.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
## Building
2+
3+
Use the netlogo.jar.url environment variable to tell sbt which NetLogo.jar to compile against (defaults to NetLogo 5.3). For example:
4+
5+
sbt -Dnetlogo.jar.url=file:///path/to/NetLogo/target/NetLogo.jar package
6+
7+
If compilation succeeds, `array.jar` will be created.

LICENSE.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
## Terms of Use
2+
3+
[![CC0](http://i.creativecommons.org/p/zero/1.0/88x31.png)](http://creativecommons.org/publicdomain/zero/1.0/)
4+
5+
The NetLogo array extension is in the public domain. To the extent possible under law, Uri Wilensky has waived all copyright and related or neighboring rights.

README.md

Lines changed: 91 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
1-
# NetLogo array extension
21

3-
This package contains the NetLogo array extension.
4-
5-
## Using
6-
7-
This extension is pre-installed in NetLogo. For instructions on using it, or for more information about NetLogo extensions, see the NetLogo User Manual.
2+
# NetLogo Array Extension
83

94
## Building
105

@@ -14,6 +9,96 @@ Use the netlogo.jar.url environment variable to tell sbt which NetLogo.jar to co
149

1510
If compilation succeeds, `array.jar` will be created.
1611

12+
## Using
13+
14+
The array extension is pre-installed in NetLogo.
15+
16+
To use the array extension in your model, add a line to the top of your Code tab:
17+
18+
```
19+
extensions [array]
20+
```
21+
22+
If your model already uses other extensions, then it already has an
23+
`extensions` line in it, so just add `array` to the list.
24+
25+
For more information on using NetLogo extensions,
26+
see the [Extensions Guide](http://ccl.northwestern.edu/netlogo/docs/extensions.html)
27+
28+
### When to Use
29+
30+
In general, anything you can do with an array in NetLogo, you could
31+
also just use a list for. But you may want to consider using an array
32+
instead for speed reasons. Lists and arrays have different performance
33+
characteristics, so you may be able to make your model run faster by
34+
selecting the appropriate data structure.
35+
36+
Arrays are useful when you need a collection of values whose size is
37+
fixed. You can quickly access or alter any item in an array if you
38+
know its position.
39+
40+
Unlike NetLogo's lists and strings, arrays are "mutable".
41+
That means that you can actually modify them directly,
42+
rather than constructing an altered copy as with lists. If
43+
the array is used in more than one place in your code, any
44+
changes you make will show up everywhere. It's tricky to write
45+
code involving mutable structures and it's easy to make subtle
46+
errors or get surprising results, so we suggest sticking with lists
47+
and strings unless you're certain you want and need mutability.
48+
49+
### Example use of Array Extension
50+
51+
```NetLogo
52+
let a array:from-list n-values 5 [0]
53+
print a
54+
=> {{array: 0 0 0 0 0}}
55+
print array:length a
56+
=> 5
57+
foreach n-values 5 [ [i] -> i ] [ [i] -> array:set a i i * i ]
58+
print a
59+
=> {{array: 0 1 4 9 16}}
60+
print array:item a 0
61+
=> 0
62+
print array:item a 3
63+
=> 9
64+
array:set a 3 50
65+
print a
66+
=> {{array: 0 1 4 50 16}}
67+
```
68+
69+
## Primitives
70+
71+
72+
### `array:from-list`
73+
74+
Reports a new array containing the same items in the same order as the input list.
75+
76+
77+
### `array:item`
78+
79+
Reports the item in the given array with the given index (ranging from zero to the length of the array minus one).
80+
81+
82+
### `array:set`
83+
84+
85+
Sets the item in the given array with the given index (ranging from zero to the length of the array minus one) to the given value.
86+
87+
Note that unlike the `replace-item` primitive for lists, a new array is not created.
88+
The given array is actually modified.
89+
90+
91+
92+
### `array:length`
93+
94+
Reports the length of the given array, that is, the number of items in the array.
95+
96+
97+
### `array:to-list`
98+
99+
Reports a new list containing the same items in the same order as the given array.
100+
101+
17102
## Terms of Use
18103

19104
[![CC0](http://i.creativecommons.org/p/zero/1.0/88x31.png)](http://creativecommons.org/publicdomain/zero/1.0/)

USING.md

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
## Using
2+
3+
The array extension is pre-installed in NetLogo.
4+
5+
To use the array extension in your model, add a line to the top of your Code tab:
6+
7+
```
8+
extensions [array]
9+
```
10+
11+
If your model already uses other extensions, then it already has an
12+
`extensions` line in it, so just add `array` to the list.
13+
14+
For more information on using NetLogo extensions,
15+
see the [Extensions Guide](http://ccl.northwestern.edu/netlogo/docs/extensions.html)
16+
17+
### When to Use
18+
19+
In general, anything you can do with an array in NetLogo, you could
20+
also just use a list for. But you may want to consider using an array
21+
instead for speed reasons. Lists and arrays have different performance
22+
characteristics, so you may be able to make your model run faster by
23+
selecting the appropriate data structure.
24+
25+
Arrays are useful when you need a collection of values whose size is
26+
fixed. You can quickly access or alter any item in an array if you
27+
know its position.
28+
29+
Unlike NetLogo's lists and strings, arrays are "mutable".
30+
That means that you can actually modify them directly,
31+
rather than constructing an altered copy as with lists. If
32+
the array is used in more than one place in your code, any
33+
changes you make will show up everywhere. It's tricky to write
34+
code involving mutable structures and it's easy to make subtle
35+
errors or get surprising results, so we suggest sticking with lists
36+
and strings unless you're certain you want and need mutability.
37+
38+
### Example use of Array Extension
39+
40+
```NetLogo
41+
let a array:from-list n-values 5 [0]
42+
print a
43+
=> {{array: 0 0 0 0 0}}
44+
print array:length a
45+
=> 5
46+
foreach n-values 5 [ [i] -> i ] [ [i] -> array:set a i i * i ]
47+
print a
48+
=> {{array: 0 1 4 9 16}}
49+
print array:item a 0
50+
=> 0
51+
print array:item a 3
52+
=> 9
53+
array:set a 3 50
54+
print a
55+
=> {{array: 0 1 4 50 16}}
56+
```

build.sbt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
enablePlugins(org.nlogo.build.NetLogoExtension)
1+
enablePlugins(org.nlogo.build.NetLogoExtension, org.nlogo.build.ExtensionDocumentationPlugin)
22

33
javaSource in Compile <<= baseDirectory(_ / "src")
44

documentation.conf

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
extensionName = "array"
2+
markdownTemplate = """
3+
# NetLogo Array Extension
4+
5+
{{#include}}BUILDING.md{{/include}}
6+
7+
{{#include}}USING.md{{/include}}
8+
9+
## Primitives
10+
11+
{{#allPrimitives}}
12+
{{{.}}}
13+
{{/allPrimitives}}
14+
15+
{{#include}}LICENSE.md{{/include}}
16+
"""
17+
primTemplate = """
18+
### `{{name}}`
19+
20+
{{{description}}}
21+
"""
22+
filesToIncludeInManual = [ "BUILDING.md", "USING.md", "primitives" ]
23+
primitives = [
24+
{
25+
name: from-list,
26+
type: reporter,
27+
returns: array,
28+
arguments: [ { type: list } ],
29+
description: "Reports a new array containing the same items in the same order as the input list."
30+
},
31+
{
32+
name: item,
33+
type: reporter,
34+
returns: anything,
35+
arguments: [ { type: array }, { name: index, type: number } ],
36+
description: "Reports the item in the given array with the given index (ranging from zero to the length of the array minus one)."
37+
},
38+
{
39+
name: set,
40+
type: command,
41+
arguments: [ { type: array }, { name: index, type: number }, { name: value, type: anything } ],
42+
description: """
43+
Sets the item in the given array with the given index (ranging from zero to the length of the array minus one) to the given value.
44+
45+
Note that unlike the `replace-item` primitive for lists, a new array is not created.
46+
The given array is actually modified.
47+
"""
48+
},
49+
{
50+
name: length,
51+
type: reporter,
52+
returns: number,
53+
arguments: [ { type: array } ],
54+
description: "Reports the length of the given array, that is, the number of items in the array."
55+
},
56+
{
57+
name: to-list,
58+
type: reporter,
59+
returns: list,
60+
arguments: [ { type: array } ],
61+
description: "Reports a new list containing the same items in the same order as the given array."
62+
}
63+
]

project/plugins.sbt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ resolvers += Resolver.url(
44
Resolver.ivyStylePatterns)
55

66
addSbtPlugin("org.nlogo" % "netlogo-extension-plugin" % "3.0")
7+
addSbtPlugin("org.nlogo" % "netlogo-extension-documentation" % "0.5")

0 commit comments

Comments
 (0)