See http://ccl.northwestern.edu/netlogo/docs/dictionary.html#ask"
(let
- ((iter (shufflerator agent-set)))
+ ((iter (shufflerator (agent-set-list agent-set))))
(loop
:for agent := (funcall iter)
:while agent
See http://ccl.northwestern.edu/netlogo/docs/dictionary.html#of"
(let
- ((iter (shufflerator agent-set)))
+ ((iter (shufflerator (agent-set-list agent-set))))
(loop
:for agent := (funcall iter)
:while agent
:collect (let ((*myself* *self*) (*self* agent)) (funcall fn)))))
-(defun shufflerator (agent-set)
+(defun shufflerator (agent-set-list)
(let
- ((copy (copy-list agent-set))
+ ((copy (copy-list agent-set-list))
(i 0)
(agent nil))
(flet
See http://ccl.northwestern.edu/netlogo/docs/dictionary.html#random-float"
(clnl-random:next-double n))
+(defun one-of (agent-set)
+ "ONE-OF AGENT-SET => RESULT
+
+ RESULT: RANDOM-AGENT | :nobody
+
+ARGUMENTS AND VALUES:
+
+ AGENT-SET: An agent set
+ RANDOM-AGENT: an agent if AGENT-SET is non empty
+
+DESCRIPTION:
+
+ From an agentset, returns a random agent. If the agentset is empty, returns nobody.
+
+ See http://ccl.northwestern.edu/netlogo/docs/dictionary.html#one-of"
+ (let*
+ ((agent-set-list (agent-set-list agent-set))
+ (length (length agent-set-list)))
+ (if (zerop length) :nobody (nth (clnl-random:next-int length) agent-set-list))))
+
(defun jump (n)
(when (not (turtle-p *self*)) (error "Gotta call fd in turtle scope, dude (~A)" *self*))
(setf
(defmethod dump-object ((o list)) (format nil "[~{~A~^ ~}]" (mapcar #'dump-object o)))
+(defmethod dump-object ((o patch))
+ (format nil "(patch ~A ~A)" (dump-object (patch-xcor o)) (dump-object (patch-ycor o))))
+
+(defmethod dump-object ((o turtle)) (format nil "(turtle ~A)" (dump-object (turtle-who o))))
+(defmethod dump-object ((o (eql :nobody))) (format nil "nobody"))
+
(defun current-state ()
"CURRENT-STATE => WORLD-STATE
(defreportertestwithsetup "set / pcolor" "ask patches [ set pcolor green ]" "[ pcolor ] of patches"
"[55 55 55 55 55 55 55 55 55]"
"3E246C518581E004BC65EFB074A09BA2EEBB2910")
+
+(defsimplereportertest "one-of 1" "one-of patches" "(patch -1 -1)"
+ "0BDACB8E9D2BB768C01826E993B47D83D39FBD0C")
+
+(defsimplereportertest "one-of 2" "one-of turtles" "nobody"
+ "E1DE30F072D785E0D0B59F28B0F7853E3D3E0D8B")
+
+(defreportertestwithsetup "one-of 3" "crt 10" "one-of turtles" "(turtle 5)"
+ "A056ED8BF26A69FB4437E79F263E362C27F8820E")