GNU bug report logs - #17634
"Unbound var" compilation error, lambda* & #:optional

Previous Next

Package: guile;

Reported by: Josep Portella Florit <jpf <at> primfilat.com>

Date: Thu, 29 May 2014 20:37: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 17634 in the body.
You can then email your comments to 17634 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#17634; Package guile. (Thu, 29 May 2014 20:37:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Josep Portella Florit <jpf <at> primfilat.com>:
New bug report received and forwarded. Copy sent to bug-guile <at> gnu.org. (Thu, 29 May 2014 20:37:02 GMT) Full text and rfc822 format available.

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

From: Josep Portella Florit <jpf <at> primfilat.com>
To: bug-guile <at> gnu.org
Subject: "Unbound var" compilation error, lambda* & #:optional
Date: Thu, 29 May 2014 22:36:08 +0200
Hi!

Please, see the attached REPL session.

Regards


scheme@(guile-user)> ((lambda* (a #:optional (b (+ a 1))) b) 1)
While compiling expression:
ERROR: unbound var a-492
scheme@(guile-user)> (define f (lambda* (a #:optional (b (+ a 1))) b))
scheme@(guile-user)> (f 1)
$2 = 2
scheme@(guile-user)> ((lambda* (a #:key (b (+ a 1))) b) 1)
$3 = 2

(Tested on Guile 2.0.11)




Information forwarded to bug-guile <at> gnu.org:
bug#17634; Package guile. (Fri, 30 May 2014 06:19:01 GMT) Full text and rfc822 format available.

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

From: Mark H Weaver <mhw <at> netris.org>
To: Josep Portella Florit <jpf <at> primfilat.com>
Cc: 17634 <at> debbugs.gnu.org
Subject: Re: bug#17634: "Unbound var" compilation error, lambda* & #:optional
Date: Fri, 30 May 2014 02:18:17 -0400
[Message part 1 (text/plain, inline)]
Josep Portella Florit <jpf <at> primfilat.com> writes:

> scheme@(guile-user)> ((lambda* (a #:optional (b (+ a 1))) b) 1)
> While compiling expression:
> ERROR: unbound var a-492
> scheme@(guile-user)> (define f (lambda* (a #:optional (b (+ a 1))) b))
> scheme@(guile-user)> (f 1)
> $2 = 2
> scheme@(guile-user)> ((lambda* (a #:key (b (+ a 1))) b) 1)
> $3 = 2
>
> (Tested on Guile 2.0.11)

The following preliminary patch should fix the problem.  I haven't yet
pushed it because I'd like to add some test cases, and have Andy or
Ludovic review the patch.

     Thanks!
       Mark


[0001-peval-Handle-optional-argument-inits-that-refer-to-p.patch (text/x-patch, inline)]
From 4d8002afa0ab851d9878c56c538dd2c8cbd7fc93 Mon Sep 17 00:00:00 2001
From: Mark H Weaver <mhw <at> netris.org>
Date: Fri, 30 May 2014 01:27:08 -0400
Subject: [PATCH] peval: Handle optional argument inits that refer to previous
 arguments.

Fixes <http://bugs.gnu.org/17634>.
Reported by Josep Portella Florit <jpf <at> primfilat.com>.

* module/language/tree-il/peval.scm (inlined-application): When inlining
  an application whose operator is a lambda expression with optional
  arguments that rely on default initializers, expand into a series of
  nested let expressions, to ensure that previous arguments are in scope
  when the default initializers are evaluated.
---
 module/language/tree-il/peval.scm | 51 +++++++++++++++++++++++++++++----------
 1 file changed, 38 insertions(+), 13 deletions(-)

diff --git a/module/language/tree-il/peval.scm b/module/language/tree-il/peval.scm
index bd92edc..04563d6 100644
--- a/module/language/tree-il/peval.scm
+++ b/module/language/tree-il/peval.scm
@@ -1313,24 +1313,49 @@ top-level bindings from ENV and return the resulting expression."
                    (nopt (if opt (length opt) 0))
                    (key (source-expression proc)))
               (define (inlined-application)
-                (make-let src
-                          (append req
-                                  (or opt '())
-                                  (if rest (list rest) '()))
-                          gensyms
-                          (if (> nargs (+ nreq nopt))
-                              (append (list-head orig-args (+ nreq nopt))
+                (if (> nargs (+ nreq nopt))
+                    (make-let src
+                              (append req
+                                      (or opt '())
+                                      (list rest))
+                              gensyms
+                              (append (take orig-args (+ nreq nopt))
                                       (list
                                        (make-application
                                         #f
                                         (make-primitive-ref #f 'list)
                                         (drop orig-args (+ nreq nopt)))))
-                              (append orig-args
-                                      (drop inits (- nargs nreq))
-                                      (if rest
-                                          (list (make-const #f '()))
-                                          '())))
-                          body))
+                              body)
+                    (let*-values
+                        (((non-rest-gensyms rest-gensyms)
+                          (split-at gensyms (+ nreq nopt)))
+                         ((provided-gensyms default-gensyms)
+                          (split-at non-rest-gensyms nargs))
+                         ((provided-vars default-vars)
+                          (split-at (append req (or opt '()))
+                                    nargs))
+                         ((rest-vars)
+                          (if rest (list rest) '()))
+                         ((rest-inits)
+                          (if rest
+                              (list (make-const #f '()))
+                              '()))
+                         ((default-inits)
+                          (drop inits (- nargs nreq))))
+                      (make-let src
+                                (append provided-vars rest-vars)
+                                (append provided-gensyms rest-gensyms)
+                                (append orig-args rest-inits)
+                                (fold-right (lambda (var gensym init body)
+                                              (make-let src
+                                                        (list var)
+                                                        (list gensym)
+                                                        (list init)
+                                                        body))
+                                            body
+                                            default-vars
+                                            default-gensyms
+                                            default-inits)))))
 
               (cond
                ((or (< nargs nreq) (and (not rest) (> nargs (+ nreq nopt))))
-- 
1.8.4


Reply sent to Mark H Weaver <mhw <at> netris.org>:
You have taken responsibility. (Mon, 29 Sep 2014 04:03:01 GMT) Full text and rfc822 format available.

Notification sent to Josep Portella Florit <jpf <at> primfilat.com>:
bug acknowledged by developer. (Mon, 29 Sep 2014 04:03:02 GMT) Full text and rfc822 format available.

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

From: Mark H Weaver <mhw <at> netris.org>
To: Josep Portella Florit <jpf <at> primfilat.com>
Cc: 17634-done <at> debbugs.gnu.org
Subject: Re: bug#17634: "Unbound var" compilation error, lambda* & #:optional
Date: Mon, 29 Sep 2014 00:02:09 -0400
Josep Portella Florit <jpf <at> primfilat.com> writes:

> scheme@(guile-user)> ((lambda* (a #:optional (b (+ a 1))) b) 1)
> While compiling expression:
> ERROR: unbound var a-492
> scheme@(guile-user)> (define f (lambda* (a #:optional (b (+ a 1))) b))
> scheme@(guile-user)> (f 1)
> $2 = 2
> scheme@(guile-user)> ((lambda* (a #:key (b (+ a 1))) b) 1)
> $3 = 2

Fixed in 7a71a45cfd6092402d540e9bc5d2432941a8a336 on the stable-2.0
branch.  I'm closing this bug.

    Thanks!
      Mark




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

This bug report was last modified 9 years and 183 days ago.

Previous Next


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