New to NetLogo... wondering if there's a procedure that performs an operation on one item in a list in a compact way (like map but for one item).
For example, say I wanted to add 3 to the item at index i in list blah.
Right now I'm doing this like:
set blah replace-item i blah (item i blah + 3)
It seems a little clunky, and like there would be a procedure that does that, but I haven't been able to find one. Just wanted to make sure I wasn't missing something.
Thank you! Taylor
There isn't something built in that does this. But you could define it yourself as a procedure that takes a task as input:
;; replace item i of xs with the result of applying fn to that item
to-report mapping-replace-item [i xs fn]
report replace-item i xs (runresult fn item i xs)
end
Sample usage:
observer> show mapping-replace-item 2 [10 20 30 40] task [? * ?]
observer: [10 20 900 40]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With