如何修复 NetLogo 6.0.4 中的 "Nothing named ? has been defined" 错误
How to fix "Nothing named ? has been defined" error in NetLogo 6.0.4
我下载了修改后的随机簇代码,用于使用 NetLogo 建模共享中的 Millington 版本的修改后的随机簇方法生成中性景观模型。当我单击 "generate-landscape" 按钮时,代码中的 "fill-landscape" 过程导致 "Nothing named ? has been defined" 错误。
当我创建附加的界面图像并尝试 运行 下面的相邻代码时。问题似乎与 "occurrences" 报告功能中的问号有关。 reduce 函数未按预期工作。有解决办法吗?看界面,然后代码如下:
ifelse ( any? neighbours with [ cluster != nobody ] ) ;; check if there are any assigned patches in neighbourhood
[
let covers []
ask neighbours with [ cluster != nobody ]
[
set covers fput cover covers ;;ask neighbours to add their covers to the list
]
let unique-covers remove-duplicates covers ;;create a list of unique covers
let max-cover-count -1 ;the number of neighbours with the maximum cover
let max-cover -1 ;the maximum cover
ifelse(length unique-covers > 1)
[
;if there is more than one unique-cover
foreach unique-covers ;for each of the unique covers
[
let occ occurrences ? covers ;count how many neighbours had this cover
ifelse(occ > max-cover-count) ;if the count is greater than the current maximum count
[
set max-cover ? ;set this as the dominant cover
set max-cover-count occ ;update the current maximum count
;---------------
to-report occurrences [x the-list]
report reduce
[ifelse-value (?2 = x) [?1 + 1] [?1]] (fput 0 the-list)
end
;---------------
该代码假定使用由 Saura 和 Martinez-Millan (2000) 开发的修改后的随机集群方法生成中性景观模型。但是,错误"Nothing named ? has been defined"错误的代码来自运行ning顺利。期待思想...
NetLogo 5.x 中的旧 ?
语法在 NetLogo 6 中被新的 ->
语法取代。参见 https://ccl.northwestern.edu/netlogo/docs/programming.html#anonymous-procedures
因此,例如,在 NetLogo 5 中,您可以这样写:
foreach [0 1 2 3] [
print ?
]
在 NetLogo 6 中,你写:
foreach [0 1 2 3] [ x ->
print x
]
Bryan 的答案(第一个过程)和 NetLogo 词典(第二个过程)的组合为您提供了以下内容。注释表示新的位。未测试。
ifelse ( any? neighbours with [ cluster != nobody ] )
[ let covers []
ask neighbours with [ cluster != nobody ]
[ set covers fput cover covers
]
let unique-covers remove-duplicates covers
let max-cover-count - 1 ; added a space around subtraction
let max-cover - 1 ; more spacing
ifelse(length unique-covers > 1)
[ foreach unique-covers
[ this-cover -> ; here's the new bit, calling ? 'this-cover'
let occ occurrences this-cover covers ; passes to the occurrences procedure
ifelse(occ > max-cover-count)
[ set max-cover this-cover ; using the name this-cover again
set max-cover-count occ
对于出现的情况,您可以直接从 NetLogo 词典中获取程序 reduce
示例
to-report occurrences [#x #the-list]
report reduce
[ [occurrence-count next-item] -> ifelse-value (next-item = #x)
[occurrence-count + 1] [occurrence-count] ] (fput 0 #the-list)
end
我下载了修改后的随机簇代码,用于使用 NetLogo 建模共享中的 Millington 版本的修改后的随机簇方法生成中性景观模型。当我单击 "generate-landscape" 按钮时,代码中的 "fill-landscape" 过程导致 "Nothing named ? has been defined" 错误。
当我创建附加的界面图像并尝试 运行 下面的相邻代码时。问题似乎与 "occurrences" 报告功能中的问号有关。 reduce 函数未按预期工作。有解决办法吗?看界面,然后代码如下:
ifelse ( any? neighbours with [ cluster != nobody ] ) ;; check if there are any assigned patches in neighbourhood
[
let covers []
ask neighbours with [ cluster != nobody ]
[
set covers fput cover covers ;;ask neighbours to add their covers to the list
]
let unique-covers remove-duplicates covers ;;create a list of unique covers
let max-cover-count -1 ;the number of neighbours with the maximum cover
let max-cover -1 ;the maximum cover
ifelse(length unique-covers > 1)
[
;if there is more than one unique-cover
foreach unique-covers ;for each of the unique covers
[
let occ occurrences ? covers ;count how many neighbours had this cover
ifelse(occ > max-cover-count) ;if the count is greater than the current maximum count
[
set max-cover ? ;set this as the dominant cover
set max-cover-count occ ;update the current maximum count
;---------------
to-report occurrences [x the-list]
report reduce
[ifelse-value (?2 = x) [?1 + 1] [?1]] (fput 0 the-list)
end
;---------------
该代码假定使用由 Saura 和 Martinez-Millan (2000) 开发的修改后的随机集群方法生成中性景观模型。但是,错误"Nothing named ? has been defined"错误的代码来自运行ning顺利。期待思想...
NetLogo 5.x 中的旧 ?
语法在 NetLogo 6 中被新的 ->
语法取代。参见 https://ccl.northwestern.edu/netlogo/docs/programming.html#anonymous-procedures
因此,例如,在 NetLogo 5 中,您可以这样写:
foreach [0 1 2 3] [
print ?
]
在 NetLogo 6 中,你写:
foreach [0 1 2 3] [ x ->
print x
]
Bryan 的答案(第一个过程)和 NetLogo 词典(第二个过程)的组合为您提供了以下内容。注释表示新的位。未测试。
ifelse ( any? neighbours with [ cluster != nobody ] )
[ let covers []
ask neighbours with [ cluster != nobody ]
[ set covers fput cover covers
]
let unique-covers remove-duplicates covers
let max-cover-count - 1 ; added a space around subtraction
let max-cover - 1 ; more spacing
ifelse(length unique-covers > 1)
[ foreach unique-covers
[ this-cover -> ; here's the new bit, calling ? 'this-cover'
let occ occurrences this-cover covers ; passes to the occurrences procedure
ifelse(occ > max-cover-count)
[ set max-cover this-cover ; using the name this-cover again
set max-cover-count occ
对于出现的情况,您可以直接从 NetLogo 词典中获取程序 reduce
示例
to-report occurrences [#x #the-list]
report reduce
[ [occurrence-count next-item] -> ifelse-value (next-item = #x)
[occurrence-count + 1] [occurrence-count] ] (fput 0 #the-list)
end