如何在 netlogo 6.1.1 中重写这段代码?

how to rewrite this code in netlogo 6.1.1?

我正在将我的代码从 net logo 3.1.5 转移到 netlogo 6.1.1。我不知道如何让这条线在新版本中工作。这是 netlogo 3.1.5 中的代码行 并且有效:

set d0 sort-by [length ?1 <= length ?2] d0

这一行表示将列表 d0 从小值到大值排序,完成后将结果再次放入 d0。

[length ?1 <= length ?2] 意思是比较名为 ?1 的临时变量的值和名为 ?2

的临时变量的值

在 netlogo 6.1.1 中它告诉我没有定义任何名为 ?1 的东西

你能帮帮我吗!

NetLogo 词典可在 https://ccl.northwestern.edu/netlogo/docs/dictionary.html 处找到,这是查找 v3 代码中任何原语的新语法的良好起点。在这种情况下,sort-by 的示例之一是根据字符串的长度进行排序。我猜 d0 的内容是字符串——从你的问题中不清楚,因为你谈论的是从小值到大值的排序,但你的代码中有 length

假设您按长度排序,这里是字典中给出的确切示例:

show sort-by [ [string1 string2] -> length string1 < length string2 ] ["Grumpy" "Doc" "Happy"]

给[“Doc”“快乐”“脾气暴躁”]

翻译成你的情况,你可能想要:

set d0 sort-by [ [s1 s2] length s1 <= length s2] d0