gpt4 book ai didi

error-handling - 可以使用make-instance创建条件吗?

转载 作者:行者123 更新时间:2023-12-03 08:03:07 25 4
gpt4 key购买 nike

在Common Lisp中,使用make-instance而不是make-condition制作条件对象是否可移植?
例如:

(define-condition foo (condition)
())

(make-condition 'foo)
(make-instance 'foo)
这与在CLOS类层次结构中放置条件的方式有关吗? (subtypep 'condition 'standard-class)在SBCL和CLISP中返回false。但是, make-instance可以在两个实现中都产生条件。这是由标准保证的吗?

最佳答案

不,这样做显然是不可移植的。从specification:

Conforming code must observe the following restrictions related to conditions:

  • define-condition, not defclass, must be used to define new condition types.
  • make-condition, not make-instance, must be used to create condition objects explicitly.
  • The :report option of define-condition, not defmethod for print-object, must be used to define a condition reporter.
  • slot-value, slot-boundp, slot-makunbound, and with-slots must not be used on condition objects. Instead, the appropriate accessor functions (defined by define-condition) should be used

关于error-handling - 可以使用make-instance创建条件吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63213374/

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