Re: Macros and symbols across packages



"Jeff M." <massung@xxxxxxxxx> writes:

> I'm curious if there is a method of making sure that symbols will
> evaluate "properly" across packages for use in a macro. For example, I
> have a package that will generate ARM assembly code like so:
>
> (addne r0 r0 r1 :lsl 4) => #x...
>
> Of course, when I use these macros from outside the ARM package,
> though, none of my symbols (registers) match those in the ARM package.
> The only two ideas I can think of to ensure that they match would be
> to:
>
> 1. Modify the instruction macro to always intern register symbols into
> the current package (bad, IMO, but only for gut reasons) or

As Pascal already pointed out, it is too late by the time your macro
executes, since the symbols have already been interned by the reader.
That is unless you decide to make the input be a string instead.

One solution, which BTW is used by the CL LOOP macro, is also mentioned
by Pascal: Test symbols via SYMBOL-NAME rather than EQ. That means the
macro that expands into the assembler doesn't care about the package,
but only about the name of the symbol used in this language.

> 2. Create a reader character macro that will change which package I'm
> in for the rest of the read:

No. I would not go this way.

> { (addne r0 r0 r1 :lsl 4) }
>
> I'm willing to do (2) if that is general practice, but I was hoping
> there might be something else I can do that may be a simpler solution
> (as I have a lot of assembly code already in place -- I just recently
> put the ARM macros in its own package.
>

What you left out was what I would consider the most reasonable way,
namely to export the symbols in the ARM package and then use that
package in places where you want the ARM macros to appear. I imagine
that you already did something like this to get your macro to be found.

I think that gives you the cleanest solution.


--
Thomas A. Russ, USC/Information Sciences Institute

.



Relevant Pages

  • Re: flets in macros
    ... >> use a walker, and that's the best way to do what you are advocating. ... > not explicitly mentioned by the user of the macro. ... > from a package that I defined. ... can lead to an equally vehement qualitative judgement in the opposite ...
    (comp.lang.lisp)
  • Re: use-package & name conflict: why they are not deferred?
    ... allowing to intern a harmful symbol to any package at any time by just ... Kaz, I see you know lisp very well, but I'd recommended to spend some ... which is declared not to be intended by lexicons. ... decorated as misc variants of "with-gensyms" macro. ...
    (comp.lang.lisp)
  • Re: packages and symbols mystery
    ... Because it is is a macro, but I'm still learning macrology and that's ... Switching to another package ... Easy to use as no extra knowledge or configuration of Emacs necessary. ... - 2 key-strokes for quotes ...
    (comp.lang.lisp)
  • Re: flets in macros
    ... >> can use the same symbol both as a LOOP keyword and for your own ... not explicitly mentioned by the user of the macro. ... from a package that I defined. ... And if he uses a tree walker he has to explicitly decide which symbols ...
    (comp.lang.lisp)
  • Re: Macros and symbols across packages
    ... > Of course, when I use these macros from outside the ARM package, ... none of my symbols match those in the ARM package. ... Modify the instruction macro to always intern register symbols into ...
    (comp.lang.lisp)