|
|
新手发问超简单问题,目前还处于研读范例码的阶段,边测边看结果来理解程序
; V: m) R( K& n1 B其中有一段如下; A, a8 i3 p/ p1 X, n; _7 E2 o0 y
ask turtles with [ infected? = true ] ! K& t. s& c3 R/ W& m
我原本以为这句会回传『所有』infected? = true 的 turtle; I6 n& A+ f% p6 i# L* a2 p8 L, O+ N) L
但看结果似乎不是这样。
0 m' [) ~5 i4 o" Q" ] y5 v! i7 y% n
假设所有符合条件的有 5 笔
" C6 Q& M" Z* f' [4 `, n& @3 ?有时候回传 1 笔,有时回传 3 笔,是不固定的2 X& }4 w& m* X" A0 u( x9 t0 B6 T
回头查语法定义. ^0 d) ?4 `1 H7 x4 B
with
- P5 ]6 N$ G3 z Z2 ~agentset with [reporter]. C2 O' z, g& q$ U5 j2 M
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.3 ~2 K) ?! Z+ `
它只说回传 agents satisfying the given condition
! C: c9 V6 [, F" s& }# l% S是否 with 回传的是『符合条件』的数据,而不是『所有符合条件』的数据 ? ) M) D3 p. ?) D3 U# l w- l( x4 X2 l
9 g4 i( a- G6 z) ^/ a8 q想确定一下( Q4 V4 ^! i% [4 A, x
谢谢!' {" u. O/ ^! u& \1 p& e
|
|