Netlogo Lists
Netlogo Lists
Or
List Syntax
BAD
[]
[ 1, 2, 3, 4 ]
[123]
546
[ Hello!
I am James!
]
{ A B C }
Creating Lists
Three
Assign
Assign
a list of constants
Assign
[ ] to a variable makes it
an empty list.
; erase turtles memory
set memory [ ]
; memory is now an empty list
(likewise, creates an empty string)
of Lists of constants
successes [ [ 7 B] [ 8 7 Z ] [ 3 ] ]
set matrix [ [ 1 0 0 ]
[010]
[001]
]
List Constructors
There
Some
Some
but-first
but-last
filter
fput
list
lput
map
modes
n-values
remove
remove-duplicates
remove-item
replace-item
reverse
sentence
shuffle
sort, sort-by
values-from
however
bob
[ b o b ]
O> [ -2 5 ]
List Code-Fu
O> [ ]
Values-From
fput lput
lput {value} {list} ; (last)
fput {value} {list} ; (first)
use to build up lists one item at a time
reports a list that is the given list with the
value appended, becoming the new last
or first item.
but-first but-last
but-first {list}
but-last {list}
REMEMBER!
List-making primitives are reporters!
Primitives that modify a list dont
actually change the input list, but report a
result based on the list.
So, to modify a list, the result must be
assigned back to the input list.
Reverse
Sort
Shuffle
LISTS Code-Fu
set modified-list
map [ ? * 2 ] original-list
set income
set outgo
Filter
Reduce
Foreach
LIST Ideas
Turtle or Patch
Memory
Choices made
Patches visited
State history
Group members
Arrays of properties
DNA, Genes
Preset information
Plot data
Lines read from files
Undo history
Route history
Queues
Stacks
Matrices
You Name It!