1 (in-package #:clnl-nvm)
3 (defun ask (agent-or-agentset fn)
4 "ASK AGENT-OR-AGENTSET FN => RESULT
6 AGENT-OR-AGENTSET: AGENT | AGENTSET
10 FN: a function, run on each agent
11 RESULT: undefined, commands don't return
12 AGENT: a NetLogo agent
13 AGENTSET: a NetLogo agentset
17 ASK is equivalent to ask in NetLogo.
19 The specified AGENTSET or AGENT runs the given FN. In the case of an
20 AGENTSET, the order in which the agents are run is random each time,
21 and only agents that are in the set at the beginning of the call.
23 See http://ccl.northwestern.edu/netlogo/docs/dictionary.html#ask"
25 ((agentset-p agent-or-agentset)
27 ((iter (shufflerator (agentset-list agent-or-agentset))))
29 :for agent := (funcall iter)
31 :do (when (not (and (turtle-p agent) (= -1 (turtle-who agent))))
32 (let ((*myself* *self*) (*self* agent)) (with-stop-and-death-handler (funcall fn)))))))
33 ((agent-p agent-or-agentset)
34 (let ((*myself* *self*) (*self* agent-or-agentset)) (with-stop-and-death-handler (funcall fn))))
36 (error "Ask requires an agentset or agent but got: ~A" agent-or-agentset))))
47 Returns from the current stop block, which will halt the currently running
48 thing, be that the program, current ask block, or procedure. Stop has odd
49 semantics that are best gleaned from the actual NetLogo manual.
51 See http://ccl.northwestern.edu/netlogo/docs/dictionary.html#stop"
52 (error (make-condition 'stop)))