- (let
- ((iter (shufflerator (agent-set-list agent-set))))
- (loop
- :for agent := (funcall iter)
- :while agent
- :collect (let ((*myself* *self*) (*self* agent)) (funcall fn)))))
+ (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
+
+DESCRIPTION:
+
+ WITH is equivalent to with in NetLogo.
+
+ Returns a new agentset containing only those agents that reported true
+ when FN is called.
+
+ See http://ccl.northwestern.edu/netlogo/docs/dictionary.html#with"
+ (list->agentset
+ (remove-if-not
+ (lambda (agent)
+ (let ((*myself* *self*) (*self* agent)) (funcall fn)))
+ (agentset-list agentset))
+ (agentset-breed agentset)))