Skip to content

Instantly share code, notes, and snippets.

@adlai
Last active June 23, 2024 12:30
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 (list* (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))))
(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))
@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