gpt4 book ai didi

Lisp Def 方法结构

转载 作者:太空宇宙 更新时间:2023-11-03 18:53:47 24 4
gpt4 key购买 nike

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

最佳答案

您正在查看的是 :before 辅助方法的定义。当使用满足类型agentupdate 的参数调用方法update 时,这段代码将在main 方法主体之前运行。也可以定义 :after:around 助剂。看看this PCL chapter获取更多信息。

至于format 字符串,我认为它被错误转录了。您获得的表格只会发出警告,表明您向其传递的格式参数过多。我想的意思是

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

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

关于Lisp Def 方法结构,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21869052/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com