你好我有下一个代码:
to difusion-out
if any? turtles with [color = yellow and shape = "ai"]
[
let mylist (list ([autoinduc] of turtles with [shape = "circle 2" and color = yellow]))
let mylist2 (list count turtles with [shape = "ai"])
let mylist3 (map [?1 - ?2] (mylist) (mylist2))
let mylist4 sum (mylist3)
let concentracion-se ((- kse * count turtles with [shape = "ai"] ) + ( 2 * (mylist4)))
ask one-of turtles with [shape = "ai"]
[hatch concentracion-se
]
]
end
我要做的是将mylist的每个成员减去mylist2的每个成员,这样这个名为mylist3的新列表需要使用命令sum对所有成员求和。但是在运行程序时我得到了这个错误: - 预期的输入是一个数字但是得到了列表[0]。 观察者跑步时出错 - 那可能是什么问题呢?我没有很好地定义我的列表,或者map命令没有正确使用?
答案 0 :(得分:1)
map
看起来很好。您错误地设置了列表:
let mylist (list ([autoinduc] of turtles with [shape = "circle 2" and color = yellow]))
[autoinduc] of turtles with [shape = "circle 2" and color = yellow]
会返回海龟'autoinduc
的列表。当您将list
放在它前面时,它会将整个列表粘贴到另一个列表中。因此,您最终得到[[1 2 3]]
而不是[1 2 3]
。
我认为这也是错误的:
let mylist2 (list count turtles with [shape = "ai"])
count turtles with [shape = "ai"]
返回一个数字(具有该形状的海龟数量)。将list
放在它前面将该单个数字粘贴在列表中。所以你最终会得到一个单个数字的列表,这可能不是你想要的。