|
|
新手发问超简单问题,目前还处于研读范例码的阶段,边测边看结果来理解程序
8 R) H* B4 {/ N3 X7 M其中有一段如下- l0 s a2 q2 E; B, a3 N
ask turtles with [ infected? = true ]
Y% G' B5 j' t; L" _; Z我原本以为这句会回传『所有』infected? = true 的 turtle, d) Y9 i0 N9 N, q; r1 N) w
但看结果似乎不是这样。 a# H2 E9 \: e; y8 |4 d5 e6 ?" l
" j+ Q( O" v* O H: s) x6 |
假设所有符合条件的有 5 笔( S+ k0 L, q; z5 f# O: q
有时候回传 1 笔,有时回传 3 笔,是不固定的! t, e$ [" c y+ E" H, I! a
回头查语法定义
3 F/ j/ d- _7 G+ ]; o( d3 Rwith
2 _' x1 G" b$ `+ R) sagentset with [reporter]2 r1 N" c C9 R X! C# Y
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./ R$ L# v8 E) Y8 i5 ^
它只说回传 agents satisfying the given condition
! p+ ^3 p, M* {: R是否 with 回传的是『符合条件』的数据,而不是『所有符合条件』的数据 ? ; x! X/ U( W8 A/ v" c
* L4 h+ H( X! n' k- ^2 \8 B. U3 [, Y
想确定一下
4 e. w7 J! O+ Z% |谢谢!
) L2 q: M2 E& `( V |
|