GNU bug report logs - #38263
Bug in srfi-11 (?)

Previous Next

Package: guile;

Reported by: Tim Gesthuizen <tim.gesthuizen <at> yahoo.de>

Date: Mon, 18 Nov 2019 20:02:02 UTC

Severity: normal

Done: Andy Wingo <wingo <at> pobox.com>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: help-debbugs <at> gnu.org (GNU bug Tracking System)
To: Tim Gesthuizen <tim.gesthuizen <at> yahoo.de>
Subject: bug#38263: closed (Re: bug#38263: Bug in srfi-11)
Date: Sun, 12 Jan 2020 21:24:03 +0000
[Message part 1 (text/plain, inline)]
Your bug report

#38263: Bug in srfi-11 (?)

which was filed against the guile package, has been closed.

The explanation is attached below, along with your original report.
If you require more details, please reply to 38263 <at> debbugs.gnu.org.

-- 
38263: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=38263
GNU Bug Tracking System
Contact help-debbugs <at> gnu.org with problems
[Message part 2 (message/rfc822, inline)]
From: Andy Wingo <wingo <at> pobox.com>
To: Tim Gesthuizen via "Bug reports for GUILE\,
 GNU's Ubiquitous Extension Language" <bug-guile <at> gnu.org>
Cc: Mark H Weaver <mhw <at> netris.org>, 38263-done <at> debbugs.gnu.org
Subject: Re: bug#38263: Bug in srfi-11
Date: Sun, 12 Jan 2020 22:23:21 +0100
Applied to both branches.  Thanks for the patch and thanks also to Mark
for the review and initial patch!

In the future, Tim, if you have larger patches, we should work out
copyright assignment paperwork.  But less-than-10-line patches are fine
without.  Let me know if this is of interest to you.  Cheers :)

Andy

On Tue 03 Dec 2019 19:15, Tim Gesthuizen via "Bug reports for GUILE, GNU's Ubiquitous Extension Language" <bug-guile <at> gnu.org> writes:

> Hello again,
>
> the attached patch also adds a unit test.
> I am not into how Guile is organized: Is there anything keeping us from
> adding the change?
>
> Tim.
>
> From 99d8fb795932eb92b7d5fb09115b6691f4bfe66d Mon Sep 17 00:00:00 2001
> From: Tim Gesthuizen <tim.gesthuizen <at> yahoo.de>
> Date: Tue, 3 Dec 2019 18:50:37 +0100
> Subject: [PATCH] srfi-11: Do not expose variables to later clauses
>
> The current implementation of srfi-11s let-values allows later clauses
> to access and modify variables bound in earlier clauses when the clause
> is not a proper list.
>
> * module/srfi/srfi-11.scm (let-values): Fix switched variable names.
> * test-suite/tests/srfi-11.test (let-values): Add test checking that the
>   variable cannot be changed in later clauses.
> ---
>  module/srfi/srfi-11.scm       | 2 +-
>  test-suite/tests/srfi-11.test | 9 ++++++++-
>  2 files changed, 9 insertions(+), 2 deletions(-)
>
> diff --git a/module/srfi/srfi-11.scm b/module/srfi/srfi-11.scm
> index 22bda21a2..7afac9c5f 100644
> --- a/module/srfi/srfi-11.scm
> +++ b/module/srfi/srfi-11.scm
> @@ -91,7 +91,7 @@
>                      (syntax (call-with-values (lambda () exp)
>                                (lambda (new-tmp ...) inner))))))
>                 ((vars exp)
> -                (with-syntax ((((new-tmp . new-var) ...)
> +                (with-syntax ((((new-var . new-tmp) ...)
>                                 (let lp ((vars (syntax vars)))
>                                   (syntax-case vars ()
>                                     ((id . rest)
> diff --git a/test-suite/tests/srfi-11.test b/test-suite/tests/srfi-11.test
> index 40563dc18..9bfaa4300 100644
> --- a/test-suite/tests/srfi-11.test
> +++ b/test-suite/tests/srfi-11.test
> @@ -74,7 +74,14 @@
>  	'(unbound-variable . ".*")
>        (let-values (((x) (values 1))
>  		   ((y) (values (1+ x))))
> -	#f))))
> +	#f))
> +
> +    (pass-if "first binding with rest invisible to second expr"
> +      (let* ((a 1)
> +             (b (let-values (((a . b) (values 2 3))
> +                             (c (begin (set! a 9) 4)))
> +                  (list a b c))))
> +        (equal? (cons a b) '(9 2 (3) (4)))))))
>  
>  ;;
>  ;; let*-values

[Message part 3 (message/rfc822, inline)]
From: Tim Gesthuizen <tim.gesthuizen <at> yahoo.de>
To: bug-guile <at> gnu.org
Subject: Bug in srfi-11 (?)
Date: Mon, 18 Nov 2019 21:01:17 +0100
Hi,
I was tinkering with srfi-11 and was wondering whether the following
is correct:

> scheme@(guile-user)> ,expand (let-values (((a b c) (values 1 2 3))
> 				  ((d . e) (values 4 5)))
> 		       (list a b c d e))
> $26 = ((@@ (srfi srfi-11) call-with-values)
>  (lambda () (values 1 2 3))
>  (lambda (t-1dff1b83541ce327-16e
>           t-1dff1b83541ce327-16f
>           t-1dff1b83541ce327-170)
>    ((@@ (srfi srfi-11) call-with-values)
>     (lambda () (values 4 5))
>     (lambda (d . e)
>       (let ((t-1dff1b83541ce327-171 d)
>             (t-1dff1b83541ce327-172 e)
>             (a t-1dff1b83541ce327-16e)
>             (b t-1dff1b83541ce327-16f)
>             (c t-1dff1b83541ce327-170))
>         (list a b c d e))))))

This differs from what the comment above the macro definition claims
to expand to.
It seems like the author forgot that he matched the temporaries before
the variables in srfi-11.scm:94.

> diff --git a/module/srfi/srfi-11.scm b/module/srfi/srfi-11.scm
> index 22bda21a2..13a2ffc4d 100644
> --- a/module/srfi/srfi-11.scm
> +++ b/module/srfi/srfi-11.scm
> @@ -95,13 +95,13 @@
>                                 (let lp ((vars (syntax vars)))
>                                   (syntax-case vars ()
>                                     ((id . rest)
> -                                    (acons (syntax id)
> -                                           (car
> +                                    (acons (car
>                                              (generate-temporaries (syntax (id))))
> +                                           (syntax id)
>                                             (lp (syntax rest))))
> -                                   (id (acons (syntax id)
> -                                              (car
> +                                   (id (acons (car
>                                                 (generate-temporaries (syntax (id))))
> +                                              (syntax id)
>                                                '())))))
>                                ((id ...) ids)
>                                ((tmp ...) tmps))

The code "works" anyhow because the lambdas are all nested and the
inner ones capture the parameters of the outer ones.
Which got me thinking why all the messing with temporaries is
neccessary at all. Why is

> (define-syntax let-values
>   (lambda (x)
>     (syntax-case x ()
>       ((_ (clauses ...) b0 b1 ...)
>        (let lp ((clauses #'(clauses ...)))
> 	 (if (null? clauses)
> 	     #'(begin b0 b1 ...)
> 	     (syntax-case (car clauses) ()
> 	       ((args exp)
> 		(with-syntax ((inner (lp (cdr clauses))))
> 		  #'(call-with-values (lambda () exp)
> 		      (lambda args inner)))))))))))

not sufficient? I would not consider my self a Scheme expert and it
could be that I just missed something.
It would be nice if someone could verify whether this is a bug or not.
I am using Guile 2.2.6 on Guix.

Tim.



This bug report was last modified 5 years and 133 days ago.

Previous Next


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