Netlogo:将报告者转换为匿名程序

Netlogo: converting reporter to anonymous procedure

我在将旧模型转换为 Netlogo 6 时遇到问题。具体来说,我有两个记者进程列表,我无法使用新语法正确工作。两者都包含 V5.0 及更低版本中使用的旧 ?2 ?1 语法。如有任何帮助,我将不胜感激。这是代码

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 

匿名程序现在要求您明确定义参数(内联),而不是使用预定义的第一个/第二个。

也就是说:

[lput (?2 + last ?1) ?1]

应映射到

[[x y] -> lput (y + last x) x]

同样的问题发生在 for 循环中。

这特别有用: https://ccl.northwestern.edu/netlogo/docs/programming.html#anonymous-procedures

匿名过程需要不止一个输入
没有

(foreach xs ys [ [ x y ] -> setx x + y ])

(map [ [ x y ] -> x mod round y ] xs ys)