From c9c12e0e396475533ef987e3969b2ec847a8af9f Mon Sep 17 00:00:00 2001
From: Arun Isaac
Date: Tue, 27 Jul 2021 15:27:25 +0530
Subject: ccwl: Make syntax-lambda** more like lambda**.
I have tripped up several times on the differences between lambda**
and syntax-lambda**. No longer! Making syntax-lambda** as close as
possible to lambda** makes the code much more readable and align
better with common sense.
* ccwl/utils.scm (syntax-lambda**): Do not ignore the first
identifier. Accept multiple values as arguments, not a single syntax
object.
* ccwl/ccwl.scm (command): Update use of syntax-lambda**.
* tests/utils.scm ("syntax-lambda**", "syntax-lambda** with default
values"): Update tests.
---
ccwl/ccwl.scm | 130 ++++++++++++++++++++++++++++----------------------------
ccwl/utils.scm | 18 +++-----
tests/utils.scm | 7 ++-
3 files changed, 77 insertions(+), 78 deletions(-)
diff --git a/ccwl/ccwl.scm b/ccwl/ccwl.scm
index 37f8177..09c590c 100644
--- a/ccwl/ccwl.scm
+++ b/ccwl/ccwl.scm
@@ -101,73 +101,75 @@ association list."
;; TODO: Add fine-grained syntax checking.
(define-syntax command
(lambda (x)
- ((syntax-lambda** (#:key stdin #:key* inputs outputs run other)
- (let ((inputs
- ;; Canonicalize inputs.
- (map (lambda (x)
- (syntax-case x ()
- ((id args ...) (identifier? #'id)
- #'(id args ...))
- (id (identifier? #'id) #'(id))
- (_ (error "Invalid input:" (syntax->datum x)))))
- inputs)))
- (unless run
- (error "#:run key required in command definition" (syntax->datum x)))
- #`(make-command
- (list #,@(map (lambda (x)
- (syntax-case x ()
- ((id args ...)
- ;; Instantiate object with
- ;; position and prefix.
- #`(input 'id
- #:position #,(list-index (lambda (x)
+ (syntax-case x ()
+ ((_ args ...)
+ (apply (syntax-lambda** (#:key stdin #:key* inputs outputs run other)
+ (let ((inputs
+ ;; Canonicalize inputs.
+ (map (lambda (x)
+ (syntax-case x ()
+ ((id args ...) (identifier? #'id)
+ #'(id args ...))
+ (id (identifier? #'id) #'(id))
+ (_ (error "Invalid input:" (syntax->datum x)))))
+ inputs)))
+ (unless run
+ (error "#:run key required in command definition" (syntax->datum x)))
+ #`(make-command
+ (list #,@(map (lambda (x)
+ (syntax-case x ()
+ ((id args ...)
+ ;; Instantiate object with
+ ;; position and prefix.
+ #`(input 'id
+ #:position #,(list-index (lambda (x)
+ (syntax-case x ()
+ (input (identifier? #'input)
+ (eq? (syntax->datum #'id)
+ (syntax->datum #'input)))
+ ((_ input)
+ (eq? (syntax->datum #'id)
+ (syntax->datum #'input)))
+ (_ #f)))
+ run)
+ #:prefix #,(any (lambda (x)
(syntax-case x ()
- (input (identifier? #'input)
- (eq? (syntax->datum #'id)
- (syntax->datum #'input)))
- ((_ input)
- (eq? (syntax->datum #'id)
- (syntax->datum #'input)))
+ ((prefix input)
+ (and (eq? (syntax->datum #'id)
+ (syntax->datum #'input))
+ #'prefix))
(_ #f)))
run)
- #:prefix #,(any (lambda (x)
- (syntax-case x ()
- ((prefix input)
- (and (eq? (syntax->datum #'id)
- (syntax->datum #'input))
- #'prefix))
- (_ #f)))
- run)
- args ...))))
- inputs))
- (list #,@(map (lambda (x)
- ;; Instantiate