|
|
新手发问超简单问题,目前还处于研读范例码的阶段,边测边看结果来理解程序' J: C5 d+ U# p" c3 n
其中有一段如下! m0 m3 v, V: m9 l \: i/ V
ask turtles with [ infected? = true ] 5 v- M1 s: N% C% ^1 r
我原本以为这句会回传『所有』infected? = true 的 turtle
5 p3 I/ L7 {+ k' G* R但看结果似乎不是这样。
1 b+ }0 [" U9 ]6 w" w- E! V- v
1 n( v3 r. E+ R% V( N假设所有符合条件的有 5 笔
' d! O2 E" @1 W9 p- D- [" |1 g K有时候回传 1 笔,有时回传 3 笔,是不固定的, U* l$ r$ I, n1 g4 o8 C2 a
回头查语法定义
+ j4 W& S! s" k+ ywith
. k- V5 U/ B. ^0 l5 pagentset with [reporter]; b2 b8 [5 w) ^: j( E& F
Takes two inputs: on the left, an agentset (usually "turtles" or "patches"). On the right, a boolean reporter. Reports a new agentset containing only those agents that reported true -- in other words, the agents satisfying the given condition.
9 h& [5 O: [7 D- Z. ~/ ^- Z它只说回传 agents satisfying the given condition3 \2 h7 \+ u3 e5 y
是否 with 回传的是『符合条件』的数据,而不是『所有符合条件』的数据 ? % T+ X0 S7 E& t6 `& Z
' y+ S7 o Z% z6 j& c8 s5 x& `
想确定一下
# `& o% I* l1 r P; ~2 b: r谢谢!
" P1 m0 u" I# H |
|