[plt-scheme] newbie define-syntax questions
On 4/13/07, Yin-So Chen <yinso.chen at gmail.com> wrote:
>
> how can define-syntax create multiple forms/definitions - I found the entry
> on http://community.schemewiki.org/?scheme-faq-macros but
> unable to extrapolate from there to creating of something similar to a
> define-struct
There's a number of ways. A macro can expand into define-values,
which is one "definition" with multiple bindings, or it can expand
into (begin DEFN1 DEFN2 ...); the begin form is special in that it can
be used to group together definitions as well as expressions.
> how to generate names based on the struct/class name into the definitions -
> seems like there needs to be ways of inserting results of a function call
> into define-syntax?
Yes, in fact any Scheme expression can go in the body of
define-syntax, certainly including function calls. Most macros are
defined using syntax-case, which helps the macro programmer break down
input syntax and then use any Scheme code to build up the result
syntax.
> I tried to read the source code of class & struct but my head exploded
> without learning much... would appreciate some pointers/links... ;)
The class and define-struct macros are definitely not "beginner
macros", so don't be discouraged if they make your head spin. I think
they make all our head spin. ;)
I don't have a link to easier macros off the top of my head, I'll have
to defer that answer to someone else.
By the way, define-struct is a macro, but at its core it uses
make-struct-type which is just a function. It's a complicated
function, though. Looking it up in Help Desk may or may not be
illuminating.
I hope that helps a little, good luck exploring macros!
--
Carl Eastlund