Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
195 changes: 195 additions & 0 deletions documentation.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,195 @@
additionalVariables:
netlogoUrl: http://ccl.northwestern.edu/netlogo/docs/
extensionName: table
icon: i-lucide-table-properties
filesToIncludeInManual:
- USING.md
- primitives
markdownTemplate: |2

# NetLogo Table Extension

{{> BUILDING.md}}

{{> USING.md}}

## Primitives

{{#contents}}{{#prims}}
[`{{name}}`](#{{primitive.extensionName}}{{primitive.name}})
{{/prims}}{{/contents}}

{{#primitives}}
{{> primTemplate}}
{{/primitives}}

{{> LICENSE.md}}
primTemplate: |2

### `{{name}}`

```NetLogo
{{#examples}}
{{primitive.fullName}}{{#args}} {{name}}{{/args}}
{{/examples}}
```

{{{description}}}
primitives:
- arguments:
- type: table
description: Removes all key-value pairs from *table*.
name: clear
type: command
- arguments:
- type: list
description: Counts the occurrences of each element of the given list and reports the counts in a table.
name: counts
returns: table
type: reporter
- arguments:
- type: agentset
- type: reporter
description: |2

Groups the agents in the agentset based on the given reporter.
Agents that report the same thing for reporter will be grouped together.
The results of the reporter will be used as the keys in the resulting table and the groups will be agentsets.

For example:

{{! prevent mustache from interpreting extension object as template variable }}{{= | | =}}
```
observer> create-turtles 100 [ set color one-of [ red green blue ] ]
observer> show table:group-agents turtles [ color ]
observer: {{table: [[105 (agentset, 38 turtles)] [55 (agentset, 32 turtles)] [15 (agentset, 30 turtles)]]}}
```
name: group-agents
returns: table
type: reporter
- arguments:
- type: list
- type: anonymous-reporter
description: |2

Groups the items of the list based on the given reporter.
The reporter should take a single argument, which will be the items of the list.
Items that report the same thing when passed to the reporter will be grouped together.
The results of the reporter will be used as the keys in the resulting table and the groups will be lists.

For example:

{{! prevent mustache from interpreting extension object as template variable }}{{= | | =}}
```
observer> show table:group-items range 10 [ num -> num mod 3 ]
observer: {{table: [[0 [0 3 6 9]] [1 [1 4 7]] [2 [2 5 8]]]}}
```
name: group-items
returns: table
type: reporter
- arguments:
- type: list
description: |2

Reports a new table with the contents of *list*.
*list* must be a list of two element lists, or pairs.
The first element in the pair is the key and the second element is the value.
name: from-list
returns: table
type: reporter
- arguments:
- type: string
description: "\n Reads in the JSON object from the given string argument, converts it to a table, and reports the table.\n The JSON object in the argument must be an object, not an array (i.e. the outmost characters must be `{` and `}`, not `[` and `]`),\n but there can be arrays inside the JSON object which will be converted to NetLogo lists.\n "
name: from-json
returns: table
type: reporter
- arguments:
- type: filename
description: "\n Reads in the JSON object from *filename.json*, converts it to a table and reports the table.\n The JSON object in *filename.json* must be an object, not an array (i.e. the outmost characters of the file must be `{` and `}`, not `[` and `]`),\n but there can be arrays inside the JSON object which will be converted to NetLogo lists.\n "
name: from-json-file
returns: table
type: reporter
- arguments:
- type: table
- name: key
type: anything
description: Reports the value that *key* is mapped to in the table. Causes an error if there is no entry for the key.
name: get
returns: anything
type: reporter
- arguments:
- type: table
- name: key
type: anything
- name: default-value
type: anything
description: Reports the value that *key* is mapped to in the table. Reports the default-value if there is no entry for the key.
name: get-or-default
returns: anything
type: reporter
- arguments:
- type: table
- name: key
type: anything
description: Reports true if *key* has an entry in *table*.
name: has-key?
returns: boolean
type: reporter
- arguments:
- type: table
description: Reports a list of all the keys in *table*, in the same order the keys were inserted.
name: keys
returns: list
type: reporter
- arguments:
- type: table
description: Reports the number of entries in *table*.
name: length
returns: number
type: reporter
- description: Reports a new, empty table.
name: make
returns: table
type: reporter
- arguments:
- type: table
- name: key
type: anything
- name: value
type: anything
description: Maps *key* to *value* in *table*. If an entry already exists in the table for the given key, it is replaced.
name: put
type: command
- arguments:
- type: table
- name: key
type: anything
description: Removes the mapping in *table* for *key*.
name: remove
type: command
- arguments:
- type: table
description: |2-

Reports a list with the content of <i>table</i>. The list will be a
list of two element lists, or pairs. The first element in the pair is
the key and the second element is the value. The keys appear in the
same order they were inserted.
name: to-list
returns: list
type: reporter
- arguments:
- type: table
description: Reports a string with the contents of the given table as a JSON string.
name: to-json
returns: string
type: reporter
- arguments:
- type: table
description: |2-

Reports a list with the entries of <i>table</i>. The entries will appear
in the same order they were inserted, with duplicates included.
name: values
returns: list
type: reporter