Reputation: 806
I am trying to improve my understanding of lists in NetLogo. Shortly, I am adding and picking (and removing) items from lists. Each turtle has its own list. Each list should contain items in a chronological order, from the most recent to the oldest. Once a turtle chooses an item, the neighbours have this item on the top of their lists (same for the turtle that chooses the item). What I tried to do is:
rnd:weighted-one-of-list mylist [ [ii] -> ii ] ; pick one of the most recent items already in the list
set mylist lput old_item mylist print "Old item" ; add items to the list
using the extension as JenB suggested in a previous post.
Condition to use pick an item from a list (old item) is that mylist is not empty (if empty? mylist
).
My question is if it is correct to pick an item using the extension in that way as I did.
UPDATE: The list is made up in the following way:
I decide to create a new item, item 4
with quality 2
(quality is a parameter in [0,5]
).
I add this item in my list (item 4, item3, item2, item1)
- from the most recent to the oldest - with quality item4 2, item3 1, item2 2, item1 5
, respectively, and in neighbours' lists: neighbour1
, for example, would have list (item4, item 11, item 10,..)
with quality 2, 3, 1
, respectively.
What I would expect is to pick an item from the list based on the quality parameter. This would mean that I would pick item1
from mylist. My neighbours would pick item11
as it has quality equal to 3, i.e. the highest in its group.
Thank you for your help.
Upvotes: 3
Views: 277
Reputation: 20450
I am reading https://ccl.northwestern.edu/netlogo/docs/rnd.html
rnd:weighted-one-of-list mylist [ [ii] -> ii ]
is it correct to pick an item using the extension in that way?
Yes, that is a correct usage, according to the documentation.
Upvotes: 1