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
&optional args
)
13 (assert (member namespace
*namespaces
*) (namespace)
14 "Namespace ~A does not exist" namespace
)
15 (make-alias namespace original new-name args
)))
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 args
))
27 (defnamespace function
28 "The namespace of ordinary and generic functions.")
30 (defmethod make-alias ((namespace (eql 'function
))
36 "The namespace of macros.")
38 (defmethod make-alias ((namespace (eql 'macro
))
40 (declare (ignore args
))
41 (alexandria:with-gensyms
(args)
42 `(setf (macro-function ',alias
)
44 (apply (macro-function ',original
) ,args
)))))
47 "The namespace of special variables.")
49 (defmethod make-alias ((namespace (eql 'special
))
51 (declare (ignore args
))
52 `(define-symbol-macro ,alias
,original
))
54 (defnamespace constant
55 "The namespace of special variables.")
57 (defmethod make-alias ((namespace (eql 'constant
))
59 (declare (ignore args
))
60 `(define-symbol-macro ,alias
,original
))