GNU bug report logs - #14203
Manual: 'my-or'; 'let' inside macros

Previous Next

Package: guile;

Reported by: Nikita Karetnikov <nikita <at> karetnikov.org>

Date: Sun, 14 Apr 2013 16:35:02 UTC

Severity: normal

Done: Mark H Weaver <mhw <at> netris.org>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 14203 in the body.
You can then email your comments to 14203 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-guile <at> gnu.org:
bug#14203; Package guile. (Sun, 14 Apr 2013 16:35:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Nikita Karetnikov <nikita <at> karetnikov.org>:
New bug report received and forwarded. Copy sent to bug-guile <at> gnu.org. (Sun, 14 Apr 2013 16:35:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Nikita Karetnikov <nikita <at> karetnikov.org>
To: bug-guile <at> gnu.org
Subject: Manual: 'my-or'; 'let' inside macros
Date: Sun, 14 Apr 2013 20:33:12 +0400
[Message part 1 (text/plain, inline)]
I think this example [1,2]:

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

should look like this:

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

Otherwise, what's the rationale behind 'let'?

AFAICT, it's described here [3], but Guile is not affected, right?  So
the following works as well:

(define-syntax my-or
  (syntax-rules ()
    ((my-or)
     #t)
    ((my-or exp)
     exp)
    ((my-or exp rest ...)
     (if exp
         exp
         (my-or rest ...)))))

Note that 'my-or' is used in several places (e.g., [4]) and it's
necessary to change them all.  Also, there are other macros that use
'let' (e.g., 'cond1').

[1] https://gnu.org/software/guile/manual/guile.html#Defining-Macros
[2] https://gnu.org/software/guile/manual/guile.html#Hygiene
[3] http://stackoverflow.com/a/3215238
[4] https://gnu.org/software/guile/manual/guile.html#Syntax-Case
[Message part 2 (application/pgp-signature, inline)]

Reply sent to Mark H Weaver <mhw <at> netris.org>:
You have taken responsibility. (Sun, 14 Apr 2013 17:59:02 GMT) Full text and rfc822 format available.

Notification sent to Nikita Karetnikov <nikita <at> karetnikov.org>:
bug acknowledged by developer. (Sun, 14 Apr 2013 17:59:02 GMT) Full text and rfc822 format available.

Message #10 received at 14203-done <at> debbugs.gnu.org (full text, mbox):

From: Mark H Weaver <mhw <at> netris.org>
To: Nikita Karetnikov <nikita <at> karetnikov.org>
Cc: 14203-done <at> debbugs.gnu.org
Subject: Re: bug#14203: Manual: 'my-or'; 'let' inside macros
Date: Sun, 14 Apr 2013 13:53:38 -0400
Nikita Karetnikov <nikita <at> karetnikov.org> writes:

> I think this example [1,2]:
>
> (define-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 ...))))))
>
> should look like this:
>
> (define-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 ...))))))

Indeed, thanks!  I've pushed this fix to the stable-2.0 branch, and am
closing this bug.

Answers to your other questions follow.

> AFAICT, it's described here [3], but Guile is not affected, right?
> [3] http://stackoverflow.com/a/3215238

That post gives an example that looks superficially similar, but is
actually entirely different:

  (define remove!
    (let ((null? null?)
          (cdr cdr)
          (eq? eq?))
      (lambda ... function that uses null?, cdr, eq? ...)

Indeed, this is not necessary in Guile due to its module system.

> So the following works as well:
>
> (define-syntax my-or
>   (syntax-rules ()
>     ((my-or)
>      #t)
>     ((my-or exp)
>      exp)
>     ((my-or exp rest ...)
>      (if exp
>          exp
>          (my-or rest ...)))))

The above definition has a problem: it would result in 'exp' being
evaluated more than once, unless it returns false.

For example, if you used your proposed definition above,
(my-or (read) 5) would expand to:

  (if (read)
      (read)
      5)

Which would obviously not do what you expect from 'or'.  Instead, we
want:

  (let ((t (read)))
    (if t
        t
        5))

> Note that 'my-or' is used in several places (e.g., [4]) and it's
> necessary to change them all.
> [4] https://gnu.org/software/guile/manual/guile.html#Syntax-Case

Unless I'm mistaken, the Syntax-case section uses 'my-or', but does not
define it, so I don't think anything needs to be fixed there.  Right?

     Thanks,
       Mark




bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Mon, 13 May 2013 11:24:03 GMT) Full text and rfc822 format available.

This bug report was last modified 10 years and 351 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.