gpt4 book ai didi

lisp - 删除 Common Lisp 中的类型

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

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/

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