Reputation: 379
When I try the following command on NL 6.1.1:
(map + [1 2 3] [2 4 6] [7 8 9])
I get [3 6 9]
as a result instead of [10 14 18]
, which means that only the first two lists are considered in the sum.
Anyone knows how to correct this and get all three lists to be considered ?
Upvotes: 1
Views: 199
Reputation: 2780
Per the documentation in the NetLogo dictionary, the map
reporter does support multiple lists, but map
expects the provided anonymous reporter to take a number of arguments equal to the number of lists you provide. In your case you cannot use the +
shortcut since +
takes 2 arguments, and we have 3 lists.
So instead you can do this:
(map [ [a b c] -> a + b + c ] [1 2 3] [2 4 6] [7 8 9])
If you need to handle adding an arbitrary number of lists (as in a list variable that could have 2, 3, 4, or more lists inside of it depending on your program), you can try this out using the reduce
reporter:
set vals [[1 2 3] [2 4 6] [7 8 9] [10 11 12]]
reduce [ [a b] -> (map + a b) ] vals
Upvotes: 4