Lisp Def方法结构

时间:2014-02-19 01:20:55

标签: lisp common-lisp clos

(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))

上述方法来自一本书,我想询问update:before之间的区别。根据我对CLOS Lisp中定义方法的理解,update是方法的名称,但:before做了什么?

最后一行是做什么的? (format T ":BEFORE completed for agent ̃A and event ̃A ̃%" a e))

1 个答案:

答案 0 :(得分:2)

您正在查看的是:before辅助方法的定义。当使用满足类型updateagent的参数调用方法update时,这段代码将在主方法体之前运行。也可以定义:after:around辅助设备。有关详细信息,请查看this PCL chapter

至于format字符串,我认为这是错误的。你在那里获得的表单只会发出一个警告,告诉你它传递了太多的格式参数。我认为是什么意思

(format t ":BEFORE completed for agent ~a and event ~a~%" a e)

将打印":BEFORE completed for agent "后跟a的值,然后是" and event ",后跟e的值,后跟新行,到流{{ 1}}。有关CL的*standard-output*指令的更多信息,请查看this other PCL chapter,还可能this section of the CLHS