(defmethod update :before ((a AGENT) (e UPDATE))
(when (null (timestamps a))
(push 0 (pls a))
(push 0 (fitnesses a)))
(push (timestamp e) (timestamps a))
(push (price e) (revalprices a))
(preprocess a e)
(format T ":BEFORE completed for agent ̃A and event ̃A ̃%" a e))
The above method came from a book and I wanted to inquire about what is the difference between update
and :before
. From my understanding from defining methods in CLOS Lisp, the update
is the name of the method, but what does :before
do?
Lastly what does the last line do? (format T ":BEFORE completed for agent ̃A and event ̃A ̃%" a e))
What you're looking at is the definition of a :before
auxiliary method. When the method update
is called with arguments that satisfy the types agent
and update
, this piece of code will run before the main method body. It's also possible to define :after
and :around
auxiliaries. Have a look at this PCL chapter for more information.
As to the format
string, I assume that's mistranscribed. The form you've got there will just issue a warning that you're passing it too many format arguments. I think what's meant is
(format t ":BEFORE completed for agent ~a and event ~a~%" a e)
which will print ":BEFORE completed for agent "
followed by the value of a
, followed by " and event "
followed by the value of e
, followed by a newline, to the stream *standard-output*
. For more information on CL's format
directives, take a look at this other PCL chapter, and possibly also this section of the CLHS