+ (cond
+ ((agentset-p agent-or-agentset)
+ (let
+ ((iter (shufflerator (agentset-list agent-or-agentset))))
+ (loop
+ :for agent := (funcall iter)
+ :while agent
+ :do (let ((*myself* *self*) (*self* agent)) (with-stop-handler (funcall fn))))))
+ ((agent-p agent-or-agentset)
+ (let ((*myself* *self*) (*self* agent-or-agentset)) (with-stop-handler (funcall fn))))
+ (t
+ (error "Ask requires an agentset or agent but got: ~A" agent-or-agentset))))
+
+(defun count (agentset)
+ "COUNT AGENTSET => N
+
+ARGUMENTS AND VALUES:
+
+ AGENTSET: a NetLogo agentset
+ N: a number
+
+DESCRIPTION:
+
+ COUNT is equivalent to count in NetLogo. Returns N, the number of
+ agents in AGENTSET.
+
+ See http://ccl.northwestern.edu/netlogo/docs/dictionary.html#count"
+ (coerce (length (agentset-list agentset)) 'double-float))
+
+(defun clear-all ()
+ "CLEAR-ALL => RESULT
+
+ARGUMENTS AND VALUES:
+
+ RESULT: undefined
+
+DESCRIPTION:
+
+ Clears ticks, turtles, patches, globals (unimplemented).
+
+ See http://ccl.northwestern.edu/netlogo/docs/dictionary.html#clear-all"
+ (clear-turtles)
+ (clear-patches)
+ (clear-ticks))
+
+(defun display ()
+ "DISPLAY => RESULT
+
+ARGUMENTS AND VALUES:
+
+ RESULT: undefined
+
+DESCRIPTION:
+
+ As of yet, this does nothing. A placeholder method for forced dipslay
+ updates from the engine.
+
+ See http://ccl.northwestern.edu/netlogo/docs/dictionary.html#display"
+ nil)
+
+(defun stop ()
+ "STOP => RESULT
+
+ARGUMENTS AND VALUES:
+
+ RESULT: undefined
+
+DESCRIPTION:
+
+ Returns from the current stop block, which will halt the currently running
+ thing, be that the program, current ask block, or procedure. Stop has odd
+ semantics that are best gleaned from the actual NetLogo manual.
+
+ See http://ccl.northwestern.edu/netlogo/docs/dictionary.html#stop"
+ (error (make-condition 'stop)))
+
+(defun of (fn agent-or-agentset)
+ "OF FN AGENT-OR-AGENTSET => RESULT
+
+ AGENT-OR-AGENTSET: AGENT | AGENTSET
+ RESULT: RESULT-LIST | RESULT-VALUE
+
+ARGUMENTS AND VALUES:
+
+ FN: a function, run on each agent
+ AGENT: a NetLogo agent
+ AGENTSET: a NetLogo agentset
+ RESULT-LIST: a list
+ RESULT-VALUE: a single value
+
+DESCRIPTION:
+
+ OF is equivalent to of in NetLogo.
+
+ The specified AGENTSET or AGENT runs the given FN. In the case of an
+ AGENTSET, the order in which the agents are run is random each time,
+ and only agents that are in the set at the beginning of the call.
+
+ RESULT-LIST is returned when the input is an AGENTSET, but RESULT-VALUE
+ is returned when only passed an AGENT.
+
+ See http://ccl.northwestern.edu/netlogo/docs/dictionary.html#of"
+ (cond
+ ((agentset-p agent-or-agentset)
+ (let
+ ((iter (shufflerator (agentset-list agent-or-agentset))))
+ (loop
+ :for agent := (funcall iter)
+ :while agent
+ :collect (let ((*myself* *self*) (*self* agent)) (funcall fn)))))
+ ((agent-p agent-or-agentset)
+ (let ((*myself* *self*) (*self* agent-or-agentset)) (funcall fn)))
+ (t
+ (error "Of requires an agentset or agent but got: ~A" agent-or-agentset))))
+
+(defun with (agentset fn)
+ "WITH AGENTSET FN => RESULT-AGENTSET
+
+ARGUMENTS AND VALUES:
+
+ AGENTSET: a NetLogo agentset
+ FN: a boolean function, run on each agent to determine if included
+ RESULT-AGENTSET: an agentset of valid agents