Is a macro executed in the context of the package where it is defined,
or where it is executed ?
My problem is basically this. I have a package P1 which defines some
component functions and a macro, and a package P2 which uses package
P1.
In package P2 I have two lists, which are supplied to the macro from
P1. This macro does two things :
- from the first list it creates accessor functions
- from the second list it creates an initialisation function for a
structure.
Upon testing I saw a potential problem, and when I expanded the macro
call in package P2 I saw the following expansion.
All the functions which where generated from the first list looked
like :
(defun accessor (p1::system) (function p1::system))
and the initialisation function looked like this :
(DEFUN SYS-2-STRUCT-INIT (P1::SYSTEM)
(CONNECT-COMPONENTS *CONNECTION-DATABASE* P1::SYSTEM)
(COMMENT-CONNECTION *ALIAS-DATABASE* P1:SYSTEM)))
But the functions connect-components and comment-connection originate
in P1 (I even write in the macro `(...P1:CONNECT-COMPONENTS)).
At the same time, when running the generated code, the system
complains that SYS-2-STRUCT-INIT is not available in P2, although that
is where the macro call is written.
As an aside, I suppose that the reason my accessors are not expanded
in P1::accessor, is that the symbols used to define them originate
from package P2 ?
Regards,
Jurgen
On Feb 23, 1:24 pm, "jurgen_defurne" <··············@pandora.be>
wrote:
> Is a macro executed in the context of the package where it is defined,
> or where it is executed ?
Where it is executed.
On Feb 23, 2:35 pm, "Tim Bradshaw" <··········@tfeb.org> wrote:
> On Feb 23, 1:24 pm, "jurgen_defurne" <··············@pandora.be>
> wrote:
>
> > Is a macro executed in the context of the package where it is defined,
> > or where it is executed ?
>
> Where it is executed.
I found out what the problem was : I forgot to prefix the macro
invocation with the package prefix.
But anyway, thanks for the clarification.
Jurgen