guile-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Need help to understand a macro


From: szgyg
Subject: Re: Need help to understand a macro
Date: Sat, 20 Mar 2010 15:13:45 +0100
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; hu; rv:1.9.1.8) Gecko/20100227 Lightning/1.0b1 Thunderbird/2.0 ThunderBrowse/3.2.8.1

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))
...


[1]
http://www.xs4all.nl/~hipster/lib/scheme/gauche/define-syntax-primer.txt




reply via email to

[Prev in Thread] Current Thread [Next in Thread]