unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
* Need help to understand a macro
@ 2010-03-19  8:57 Josef Wolf
  2010-03-19 12:54 ` Ken Raeburn
                   ` (2 more replies)
  0 siblings, 3 replies; 15+ messages in thread
From: Josef Wolf @ 2010-03-19  8:57 UTC (permalink / raw)
  To: guile-user

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?




^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2010-03-23  0:50 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-03-19  8:57 Need help to understand a macro Josef Wolf
2010-03-19 12:54 ` Ken Raeburn
2010-03-22 19:25   ` Josef Wolf
2010-03-22 20:16     ` Andy Wingo
2010-03-22 20:54       ` Josef Wolf
2010-03-19 14:28 ` Andy Wingo
2010-03-19 16:15   ` Andreas Rottmann
2010-03-22 19:55     ` Josef Wolf
2010-03-22 21:50       ` Andreas Rottmann
2010-03-22 19:50   ` Josef Wolf
2010-03-22 20:36     ` Andy Wingo
2010-03-22 21:01       ` Josef Wolf
2010-03-23  0:50         ` Neil Jerram
2010-03-20 14:13 ` szgyg
2010-03-22 21:06   ` Josef Wolf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).