【问题标题】:Lisp Def Method StructureLisp Def 方法结构
【发布时间】:2014-02-19 01:20:54
【问题描述】:
(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))

【问题讨论】:

    标签: lisp common-lisp clos


    【解决方案1】:

    您正在查看的是: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 的值,然后是" and event ",然后是e 的值,然后是换行符,到流*standard-output*。有关 CL 的 format 指令的更多信息,请查看 this other PCL chapter,也可能查看 this section of the CLHS

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-02-21
      • 2014-09-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多