Command List
Here are a list of commands that affect lists. Note that these commands are only for lists of data. Lists of data are linked data lists, similar to lists in other versions of Logo. Unlike other Logos, however, StarLogo does not enable you to execute lists of data as instructions (that is, there is no run command). You can create a list of data using the list or sentence commands, or by enclosing the literal elements in []
's. No elements inside the []
's are evaluated.
ask-list-of-turtles
[list of turtle who numbers] [list of commands]
Parameters:
[list of turtle who numbers] |
List |
A list of turtle who numbers to ask |
[list of commands] |
List of turtle commands |
A list of commands to ask these turtles to run |
Description:
Turtles whose who numbers (ID numbers) are in
[list of turtle who numbers] run
[list of commands]. The caller of this command waits for it to finish before continuing. If some invalid whonumbers make up
[list of turtle who numbers], they are ignored.
Asking a list of turtles to do something is a moderately expensive operation since StarLogo creates a thread for each turtle. Try to group commands that you would have put into separate ask-list-of-turtles
into the same one to minimize thread creation overhead.
Examples:
ask-list-of-turtles [4 6 10 14] [fd 1]
makes 4 turtles (those with who numbers 4, 6, 10, and 14) move forward one step.
Related Commands:
ask-breed
ask-patch-at
ask-patches
ask-turtle
ask-turtles
ask-turtles-with
average-of-list
[list of values]
Parameters:
[list of values] |
List |
List of values to average |
Description:
Returns the numerical average of values in the given list.
Examples:
average-of-list [1 2 3 4 5]
returns 3
Notes:
If [list of values] contains no numbers, an error occurs. If some of the [list of values] are not numbers, those values are ignored.
Related Commands:
max-of-list
median-of-list
min-of-list
mode-of-list
sdev-of-list
sum-of-list
variance-of-list
butfirst (bf)
value
Parameters:
value |
List or string |
A list of data or a string |
Description:
When passed a list,
butfirst
returns a new list
[list of data]
with the first item removed. The input list is not changed.
When passed a string, butfirst
returns a new string with the first character removed. The input string is not changed.
Examples:
butfirst [4 5 6 7]
returns [5 6 7]
.
Related Commands:
butlast
first
last
lput
sentence
butlast (bl)
value
Parameters:
value |
List or string |
The list of data or string to operate on |
Description:
When given a list of data, returns the new value of value with the last item removed. The input list is not changed.
When given a string, returns a new string with the last character removed. The input string is not changed.
Examples:
butlast [4 5 6 7]
returns [4 5 6]
.
Related Commands:
butfirst
first
last
lput
sentence
copy-list
[list]
Parameters:
[list] |
List |
original list to be copied |
Description:
Returns a copy of [list] such that if you edit the copy, you will not edit the original.
Examples:
copy-list [1 2 3]
returns the list [1 2 3].
Related Commands:
list
make-list
sentence
dolist
[:loop-variable list] [commands to run]
Parameters:
[:loop-variable list] |
List of commands |
On each iteration, :loop-variable is assigned to each element of the list |
[commands to run] |
List of commands |
Commands to run once for each element of the list |
Description:
This command loops over each element of the list, and runs [commands to run] for each one. During each run of [commands to run], the element of the list is bound to loop-variable
.
Examples:
dolist [:i [2 4 -1]] [fd :i]
loops over the list [1 2 3]
. There are three iterations of this loop; in the first, we run fd 2
, in the second fd 4
and the third fd -1
.
Related Commands:
dotimes
empty?
data
Parameters:
data |
List or string |
list or string to test for emptiness |
Description:
If
data is a list of data, reports true if
data is empty.
If data is a string, reports true if data has no characters (i.e. = "").
Examples:
empty? [0 0]
returns false.
empty? [] returns true.
empty? "hello" returns false.
Related Commands:
first
last
make-list
sentence
first
[list of data] or string
Parameters:
[list of data] or string |
List or string |
List or string to return the first character/element from |
Description:
Returns the first element of a [list of data] or the first character of a string.
Examples:
first [3 4 5 6]
returns 3.
first "hello" returns "h".
Related Commands:
butfirst
butlast
empty?
fput
last
lput
fput
item
Parameters:
Description:
Adds the item into the list as the first element
Examples:
fput 1 [2 3 4]
returns [1 2 3 4].
fput "hello" "mom"
returns "hellomom".
Related Commands:
first
insert
last
lput
reverse
sentence
item
number [list]
Parameters:
number |
Number |
|
[list] |
List |
|
Description:
Returns the element of [list] at the number'th position.
Examples:
item 2 [4 6 8]
returns 6.
Notes:
Indexing starts from 1.
Related Commands:
position
remove
remove-element
setitem
last
[list of data]
Parameters:
[list of data] |
List or string |
list of data of which you want the last element |
Description:
Returns the last item of [list of data].
Examples:
last [4 5 6 7]
returns 7.
Related Commands:
butfirst
butlast
empty?
first
fput
lput
length
[list of data]
Parameters:
[list of data] |
List or string |
list of data for which you want the length |
Description:
Returns the length of [list of data].
Examples:
length []
returns 0.
length [4 5 6 7]
returns 4.
Related Commands:
list
make-list
sentence
list
item 1 item 2
Parameters:
item 1 |
Anything |
the first item in your list |
item 2 |
Number |
the second item in your list |
Description:
Returns a new [list of data]
with item 1 as its first element, and item 2 as its second.
Examples:
list 4 5
returns [4 5]
.
Related Commands:
copy-list
length
make-list
pick
position
remove
remove-element
reverse
sentence
sublist
to-list
list-of-breed
Description:
Returns a list of the who numbers of the turtles of the breed specified by
breed
.
Examples:
list-of-frogs
returns a list of all of the turtles of breed frogs
list-of-cars
returns a list of all of the turtles of breed cars
Related Commands:
list-of-breed-at
list-of-breed-here
list-of-breed-towards
list-of-breed-with
list-of-turtles
list-of-breed-at
xcor ycor
Parameters:
xcor |
Number |
number of units away in the x direction |
ycor |
Number |
number of units away in the y direction |
Description:
Returns a list of the who numbers of the turtles of the breed specified by breed
xcor units in the x direction and ycor units in the y direction away from the caller.
Examples:
list-of-frogs-at 1 1
returns a list of the who numbers of the turtles of breed frogs one unit to the right and one unit above the caller.
list-of-cars-at 3 5
returns a list of the who numbers of the turtles of breed cars three units to the right and five units above the caller.
Related Commands:
list-of-breed
list-of-turtles-at
list-of-turtles-at-with
list-of-breed-here
Description:
Returns a list of turtles of the breed specified by breed
on the caller's patch.
Examples:
list-of-frogs-here
returns a list of turtles of breed frogs
on the caller's patch.
list-of-cars-here
returns a list of turtles of breed cars
on the caller's patch.
Related Commands:
list-of-breed
list-of-breed-here-with
list-of-turtles-here
list-of-breed-towards
angle distance
Parameters:
angle |
Number |
angle from the caller |
distance |
Number |
distance away from the caller |
Description:
Returns a list of the who numbers of the turtles of the breed specifed by breed
at the patch angle away at angle distance from the caller.
Examples:
list-of-frogs-towards 0 1
returns a list of the turtles of breed frog directly ahead and one patch away from the caller.
list-of-cars-towards 90 5
returns a list of the turtles of breed cars 90 degreses to the right and five patches away from the caller.
Related Commands:
list-of-breed
list-of-breed-towards-with
list-of-turtles-towards
list-of-breed-with
[condition]
Parameters:
[condition] |
List of turtle commands |
list of commands that evaluates to true or false |
Description:
Returns a list of turtles of breed indicated by breed
satisfying condition
.
Examples:
list-of-frogs-with [color = green]
will return a list of turtles that are breed frogs
and have color green
.
list-of-cars-with [color = black]
will return a list of turtles that are breed cars
and have color black
.
Notes:
Note [condition] must be a boolean statement and return true or false.
Related Commands:
list-of-breed
list-of-turtles-with
list-of-turtles
Description:
Returns a list of the who numbers of all the turtles.
Related Commands:
list-of-breed
list-of-turtles-with
one-of-breed
one-of-turtles
list-of-turtles-at
xcor ycor
Parameters:
xcor |
Number |
number of units away in the x direction |
ycor |
Number |
number of units away in the y direction |
Description:
Returns a list of turtles xcor units in the x direction and ycor units in the y direction away from the caller .
Examples:
list-of-turtles-at 1 1
returns a list of turtles one unit to the right and one unit above the caller.
Related Commands:
list-of-breed-at
list-of-turtles-at-with
list-of-turtles-here
list-of-turtles-towards
list-of-turtles-here
Description:
Returns a list of turtles on the caller's patch.
Related Commands:
list-of-breed-here
list-of-turtles-at
list-of-turtles-towards
list-of-turtles-with
one-of-breed-here
list-of-turtles-towards
angle distance
Parameters:
angle |
Number |
angle from the caller |
distance |
Number |
distance away from the caller |
Description:
Returns a list of turtles at the patch angle away at angle distance from the caller.
Examples:
list-of-turtles-towards 0 1
returns a list of turtles one unit directly in front of the caller.
Related Commands:
list-of-breed-towards
list-of-turtles-at
list-of-turtles-here
list-of-turtles-towards-with
list-of-turtles-with
[condition]
Parameters:
[condition] |
List of commands |
list of commands that evaluates to true or false |
Description:
Returns a list of the who numbers of the turtles satisfying condition
.
Examples:
list-of-turtles-with [color = red]
returns a list of the who numbers of the red turtles.
Related Commands:
list-of-breed-with
list-of-turtles
list-of-turtles-here
myself
one-of-turtles-with
list?
thing
Parameters:
thing |
Number |
the item, string, list, or variable that you are trying to determine if it is a list |
Description:
Returns true if thing is a list.
Examples:
list? 4
returns false.
list? [4]
returns true.
Related Commands:
number?
word?
lput
item [list of data]
Parameters:
item |
Integer |
the item that you are placing in the list |
[list of data] |
List or string |
list of data that you are adding to |
Description:
Returns the new value of [list of data] with item as its last element. The input list is not changed.
Examples:
lput 4 [1 2 3]
returns [1 2 3 4]
.
Related Commands:
butfirst
butlast
first
fput
insert
last
reverse
sentence
make-list
integer element
Parameters:
integer |
Integer |
number of times the item will be in the list |
element |
Anything |
the data that will be repeated in the list |
Description:
Returns a list of length integer filled with element.
Examples:
make-list 5 0
returns [0 0 0 0 0]
Related Commands:
copy-list
empty?
length
list
sentence
to-list
max-of-list
list
Parameters:
list |
List |
list of which you want the maximum value |
Description:
Returns the greatest value in the given list.
Examples:
max-of-list [5 7 1]
returns 7
.
Related Commands:
average-of-list
median-of-list
min-of-list
mode-of-list
sdev-of-list
sort-num-list
sum-of-list
variance-of-list
median-of-list
list
Parameters:
list |
List |
list of numbers for which you want the median value |
Description:
Returns the median of the given list.
Examples:
median-of-list [ 1 3 5 7 9]
returns 5
.
Notes:
If an element in list is not a number, an error occurs.
If list contains no numbers, an error occurs. If some of the list, when evaluated, are not numbers, those values are ignored.
Related Commands:
average-of-list
max-of-list
min-of-list
mode-of-list
sdev-of-list
sum-of-list
variance-of-list
member?
item [list of data]
Parameters:
item |
Anything |
item which you are looking for |
[list of data] |
List or string |
list of data to search |
Description:
Returns true if item is a member of [list of data].
Examples:
member? 4 [1 0 9]
returns false
.
member? 4 [1 4 9]
returns true
.
Related Commands:
insert
position
remove
remove-element
setitem
min-of-list
list
Parameters:
list |
List |
list of numbers |
Description:
Returns the least value in the given list.
Examples:
min-of-list [1 2 3]
returns 1
Notes:
Note: If list contains no numbers, the greatest possibel number is returned. If some of the list, when evaluated, are not numbers, those values are ignored.
Related Commands:
average-of-list
max-of-list
median-of-list
mode-of-list
sdev-of-list
sort-num-list
sum-of-list
variance-of-list
mode-of-list
list
Parameters:
Description:
Returns the mode of the given list.
Examples:
mode-of-list [1 1 2 2 2]
returns 2.
Notes:
Note: If list contains no numbers, an error occurs. If some of the list, when evaluated, are not numbers, those values are ignored.
Related Commands:
average-of-list
max-of-list
median-of-list
min-of-list
mode-of-list
sdev-of-list
sort-num-list
sum-of-list
variance-of-list
pick
[list of data]
Parameters:
[list of data] |
List or string |
|
Description:
Returns a random element of the [list of data]. Returns false if the list is empty.
Examples:
pick [1 2]
would return 1 half of the time and would return 2 half of the time.
Related Commands:
list
random
sentence
to-list
position
item [list of data]
Parameters:
item |
Integer |
|
[list of data] |
List or string |
|
Description:
Returns the position of item in the [list of data]
Examples:
position 1 [6 7 1]
returns 3
Related Commands:
item
list
member?
remove
remove-element
sentence
setitem
remove
index [list]
Parameters:
index |
Number |
position in list of element to remove |
[list] |
List |
list with element to remove |
Description:
Reports the new list with the element in the index position removed from the specified list. The input list is not changed.
Examples:
remove 5 [2 4 6 8 10 12]
reports [2 4 6 8 12].
Related Commands:
insert
item
list
member?
position
remove-element
sentence
setitem
remove-element
element [list]
Parameters:
element |
Anything |
element to be removed |
[list] |
List |
list with element to be removed |
Description:
Reports the new list when all instances of the specified element are removed from list. The input list is not changed.
Examples:
remove-element [1 2] [3 [4 5] [1 2] 6 [1 2]]
returns [3 [4 5] 6]
Notes:
"=" is used as the comparison operator.
Related Commands:
item
list
member?
position
remove
sentence
setitem
reverse
[list]
Parameters:
[list] |
List |
list to be reversed |
Description:
Reports the new list with the order of the elements in [list] reversed. The input [list] is not changed.
Examples:
reverse [1 2 3]
reports the list [3 2 1].
Related Commands:
fput
list
lput
sentence
sdev-of-list
list
Parameters:
Description:
Reports the standard deviation of the given list.
Examples:
sdev-of-list [2 2 2]
returns 0.
Notes:
If list contains no numbers, an error occurs. If some elements of the list, when evaluated, are not numbers, those elements are ignored.
Related Commands:
average-of-list
max-of-list
median-of-list
min-of-list
min-of-patches
mode-of-list
mode-of-patches
sort-num-list
sum-of-list
variance-of-list
sentence (se)
anything1 anything2
Parameters:
anything1 |
Anything |
|
anything2 |
Anything |
|
Description:
Returns a list. If anything1 and anything2 are lists, it concatenates the two lists (combines their items into one list). If anything1 is a list and anything2 is not, it puts anything2 at the end of the first list. If anything1 is not a list and anything2 is a list, it puts anything1 at the front of the second list. If both anything1 and arg2 are not lists, it creates a new list containing both anything1 and anything2.
Examples:
se 1 2
returns
[1 2]
se [1] 2
returns [1 2]
se 1 [2]
returns [1 2]
se [1] [2]
returns [1 2]
Related Commands:
butfirst
butlast
copy-list
empty?
fput
length
list
lput
make-list
pick
position
remove
remove-element
reverse
sublist
to-list
setitem
setitem list newvalue
Parameters:
setitem |
Integer |
position in the list |
list |
List |
list of items |
newvalue |
Anything |
item to be inserted into the list |
Description:
Sets the item at position setitem in list list to newvalue.
Examples:
setitem 2 [1 3 3 4] 5
changes the list to [1 5 3 4]
.
Related Commands:
item
member?
position
remove
remove-element
sort-num-list
list-of-data
Parameters:
list-of-data |
List or string |
|
Description:
Returns the list list-of-data sorted in increasing order. All elements of the list must be numbers.
Examples:
sort-num-list [3 1 2]
returns [1 2 3]
Related Commands:
max-of-list
min-of-list
mode-of-list
sdev-of-list
sort-num-list
sum-of-list
variance-of-list
sublist
list begin end
Parameters:
list |
List |
List that you want to subset |
begin |
Integer |
The beginning index that you want to keep |
end |
Integer |
The ending index that you want to keep |
Description:
Return a new list that is a subset of the original list. The new list will be end - begin + 1 elements long, and will contain the elements of list from and including begin up to end.
Examples:
sublist [1 2 3 4 5] 2 4
returns [2 3 4]
.
sublist [1 2 3 4 5] 0 0
returns [1]
.
sublist [1 2 3 4 5] 4 5
returns [4 5]
.
Related Commands:
list
sentence
to-list
sum-of-list
list
Parameters:
list |
List |
List of numbers |
Description:
Returns the sum of the numbers in the list.
Examples:
sum-of-list [1 2 -3 4.5 5]
returns 9.5
.
Notes:
Note: If list contains no numbers, an error occurs. If some of the list, when evaluated, are not numbers, those values are ignored.
Related Commands:
average-of-list
max-of-list
median-of-list
min-of-list
mode-of-list
sdev-of-list
sort-num-list
variance-of-list
to-list
[list of commands]
Parameters:
[list of commands] |
List of commands |
Commands to execute whose return values will form the list |
Description:
Runs then commands in [list of commands] and makes a new list from each command's return value.
Examples:
globals [foo]
set foo 45
to-list [1 2 + 4 foo]
returns the list [1 6 45]
.
Related Commands:
list
make-list
pick
sentence
sublist
to-delimited-string
to-string
variance-of-list
[list of values]
Parameters:
[list of values] |
Number |
List of values to average |
Description:
Returns the numerical variance of values in the given list.
Examples:
variance-of-list [1 3 5]
returns 2.666
.
Notes:
If [list of values] contains no numbers, an error occurs. If some of the [list of values] are not numbers, those values are ignored.
Related Commands:
average-of-list
max-of-list
median-of-list
min-of-list
mode-of-list
sdev-of-list
sort-num-list
sum-of-list