Skip to content

Instantly share code, notes, and snippets.

@adlai
Last active September 19, 2024 21:09
Show Gist options
  • Save adlai/eb29616be321f351d72a to your computer and use it in GitHub Desktop.
Save adlai/eb29616be321f351d72a to your computer and use it in GitHub Desktop.
package hackery for moving classes between packages
(defgeneric rehome-class (class new-home)
(:method ((class symbol) new-home)
(rehome-class (find-class class) (find-package new-home)))
(:method ((class class) (new-home package))
(let ((old-home (symbol-package (class-name class)))
(symbols `(,(class-name class)
,@(mapcar 'sb-mop:slot-definition-name
(sb-mop:class-direct-slots class)))))
(mapc (lambda (symbol) (unintern symbol old-home)) symbols)
(import symbols new-home)
(import symbols old-home))))
;;; `(,'car ,@'(cadr caddr)) = (list* 'car '(cadr caddr))
(defun rehome-symbol
(symbol new-home &aux (old-home (symbol-package symbol)))
(unintern symbol old-home)
(import (list symbol) new-home)
(import (list symbol) old-home))
;;; try to avoid triggering `C-u M-q' and `C-x f' within lisp
@adlai
Copy link
Author

adlai commented Sep 24, 2014

updated to import instead of intern

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment