summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArun Isaac2021-07-20 16:58:48 +0530
committerArun Isaac2021-07-20 16:58:48 +0530
commitcdedc54e7c51755103d78014e8a8773d82110c63 (patch)
treee4e53789892a34e5d70f7ae242b8743e51c3b21e
parent54d5ce4ecdc414c74afd3cf2b37fbebb82c3cc81 (diff)
downloadccwl-cdedc54e7c51755103d78014e8a8773d82110c63.tar.gz
ccwl-cdedc54e7c51755103d78014e8a8773d82110c63.tar.lz
ccwl-cdedc54e7c51755103d78014e8a8773d82110c63.zip
ccwl: Set default value of lambda** n-ary arguments to '().
* ccwl/utils.scm (lambda**): Set default value of lambda** n-ary arguments to the empty list. Document this in the docstring. * tests/utils.scm ("default value of lambda** unary argument should be #f", "default value of lambda** n-ary argument should be the empty list"): New tests.
-rw-r--r--ccwl/utils.scm11
-rw-r--r--tests/utils.scm10
2 files changed, 16 insertions, 5 deletions
diff --git a/ccwl/utils.scm b/ccwl/utils.scm
index c018237..14a3c4d 100644
--- a/ccwl/utils.scm
+++ b/ccwl/utils.scm
@@ -138,12 +138,13 @@ for example, be invoked as:
=> (1 2 123 (1 2 3))
lambda** also supports default values for both unary and n-ary keyword
-arguments. For example,
+arguments. Note that the default value for unary arguments is #f,
+while that for n-ary arguments is the empty list. For example,
-((lambda** (foo aal #:key vale (pal 9) #:key* naal (irandu 7) (sol 3 2 1))
- (list foo aal vale pal naal irandu sol))
+((lambda** (foo bar #:key aal vale (pal 9) #:key* naal (irandu 7) (sol 3 2 1) uruthi)
+ (list foo bar aal vale pal naal irandu sol uruthi))
1 2 #:vale 123 #:naal 321 456)
-=> (1 2 123 9 (321 456) (7) (3 2 1))"
+=> (1 2 #f 123 9 (321 456) (7) (3 2 1) ())"
(syntax-case x ()
((_ (args-spec ...) body ...)
#`(lambda args
@@ -160,7 +161,7 @@ arguments. For example,
(syntax-case x ()
((arg defaults ...)
#'(arg (list defaults ...)))
- (arg #'arg)))
+ (arg #'(arg '()))))
nary-arguments))
body ...)
(let ((positionals rest (break keyword? args)))
diff --git a/tests/utils.scm b/tests/utils.scm
index 5c5bfd1..bc9315d 100644
--- a/tests/utils.scm
+++ b/tests/utils.scm
@@ -70,6 +70,16 @@
(list foo aal vale pal naal irandu sol))
1 2 #:vale 123 #:naal 321 456))
+(test-equal "default value of lambda** unary argument should be #f"
+ #f
+ ((lambda** (#:key foo)
+ foo)))
+
+(test-equal "default value of lambda** n-ary argument should be the empty list"
+ '()
+ ((lambda** (#:key* foo)
+ foo)))
+
(test-assert "syntax-lambda**"
(equal? (list #'1 #'2 #'123 (list #'1 #'2 #'3))
((syntax-lambda** (a b #:key foo #:key* bar)