anonymous
anonymous

Reputation: 1532

Bulk `unintern` for renamed exported symbols

I use packages a lot and the exported symbols often change their names. When I try to recompile the package I get warnings like this:

package.lisp:3:1:
warning: 
    MY-PROJECT also exports the following symbols:
  (OLD-SYMBOL1 OLD-SYMBOL2 OLD-SYMBOL3)

See also:
  Common Lisp Hyperspec, DEFPACKAGE [:macro]
  SBCL Manual, *ON-PACKAGE-VARIANCE* [:variable]
--> EVAL-WHEN 
==>
  (SB-IMPL::%DEFPACKAGE "MY-PACKAGE" '("KE") 'NIL 'NIL 'NIL '("CL") 'NIL
                        'NIL '("NEW-EXPORTED-SYMBOL1" "NEW-EXPORTED-SYMBOL2") '("MY-PROJECT") 'NIL
                        ...)

I know that I can use (unintern 'old-symbol1) to signal the system I don't want to use that symbol anymore. However this is becoming very tedious when there is a lot of renaming.

My questions are:

1) Is is possible to signal to sbcl or emacs to unintern the old/previously exported symbols automatically?

2) If not - is it possible to get all "old" symbols in a variable?

My plan for 2) is to make a key binding to something like (apply #'unintern *old-symbols*)

Upvotes: 3

Views: 272

Answers (2)

PuercoPop
PuercoPop

Reputation: 6807

First I don't think you want to unitern symbols. Unintern removes them from the package. I think you want to unexport them to avoid the warning. You can do that with the following function

(defun unexport-package-symbols (package)
  (do-symbols (symbol package)
    (destructuring-bind (symbol status)
        (find-symbol (symbol-name symbol) package)
      (when (eq status :external)
        (cl:unexport symbol package)))))

;; It takes a package-designator as an argument.
(unexport-package-symbols "MY-PACKAGE")

Upvotes: 3

jkiiski
jkiiski

Reputation: 8411

Setting the variable *on-package-variance* to a list (:error t) will give you an error instead of a warning when redefining the package. The error will have a restart DROP-THEM to unexport the symbols.

You can add

(setf *on-package-variance* '(:error t))

to your ~/.sbclrc to have it always set when starting up SBCL.

Upvotes: 6

Related Questions