NetLogo:将报告程序转换为匿名过程

时间:2018-10-29 12:31:56

标签: netlogo

我无法将较旧的模型转换为Netlogo6。具体地说,我有两个报告程序进程列表,无法使用新语法正常工作。两者都结合了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 

1 个答案:

答案 0 :(得分:2)

现在,匿名过程要求您(在线)显式定义参数,而不是使用预定义的1st / 2nd。

话虽这么说

[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)