Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Deleting a type in Common Lisp

Does Common Lisp provide a facility for undefining types created with deftype?

I've not found anything in the Hyperspec about it.

like image 681
Lex Avatar asked Sep 01 '12 16:09

Lex


1 Answers

I would just unintern the derived type specifier:

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]

Also, if you are really concerned about deleting every trace of the type for some reason, you can always write implementation-dependent code to achieve it, even if such functionality is not mentioned in the standard. For example, in CCL (untested, I just skimmed the relevant code):

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

And here we go:

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]
like image 80
danlei Avatar answered Oct 14 '22 04:10

danlei