[plt-scheme] Help with understanding how to reuse macro data
On Fri, Jan 2, 2009 at 4:25 PM, Grant Rettke <grettke at acm.org> wrote:
>
> My lurking question is one of Scheme style. Since I am not interested
> in evaluating code from "somewhere else", and I am really just
> interested in utilizing the data to generate some code based on "what
> is says", it doesn't seem like an abuse of the macro system. I just
> want to take some symbols and generate code differently based on what
> I see.
>
> Does the fact that I'm taking this data and compiling it down to
> something trivial disqualify it? What if it were being compiled into a
> compelling "thing" written in Scheme?
Here's the logic behind my opinion. In your example, you are manipulating
`means to open safes'. You have primitives like `try this combination' and
`ask Vinnie', and means of combination like `first try primitive1, then try
primitive2'. Now, given several primitives and some combinators, you want
to reason about strategy. It seems to me that your primitives and combinators
should be first-class objects. You want to bind them to variables, make lists
of them, put them together and take them apart, etc.
Macros, however, aren't designed for this sort of thing. A macro
isn't a first-class
object. You are using the macro only to parse the list representation
of *one* of
the primitive means to open a safe. A parsing library would get you
further, and
you wouldn't be limited by requiring that the list representation
appear as a literal
in the code.
> I see now, there is a clear delineation: once scenario is parsing data
> differently (with different functions or classes) and another is
> generating code differently based on the input. The problem I am
> trying to solve is the former, macros don't make sense.
>
> That said, if they did make sense, how would one go about reusing that
> data definition?
I have seen *very* few cases where this would make sense, but I think
what you would want to do is write meta-macros that wrap the macros
with a let-syntax form that does the base macro processing. It'd be one
of those hairballs that Al* Petrofsky is so fond of.
--
~jrm