Opened 13 years ago

Closed 13 years ago

Last modified 12 years ago

#805 closed defect (fixed)

case-lambda is unhygienic

Reported by: Moritz Heidkamp Owned by: Christian Kellermann
Priority: minor Milestone: 4.9.0
Component: core libraries Version: 4.7.x
Keywords: Cc:
Estimated difficulty:

Description

case-lambda unhygienically expands to length. To wit:

#;1> (module foo (foo) (import (only scheme quote) (prefix chicken c/) (prefix scheme s/)) (s/define foo (c/case-lambda ((a) a) ((a b) b))))

Warning: reference to possibly unbound identifier `length' in:
Warning:    foo

Error: module unresolved: foo

I tried the following fix but it doesn't seem to change a thing:

diff --git a/chicken-syntax.scm b/chicken-syntax.scm
index 08bede2..a6c70d4 100644
--- a/chicken-syntax.scm
+++ b/chicken-syntax.scm
@@ -785,11 +785,12 @@
 	   (%>= (r '>=))
 	   (%eq? (r 'eq?))
 	   (%car (r 'car))
-	   (%cdr (r 'cdr)))
+	   (%cdr (r 'cdr))
+	   (%length (r 'length)))
       `(##core#lambda
 	,(append minvars rvar)
 	(##core#let
-	 ((,lvar (length ,rvar)))
+	 ((,lvar (,%length ,rvar)))
 	 ,(fold-right
 	   (lambda (c body)
 	     (##sys#decompose-lambda-list

Does anyone know what's going on?

Change History (4)

comment:1 Changed 13 years ago by Christian Kellermann

Owner: set to Christian Kellermann
Status: newaccepted

Does the following patch solve the issue for you?

diff --git a/chicken-syntax.scm b/chicken-syntax.scm
index 08bede2..c92e0f3 100644
--- a/chicken-syntax.scm
+++ b/chicken-syntax.scm
@@ -764,7 +764,8 @@
  `((>= . ,(##sys#primitive-alias '>=))
    (car . ,(##sys#primitive-alias 'car))
    (cdr . ,(##sys#primitive-alias 'cdr))
-   (eq? . ,(##sys#primitive-alias 'eq?)))
+   (eq? . ,(##sys#primitive-alias 'eq?))
+   (length . ,(##sys#primitive-alias 'length)))
  (##sys#er-transformer
   (lambda (form r c)
     (##sys#check-syntax 'case-lambda form '(_ . _))
@@ -785,11 +786,12 @@
           (%>= (r '>=))
           (%eq? (r 'eq?))
           (%car (r 'car))
-          (%cdr (r 'cdr)))
+          (%cdr (r 'cdr))
+           (%length (r 'length)))
       `(##core#lambda
        ,(append minvars rvar)
        (##core#let
-        ((,lvar (length ,rvar)))
+        ((,lvar (,%length ,rvar)))
         ,(fold-right
           (lambda (c body)
             (##sys#decompose-lambda-list

comment:2 Changed 13 years ago by Moritz Heidkamp

Ah, so that's what I was overlooking. Works brillantly now. Can you create a format-patch version of this fix for me to sign it off? Thanks!

comment:3 Changed 13 years ago by Moritz Heidkamp

Resolution: fixed
Status: acceptedclosed

comment:4 Changed 12 years ago by felix winkelmann

Milestone: 4.8.04.9.0

Milestone 4.8.0 deleted

Note: See TracTickets for help on using tickets.