Reputation: 1091
I'm trying a recursive program in ACSLogo (a mac version of Logo) and want to return a list of 2 integers (basically and X coordinate and a Y coordinate). I cannot figure out how to get it to return 2 values. It does one no problem.
Also, when you create a list and you wish to refer back to it to extract a value in a particular index, it seems like you have to paste the list as is and you cannot refer to it by an assigned name.
Example:
Item 4 [1 1 2 3 5 8 13 21]
You cannot name that list "fibb" and refer to it like this X + fibb item 4
Upvotes: 4
Views: 462
Reputation: 43743
You can assign a list to a variable name like this:
Make "locations [1 1 2 3 5 8 13 21]
You can then access one of the items in the list like this:
Item 1 :locations
For instance, to set a variable named x
equal to the second item, you could do this:
Make "x (Item 2 :locations)
Next, to make a new list from two different values, you can use the List
command, for instance:
Make "location (List 1 2)
Or, from variables:
Make "location (List :x :y)
So, to get an x
and y
coordinate out of a list of locations and then create a new location
variable containing both the x
and y
values, you could do this:
Make "locations [1 1 2 3 5 8 13 21]
Make "x (Item 1 :locations)
Make "y (Item 2 :locations)
Make "location (List :x :y)
Or, more simply:
Make "locations [1 1 2 3 5 8 13 21]
Make "location (List (Item 1 :locations) (Item 2 :locations))
Upvotes: 3