Reputation: 119
I'm having trouble converting an older model to Netlogo 6. Specifically, I have two reporters process lists that I can't get to work correctly with the new syntax. Both incorporate the old ?2 ?1 syntax used in V5.0 and below. I would appreciate any assistance. Here is the code
to-report util-partial-sums [#lst]
set #lst (fput [0] #lst)
report butfirst reduce [lput (?2 + last ?1) ?1] #lst
end
to-report util-compare-adjacent-pairs-in-list [randnum specieslist]
let post 0
let list1 (butlast specieslist)
let list2 (butfirst specieslist)
ifelse randnum <= first specieslist [set post 0]
[ifelse randnum > last specieslist [set post position (last specieslist) specieslist]
[
(foreach list1 list2 [
if randnum > ?1 and randnum <= ?2 [set post ((position ? specieslist) + 1)]])
]
]
report post
end
Upvotes: 3
Views: 126
Reputation: 3806
Anonymous procedures now require you to explicitly define parameters (in-line), rather than use pre-defined 1st/2nd.
That being said:
[lput (?2 + last ?1) ?1]
should be mapped to
[[x y] -> lput (y + last x) x]
The same issue occurs within the for loop.
This is particularly useful: https://ccl.northwestern.edu/netlogo/docs/programming.html#anonymous-procedures
Anonymous procedure takes more than one input
nothing
(foreach xs ys [ [ x y ] -> setx x + y ])
(map [ [ x y ] -> x mod round y ] xs ys)
Upvotes: 3