2014-02-19 2 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은 무엇을합니까?리스프 데프 방법 구조

마지막으로 마지막 줄은 무엇입니까? (format T ":BEFORE completed for agent ̃A and event ̃A ̃%" a e))

답변

2

당신이 찾고있는 것은 :before 보조 방법의 정의입니다. 메서드 updateagentupdate 유형의 인수로 호출되면이 코드 부분이 기본 메서드 본문보다 먼저 실행됩니다. :after:around 보조 장치를 정의 할 수도 있습니다. 자세한 내용은 this PCL chapter을보십시오.

문자열에 대해서는 format 문자열로 잘못 입력했다고 가정합니다. 거기에있는 양식은 너무 많은 형식 인수를 전달한다는 경고를 발행합니다. 나는 무엇을 의미하는 것 것은 스트림 *standard-output*에, 개행 다음 e의 값 다음에 " and event " 다음 a의 값, 다음 ":BEFORE completed for agent "을 인쇄 할

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

생각합니다. CL의 format 명령어에 대한 자세한 내용은 this other PCL chapter을 참조하십시오. this section of the CLHS