[plt-scheme] Help with understanding how to reuse macro data
On Fri, Jan 2, 2009 at 4:18 PM, Joe Marshall <jmarshall at alum.mit.edu> wrote:
> On Fri, Jan 2, 2009 at 2:10 PM, Grant Rettke <grettke at acm.org> wrote:
>>
>> This seems ok because the data specification is static. I only thought
>> about this just now, so I didn't dig any deeper yet. Is this a
>> reasonable approach? If so, what is the best way to approach it?
>>
>> What is the right/idiomatic solution here? Or is this bad idea?
>
> Just my 2 cents.
>
> Use a function rather than a macro.
>
> Macros are a great tool for syntactic abstraction, but you aren't
> doing that.
The last time I tried something like this, I ended up using the match
library to destructure the data and delegated the work to different
classes that implemented the same interface. It worked out fine, but I
am starting to think that I could have implemented it in a more easily
maintained manner. I also wonder what my solution would have looked
like if I had stuck with the now availabe R6RS and not used an object
system at all. I suspect that structures would have made my approach
easier to maintain.
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?
Your point makes sense. It can be a standard approach; macros are for
syntactic abstraction, period.
The confusing part here is that if I am using that data to to control
how something is generated with a macro in Scheme, it is not syntactic
abstraction, but, it doesn't seem like an abuse of the macro system
either.
I recently reread Shriram's "Automata via Macros", and was thinking
about this sort of a scenario and how one might deal with the same
specification being used to generate different types of code. I think
that is the key, it is not about parsing data, it is about generating
code differently based on the input data.
I believe I am closer to asking the right question than I did to start
with, because that is not the question that I asked in the original
post.
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?