fix curried definitions for value defines
authorAndy Wingo <wingo@pobox.com>
Thu, 8 Apr 2010 19:01:52 +0000 (21:01 +0200)
committerAndy Wingo <wingo@pobox.com>
Thu, 8 Apr 2010 19:01:52 +0000 (21:01 +0200)
* module/ice-9/curried-definitions.scm: Allow definitions of values with
  define and define*.
* test-suite/tests/curried-definitions.test: Add tests.

module/ice-9/curried-definitions.scm
test-suite/tests/curried-definitions.test

index d7db1f0..d55f1fb 100644 (file)
@@ -25,7 +25,9 @@
        (lambda rest body body* ...)))
     ((_ (head . rest) body body* ...)
      (define head
-       (lambda rest body body* ...)))))
+       (lambda rest body body* ...)))
+    ((_ . rest)
+     (define . rest))))
 
 (define-syntax cdefine*
   (syntax-rules ()
@@ -34,4 +36,6 @@
        (lambda* rest body body* ...)))
     ((_ (head . rest) body body* ...)
      (define* head
-       (lambda* rest body body* ...)))))
+       (lambda* rest body body* ...)))
+    ((_ . rest)
+     (define* . rest))))
index 650288f..b4a1f65 100644 (file)
             (primitive-eval '(let ()
                                (define (((foo)) x)
                                  (+ x 34))
-                               (((foo)) 300))))))
+                               (((foo)) 300)))))
+
+  (pass-if "just a value"
+    (equal? 444
+            (primitive-eval '(let ()
+                               (define foo 444)
+                               foo)))))
+
+(with-test-prefix "define*"
+  (pass-if "define* works as usual"
+    (equal? 34
+            (primitive-eval '(let ()
+                               (define* (foo)
+                                 34)
+                               (foo)))))
+  (pass-if "define* works as usual (2)"
+    (equal? 134
+            (primitive-eval '(let ()
+                               (define* (foo x)
+                                 (+ x 34))
+                               (foo 100)))))
+  (pass-if "currying once"
+    (equal? 234
+            (primitive-eval '(let ()
+                               (define* ((foo) x)
+                                 (+ x 34))
+                               ((foo) 200)))))
+  (pass-if "currying twice"
+    (equal? 334
+            (primitive-eval '(let ()
+                               (define* (((foo)) x)
+                                 (+ x 34))
+                               (((foo)) 300)))))
+
+  (pass-if "just a value"
+    (equal? 444
+            (primitive-eval '(let ()
+                               (define* foo 444)
+                               foo)))))