guile-user
[Top][All Lists]
Advanced

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

Need help to understand a macro


From: Josef Wolf
Subject: Need help to understand a macro
Date: Fri, 19 Mar 2010 09:57:01 +0100
User-agent: Mutt/1.5.20 (2009-06-14)

Hello,

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

Of course this is possible. After all, code is data and data is code.

My next question is more related to the defstruct macro.
In line 11, defstruct stores the default initializers into the vv vector:

   (if (pair? f) (cadr f) '(if #f #f)))

So if the field is a pair, the initializer is stored in vv. That's easy.
But if it is not a pair, '(if #f #f) is stored. What is this good for?
This 'if' would evaluate the 'else' part, which does not exist. So we
would get #f as a result. So why not storing #f in the first place? Why
is not

   (if (pair? f) (cadr f) #f))

used here?




reply via email to

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