Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Hierarchical packages using user-extensible packages
(in-package :cl-user)
(defstruct (hierarchical-package (:include sb-package:standard-package)))
(defmethod sb-package:find-package (package-designator (package hierarchical-package))
(flet ((find-package-from-string (string)
(when (and (> (length string) 0)
(char= (elt string 0) #\.))
(setq string (concatenate 'string (package-name package) string)))
(call-next-method string package)))
(typecase package-designator
(package package-designator)
(symbol (find-package-from-string (symbol-name package-designator)))
(string (find-package-from-string package-designator))
(character (find-package-from-string (string package-designator)))
(t (error 'type-error
:datum package-designator
:expected-type '(or character package string symbol))))))
(let ((package (make-hierarchical-package
:%name "FOO"
:internal-symbols (sb-impl::make-or-remake-package-hashtable 10)
:external-symbols (sb-impl::make-or-remake-package-hashtable 10))))
(sb-impl::initialize-package package :use '(:cl)))
(defpackage (:use :cl))
(setq *package* (find-package :foo))
(print (find-package
(print (.bar::+ 1 2))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment