[plt-scheme] newbie define-syntax questions
On Fri, 13 Apr 2007, Yin-So Chen wrote:
> Hi all -
>
> I have a couple of related questions about define-syntax - basically I am
> wondering how some language facilities such as struct or classes are done as
> macros:
>
> 1. 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
> 2. 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?
If you are trying to make a define-struct like macro with standard
naming conventions, check generate-struct-declaration (lives in struct.ss
of the syntax collection).
For more general, arbitrary symbol injections, syntax-object->datum and
dautm->syntax-object are your friends.
Break down the syntax with syntax-case, ->datum, manipulate to make
your identifiers, ->syntax.
To put the result of function calls in the transformer environment back
into generated syntax, use quasisyntax/unsyntax/unsyntax-splicing (#` #,
#,@)
-- vyzo