[plt-scheme] newbie define-syntax questions

From: Yin-So Chen (yinso.chen at gmail.com)
Date: Mon Apr 16 01:26:24 EDT 2007

Hi Vyzo, Carl, and Grant -

after struggling with this some more, I was finally able to create a macro
with multiple definitions.  Below are my take-aways:

   - use with-syntax over let: let allows me to create my own symbol
   transformations in a function - with-syntax allows the same in a macro
   - symbol != syntax-object: at first my transform function returns a
   symbol and I couldn't create a definition - it doesn't work until I figure
   out I need a syntax-object and how to use datum->syntax-object to do
   so
   - The way to manipulate symbol is still through string-append - this
   means I need to convert the type from syntax-object -> symbol -> string ->
   symbol -> syntax-object... seems quite a bit of work ;)
   - use define-for-syntax rather than define to abstract the
   transformation
   - syntax-case affords more control... syntax-rules use might be
   limited

My head still hurts but I definitely learned something here - again thanks
for the help! ;)

yinso



On 4/13/07, Dimitris Vyzovitis <vyzo at media.mit.edu> wrote:
>
> 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
>
>


-- 
http://www.yinsochen.com
...continuous learning...
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20070415/b335e46a/attachment.html>

Posted on the users mailing list.