unofficial mirror of bug-guile@gnu.org 
 help / color / mirror / Atom feed
* bug#14859: my-or macro in documentation
@ 2013-07-13 18:52 Josep Portella Florit
  2013-07-14  0:41 ` Mark H Weaver
  0 siblings, 1 reply; 2+ messages in thread
From: Josep Portella Florit @ 2013-07-13 18:52 UTC (permalink / raw)
  To: 14859

Hi!

The my-or example macro in the documentation has a subtle bug.

          (letrec-syntax ((my-or
                           (syntax-rules ()
                             ((my-or)
                              #t)
                             ((my-or exp)
                              exp)
                             ((my-or exp rest ...)
                              (let ((t exp))
                                (if exp
                                    exp
                                    (my-or rest ...)))))))
            (my-or #f "rockaway beach"))

In the third rule t is bound to exp, presumably to use t instead of exp
to prevent evaluating exp multiple times, but t is never used and exp is
used again.  This is the bug in action:

scheme@(guile-user)> (letrec-syntax ((my-or
                           (syntax-rules ()
                             ((my-or)
                              #t)
                             ((my-or exp)
                              exp)
                             ((my-or exp rest ...)
                              (let ((t exp))
                                (if exp
                                    exp
                                    (my-or rest ...)))))))
            (my-or (display "*") 1))
***scheme@(guile-user)>

I'm sure you already know how to fix it :-)

          (letrec-syntax ((my-or
                           (syntax-rules ()
                             ((my-or)
                              #t)
                             ((my-or exp)
                              exp)
                             ((my-or exp rest ...)
                              (let ((t exp))
                                (if t
                                    t
                                    (my-or rest ...)))))))
            (my-or #f "rockaway beach"))

Josep





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

end of thread, other threads:[~2013-07-14  0:41 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-07-13 18:52 bug#14859: my-or macro in documentation Josep Portella Florit
2013-07-14  0:41 ` Mark H Weaver

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