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

The point is not that it's bad, it's that the symbols are interned by
the _reader_!

> 2. Create a reader character macro that will change which package I'm
> in for the rest of the read:
>
> { (addne r0 r0 r1 :lsl 4) }

Or you could just write: (in-package "ARM")
or just (use-package "ARM"), having taken care of exporting these symbols.


> 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.


You could write:

(use-package "ARM") (addne r0 r0 r1 :lsl 4)

or: (arm:addne arm:r0 arm:r0 arm:r1 :lsl 4)

or: (arm:addne :r0 :r0 :r1 :lsl 4)

or: (arm:addne "r0" "r0" "r1" :lsl 4)

or, now that you're ready to use STRING-EQUAL instead of EQL,

(addne mypackage::r0 the-other-package::r0 :r1 :lsl 4)


(and (string-equal 'r1 :r1) (string-equal 'p1::r1 'p2::r1))


--
__Pascal Bourguignon__ http://www.informatimago.com/
Our enemies are innovative and resourceful, and so are we. They never
stop thinking about new ways to harm our country and our people, and
neither do we. -- Georges W. Bush
.



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: 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: 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: 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 ... > (as I have a lot of assembly code already in place -- I just recently ...
    (comp.lang.lisp)
  • Re: Lisp mistakes in Python
    ... So if you are okay with generic function, ... Sometime macro is too easy to ... I may add Package issue in Common Lisp. ... Being able to calculate things at compile time is a neat trick but, ...
    (comp.lang.lisp)