lisp - 删除 Common Lisp 中的类型

标签 lisp common-lisp

Common Lisp 是否提供一种工具来取消定义使用 deftype 创建的类型? ?

我在 Hyperspec 中没有找到任何关于它的信息。

最佳答案

我只是unintern派生类型说明符:

T1> (deftype foo () 'fixnum)
FOO
T1> (let ((bar 1))
      (check-type bar foo))
NIL
T1> (unintern 'foo)
T
T1> (let ((bar 1))
      (check-type bar foo))

Unknown type specifier: FOO
   [Condition of type SIMPLE-ERROR]

此外,如果您真的担心出于某种原因删除该类型的所有踪迹,您总是可以编写依赖于实现的代码来实现它,即使标准中没有提到这样的功能。比如在CCL中(未经测试,我只是粗略浏览了一下相关代码):

(defun delete-type (derived-type-specifier)
  (ccl::clear-type-cache)
  (remhash derived-type-specifier ccl::%deftype-expanders%)
  (setf (documentation derived-type-specifier 'type) nil))

我们开始吧:

T1> (deftype foo () "frob" 'fixnum)
FOO
T1> (documentation 'foo 'type)
"frob"
T1> (let ((bar 1))
      (check-type bar foo))
NIL
T1> (delete-type 'foo)
NIL
T1> (documentation 'foo 'type)
NIL
T1> (let ((bar 1))
      (check-type bar foo))

Unknown type specifier: FOO
   [Condition of type SIMPLE-ERROR]

关于lisp - 删除 Common Lisp 中的类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12229488/

相关文章:

syntax - 文件流字符以对象结尾

python - 当一个 DSL 得到 'lispy'

lisp - 如何将存储在变量中的值添加到列表中?

io - Common Lisp 格式 : call function with slash in name using ~/directive

lisp 正负之间的区别

lisp - 为什么 llvm 上没有好的方案/lisp?

java - 如何使用 Java 获取 ABCL 中的值

lispworks fli : cannot be converted to foreign type

lisp - 寻找最大元素的迭代解决方案

common-lisp - 如何创建由 `make-symbol` 创建的符号