[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Need help to understand a macro
From: |
Josef Wolf |
Subject: |
Re: Need help to understand a macro |
Date: |
Mon, 22 Mar 2010 22:06:07 +0100 |
User-agent: |
Mutt/1.5.20 (2009-06-14) |
On Sat, Mar 20, 2010 at 03:13:45PM +0100, szgyg wrote:
> Josef Wolf wrote:
> >I am trying to understand the defstruct macro from the "teach yourself
> >scheme in fixnum days" tutorial, which can be found in chapter 9 at
> >http://www.ccs.neu.edu/home/dorai/t-y-scheme/t-y-scheme-Z-H-11.html#node_chap_9
> >
> >My first question is of a more generic type. For a better understanding
> >how macros work, I'd like to have a way to show what expansion a macro
> >would generate when it would be used. E.g., I'd like to do something
> >like
> >
> > (show-expansion (defstruct tree height girth age leaf-shape leaf-color))
> >
> >and get what the expansion of this macro would produce:
> >
> > (begin
> > (define make-tree
> > (lambda fvfv
> > [ ... and so on ... ]
>
> Use the trick from the inexplicable JRM's Syntax-rules Primer for
> the Merely Eccentric[1], wrap the output with quote:
>
> ...
> (let ((ff (map (lambda (f) (if (pair? f) (car f) f))
> ff)))
> `'(begin
> ; ^
> (define ,(string->symbol
> (string-append "make-" s-s))
> ...
Ah, sounds reasonable. Thanks!
> [1]
> http://www.xs4all.nl/~hipster/lib/scheme/gauche/define-syntax-primer.txt
I will save this link for later, since this stuff is still too advanced for
me. In the meantime, I'll be looking for something that's more entry-level...
- Re: Need help to understand a macro, (continued)
Re: Need help to understand a macro, szgyg, 2010/03/20
- Re: Need help to understand a macro,
Josef Wolf <=