Amazed by macros working on first attempt




Admittedly, macros so far have been 'with-' style macros that don't
take a lot of thought. But I just ran into a situation that led me to
try them in a new way, and I was amazed.

I wanted one package to have access to values from another, but I
didn't want to export/expose the variables. So, I decided to add
accessor functions and create a new 'interface.lisp' module.

I started out with this type of function:
(defun get-account-fwd (account-name)
(cond
((equalp account-name (name *account-1*))
(balance-fwd *account-1*))
((equalp account-name (name *account-2*))
(balance-fwd *account-2*))))

Then I realized I could try this:
(defmacro defaccgetter (fname sname)
`(defun ,fname (aname)
(cond
((equalp aname (name *account-1*))
(,sname *account-1*))
((equalp aname (name *account-2*))
(,sname *account-2*)))))

(defaccgetter get-account-fwd balancefwd)

and a few others like this one. I worked on the syntax to get it right
before I tried building and just confusing myself, and when I was
satisfied, I added all of these 'getters' to the package export list.
I was *stunned* when it compiled and ran *flawlessly*. No problem with
sequence of macro expansion, export of generated function names, or
anything. It was great.

One improvement I would like to make would be to use some kind of
iterating or looping form to go through all the slots of a specific
object and apply that macro to them and then export the result, so I
can add a new slot and have the cross-package-accessor function
automatically generated and even exported.

How might I approach this problem?

.



Relevant Pages

  • Re: Question about jumps
    ... I think some assemblers dump the symbol table with the listing file, which Nasm doesn't do... ... scale it down a good bit to make a "Linux NASM Beginner Kit" package. ... If "nasm64" ever appears, we'll want macros so ... mov rax, 1; maybe just eax? ...
    (alt.lang.asm)
  • GNU Autoconf 2.65 released [stable]
    ... The GNU Autoconf team is pleased to announce the stable release of ... configuration script for a package from a template file that lists the ... This release updates Autoconf to use GPLv3, along with a license exception ... those a stable part of the interface when using autoconf macros. ...
    (gnu.announce)
  • Re: aclocal and hello world
    ... >> macros used in configure.ac. ... > into the autoconf package where they more properly belong. ... > seems to be part of automake, ...
    (comp.unix.programmer)
  • Re: aclocal and hello world
    ... > macros used in configure.ac. ... I've read somewhere, in a recent autoconf manual I believe, ... into the autoconf package where they more properly belong. ... Anyways, it's good that aclocal is outputting those warnings, cause ...
    (comp.unix.programmer)
  • Autoconf 2.62 released
    ... The GNU Autoconf team is pleased to announce the release of stable ... configuration script for a package from a template file that lists the ... ** New Autoconf macros: ... ** Documentation for m4sugar is improved. ...
    (gnu.announce)