In article <
87haz4w...@kuiper.lan.informatimago.com>,
> RG <
rNOS...@flownet.com> writes:
> >> > But why on earth would you want with-package-aliases?
> >>
> >> Along with the reader macro, it would keep the aliasing in the lexical
> >> scope.
> >
> > Huh? Which lexical scope? This is (per your suggestion) a reader macro
> > we're talking about here. There is no lexical environment in a reader
> > macro.
>
> But there is! A reader macro deals with text, and defines a textual
> scope, which is the definition of a lexical scope.
No, it isn't. At least that's not the definition of lexical scope in
the ANSI CL standard. That definition is:
lexical scope n. scope that is limited to a spatial or textual region
within the establishing form.
There is no "establishing form" in a reader macro.
But fine, we can go with your definition for now...
> All the characters
> between the closing parenthesis of the first list inside
> [with-package-aliases, and the closing ], define the lexical scope
> where the package aliases are in effect.
>
> With:
>
> (defpackage "X" (:use "CL"))
> (in-package "X")
> (defun print (obj) (list obj obj))
That's an error. You can't rebind symbols in the CL package.
Perhaps you meant something more like this:
(make-package :x)
(make-package :y)
(in-package :x)
(defun foo () 'x-foo)
(defun baz () 'x-baz)
(in-package :y)
(defun baz () 'y-baz)
(defun bar () 'y-bar)
(in-package :cl-user)
(with-package-aliases ((:x :y))
(x::foo)
(x::baz)
(x::bar)
)
Running this code under Daniel's reference implementation is instructive.
> (in-package "CL-USER")
> (defun f () (x::print 'hi))
>
>
> (with-package-aliases ((:x :cl))
> (x::print (f)))
>
> would print:
>
> HI
> HI
>
> while:
>
> [with-package-aliases ((:x :cl))
> (x::print (f))]
>
> would print:
>
> (HI HI)
It's hard to say what [w-p-a ...] would do becase because we don't have
a working version of it yet in this thread.
But the problem you'd encounter following the strategy I suggested has
nothing to do with lexical scope, it has to do with the fact that you
can't use the name of an existing package as a nickname for another
package. But that is also easily solved (assuming the goal is to
reproduce the behavior of Daniel's reference implementation) by
temporarily renaming the existing package.
I still fail to see the point of this exercise.
rg