1 ;;;; -*- Mode: Lisp; indent-tabs-mode: nil -*-
3 ;;; --- Creating aliases in CL namespaces
6 (in-package :iolib.base
)
8 (defvar *namespaces
* nil
)
10 (defmacro defalias
(alias original
)
11 (destructuring-bind (namespace new-name
)
13 (assert (member namespace
*namespaces
*) (namespace)
14 "Namespace ~A does not exist" namespace
)
15 (make-alias namespace original new-name
)))
17 (defmacro defnamespace
(namespace &optional docstring
)
18 (check-type namespace symbol
)
19 (check-type docstring
(or null string
))
21 (pushnew ',namespace
*namespaces
*)
22 (handler-bind ((warning #'muffle-warning
))
23 (setf (documentation ',namespace
'namespace
) ,docstring
))))
25 (defgeneric make-alias
(namespace original alias
))
27 (defnamespace function
28 "The namespace of ordinary and generic functions.")
30 (defmethod make-alias ((namespace (eql 'function
))
33 (setf (fdefinition ',alias
)
34 (fdefinition ',original
))
35 (setf (documentation ',alias
'function
)
36 (documentation ',original
'function
))))
39 "The namespace of macros.")
41 (defmethod make-alias ((namespace (eql 'macro
))
44 (setf (macro-function ',alias
)
45 (macro-function ',original
))
46 (setf (documentation ',alias
'function
)
47 (documentation ',original
'function
))))
50 "The namespace of special variables.")
52 (defmethod make-alias ((namespace (eql 'special
))
55 (define-symbol-macro ,alias
,original
)
56 (setf (documentation ',alias
'variable
)
57 (documentation ',original
'variable
))))
59 (defnamespace constant
60 "The namespace of special variables.")
62 (defmethod make-alias ((namespace (eql 'constant
))
65 (define-symbol-macro ,alias
,original
)
66 (setf (documentation ',alias
'variable
)
67 (documentation ',original
'variable
))))