On 2008-12-12, Kaz Kylheku <kkylh...@gmail.com> wrote:
> ;;; provides #@ read macro
> (load "pkg")
> ;;; some test packages
> (defpackage :p1
> (:use :cl)
> (:export :e0 :e1 :e2)
> (:intern :i0 :i1 :i2))
> (defpackage :p2
> (:use :cl)
> (:export :e1 :e2 :e3)
> (:intern :i1 :i2 :i3))
> ;;;
> ;;; Syntax:
> ;;;
> ;;; syntax ::= #@ directive form
> ;;; | #@ ( {directive}* ) form
> ;;;
> ;;; directive := (use {package-spec}*)
> ;;; (from package-spec import {symbol-spec}*)
> ;;;
More syntax:
;;; directive := (use {package-spec}*)
;;; (from package-spec import {symbol-spec}*)
;;; (keep {symbol-spec}*)
;;; (inherit {symbol-spec}*)
;;; (top)
The KEEP directive specifies which symbols newly interned during
the reading of FORM should be retained, i.e. propagated
to the enclosing package. Keep with no arguments (keep)
means do not propagate any new symbols. This means
that any symbols newly created in FORM turn into gensyms
automagically. The default behavior if no (KEEP) form is specified is that all
of the symbols newly interned are propagated to the outer package.
KEEP also causes the specified symbols to be inherited
from the surrounding package, if they are visible there,
to prevent conflicts.
INHERIT means that only the following symbols, which must exist in the
surrounding package, are to be visible to FORM. Overrides anything to the left.
Must be followed by suitable KEEP to prevent conflicts,
since INHERIT will cause any symbols not on the list to be
freshly interned, and by default they will all be propagated
into the surrounding package.
The TOP directive resets the visibility to the top-level
package which was in effect when the reader was invoked.
Examples:
Write a simplified DEFPACKAGE, without using #: on symbols. Let's quote it so
we see the form as it is read. Note treatment of LIST.
#@(keep)
'(defpackage foo (:use cl) (:export xyzzy quux) (:shadow list))
--> (DEFPACKAGE FOO (:USE CL) (:EXPORT #:XYZZY #:QUUX) (:SHADOW LIST))
Propagate the symbol FOO from the form, but let others
lapse into gensyms. Show that the symbols are interned,
first before becoming homeless, using *print-circle*:
(setf *print-circle* t)
#@(keep foo)
'(defun foo (x y z) (+ x y z))
--> (DEFUN FOO (#1=#:X #2=#:Y #3=#:Z) (+ #1# #2# #3#))
Reset visibility to top without having to know explicitly
what that package is called:
#@(from p1 import e1) '(e1 #@(top) e1)
--> (P1:E1 E1)
Demonstrate inherit and keep: LIST symbol is not inherited
this time:
#@((inherit defpackage)
(keep))
'(defpackage foo (:use cl) (:shadow list))
--> (DEFPACKAGE #:FOO (:USE #:CL) (:SHADOW #:LIST))