2014-02-19 42 views
1
(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的作用是什麼?Lisp的防守方法結構

最後最後一行做了什麼? (format T ":BEFORE completed for agent ̃A and event ̃A ̃%" a e))

回答

2

你在看什麼是:before輔助方法的定義。當使用滿足agentupdate類型的參數調用方法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值,跟着一個換行符,到流*standard-output*。有關CL的format指令的更多信息,請參閱this other PCL chapter,並且可能還有this section of the CLHS