1 (in-package #:clnl-nvm)
3 (defun agent-value (var &optional (agent *self*))
4 "AGENT-VALUE VAR &optional AGENT => RESULT
9 AGENT: an agent, defaulting to *self*
10 RESULT: the value of VAR
14 AGENT-VALUE is the general agent variable access function. For many
15 NetLogo reporters, the compilation results is AGENT-VALUE. The list of
16 valid values are any builtin variable in the NetLogo dictionary, as well
17 as any *-own variable.
19 See http://ccl.northwestern.edu/netlogo/docs/dictionary.html for builtins"
20 (agent-value-inner agent (intern (string-upcase var) :keyword)))
22 (defsetf agent-value (var &optional (agent '*self*)) (new-value)
23 `(set-agent-value-inner ,agent ,var ,new-value))
25 (defgeneric set-agent-value-inner (agent var new-value))
26 (defgeneric agent-value-inner (agent var))
28 (defmacro defagent-value (type symb &optional accessor)
30 ((accessor (or accessor (intern (format nil "~A-~A" type symb))))
35 (defmethod agent-value-inner ((,agent ,type) (,var (eql ,symb))) (,accessor ,agent))
36 (defmethod set-agent-value-inner ((,agent ,type) (,var (eql ,symb)) ,new-val) (setf (,accessor ,agent) ,new-val)))))
38 ; Don't want the setter for :who
39 (defmethod agent-value-inner ((agent turtle) (var (eql :who))) (turtle-who agent))
41 (defagent-value patch :pcolor patch-color)
43 (defagent-value turtle :color)
44 (defagent-value turtle :label)
45 (defagent-value turtle :label-color)
46 (defagent-value turtle :size)