My situation: I have two lists in NetLogo which are thought to correspond with each other, e.g. being two rows of of a matrix.
For example
set list-1 [1 2 2]
set list-2 [13 7 8]
where 1 is thought to be paired with 13, 2 with 7, and 2 with 8. These pairings may not be broken.
My problem:
I want to filter list-2 by applying a criterion on the corresponding elements of list-1. E.g. preserve an item of list-2 if the corresponding item equals 2
The result should be:
list-2: [7 8]
where the 13 is removed because the corresponding 1 does not equal 2.
How to program that in NetLogo?
My NetLogo version: 5.3.1
I can think of many different ways to do this:
That last one is by far my favorite, as I think it expresses the intent better than the others, but that might be subjective.
To make things reusable, you can isolate your preferred method in a reporter:
And then you can call it like this:
Converting all of this to NetLogo 6 syntax is left as an exercise to the reader. :-)