See http://ccl.northwestern.edu/netlogo/docs/dictionary.html for builtins"
(agent-value-inner agent (intern (string-upcase var) :keyword)))
+(defsetf agent-value (var &optional (agent '*self*)) (new-value)
+ `(set-agent-value-inner ,agent ,var ,new-value))
+
+(defgeneric set-agent-value-inner (agent var new-value))
(defgeneric agent-value-inner (agent var))
-(defmethod agent-value-inner ((agent turtle) (var (eql :who))) (turtle-who agent))
+(defmacro defagent-value (type symb &optional accessor)
+ (let
+ ((accessor (or accessor (intern (format nil "~A-~A" type symb))))
+ (agent (gensym))
+ (var (gensym))
+ (new-val (gensym)))
+ `(progn
+ (defmethod agent-value-inner ((,agent ,type) (,var (eql ,symb))) (,accessor ,agent))
+ (defmethod set-agent-value-inner ((,agent ,type) (,var (eql ,symb)) ,new-val) (setf (,accessor ,agent) ,new-val)))))
+
+(defagent-value turtle :who)
+
+(defagent-value patch :pcolor patch-color)
(setf (turtle-who *self*) -1)
(setf *turtles* (remove *self* *turtles*)))
+(defun patches ()
+ "PATCHES => ALL-PATCHES
+
+ARGUMENTS AND VALUES:
+
+ ALL-PATCHES: a NetLogo agentset, all patches
+
+DESCRIPTION:
+
+ Reports the agentset consisting of all the patches.
+
+ This agentset is special in that it represents the living patches
+ each time it's used, so changes depending on the state of the engine.
+
+ See http://ccl.northwestern.edu/netlogo/docs/dictionary.html#patches"
+ *patches*)
+
(defun turtles ()
"TURTLES => ALL-TURTLES
#:of
#:forward
#:lookup-color
+ #:patches
#:reset-ticks
#:random-float
#:show
`(lambda () ,@(transpile-commands-inner (cdr block))))
(defun transpile-reporter-block (block)
- ;(when (/= (length block) 1) (error "Reporter block invalid ~S" block))
+ (when (/= (length block) 2) (error "Reporter block invalid ~S" block))
`(lambda ()
- ,@(transpile-reporter (cadr block))))
+ ,(transpile-reporter (cadr block))))
; Undoes the previous function :)
(defun make-command-block-inline (block)
`(push (list :name ,name :real-symb ,real-symb) *prim-aliases*))
(defmacro defagentvalueprim (name)
- `(defsimpleprim ,name :reporter (clnl-nvm:agent-value ,name)))
+ `(defprim ,name :reporter (lambda () `(clnl-nvm:agent-value ,,name))))
; We count on the parser to handle arguemnts for us, when collating things.
(defsimpleprim :lt :command clnl-nvm:turn-left)
(defkeywordprim :nobody)
(defsimpleprim :of :reporter clnl-nvm:of)
+(defsimpleprim :patches :reporter clnl-nvm:patches)
+(defagentvalueprim :pcolor)
(defsimpleprim :reset-ticks :command clnl-nvm:reset-ticks)
(defsimpleprim :random-float :reporter clnl-nvm:random-float)
(defsimpleprim :rt :command clnl-nvm:turn-right)
(defsimpleprim :show :command clnl-nvm:show)
+(defsimpleprim :set :command cl:setf)
(defsimpleprim :tick :command clnl-nvm:tick)
(defsimpleprim :ticks :reporter clnl-nvm:ticks)
(defsimpleprim :turtles :reporter clnl-nvm:turtles)
(defreportertestwithsetup "of / who 1" "crt 10" "[ who ] of turtles" "[5 9 4 3 7 0 1 2 6 8]"
"3F39BD2D8D5A1B2333E6C0DB665DBE3DCD5A75CE")
+
+(defreportertestwithsetup "set / pcolor" "ask patches [ set pcolor green ]" "[ pcolor ] of patches"
+ "[55 55 55 55 55 55 55 55 55]"
+ "3E246C518581E004BC65EFB074A09BA2EEBB2910")
(defviewtest "lt" "crt 20 ask turtles [ fd 2 lt 100 fd 2 ]"
'("BF49775097BBFAE12E42D6F13FAFC93090B7ACAC" "ABAEAF8DDD68E7F0FED6CB243F27DB312588A1E8"))
+
+(defviewtest "pcolor green" "ask patches [ set pcolor green ]"
+ "90F5F4870955B9FF02224F00E3C9814B8A6F766E")