From 553460f7d15e44deda3a7959b89b23bfacc12060 Mon Sep 17 00:00:00 2001
From: Arun Isaac
Date: Sun, 21 Mar 2021 16:00:01 +0530
Subject: Add alist filtering utility function.
* ccwl/ccwl.scm (filter-alist): New function.
(input->tree): Use filter-alist.
---
ccwl/ccwl.scm | 19 ++++++++++++-------
1 file changed, 12 insertions(+), 7 deletions(-)
diff --git a/ccwl/ccwl.scm b/ccwl/ccwl.scm
index 97613a2..be99eb6 100644
--- a/ccwl/ccwl.scm
+++ b/ccwl/ccwl.scm
@@ -68,16 +68,21 @@
(define %stdout
(output "stdout" #:type 'stdout))
+(define (filter-alist alist)
+ "Filter ALIST removing entries with #f as the value."
+ (filter (match-lambda
+ ((_ . #f) #f)
+ (_ #t))
+ alist))
+
(define (input->tree input)
"Convert INPUT, an object, to a tree."
`(,(input-id input)
- ,@(filter identity
- (list (and (input-type input)
- (cons 'type (input-type input)))
- (and (input-label input)
- (cons 'label (input-label input)))
- (and (not (unspecified-default? (input-default input)))
- (cons 'default (input-default input)))))
+ ,@(filter-alist
+ `((type . ,(input-type input))
+ (label . ,(input-label input))
+ (default . ,(and (not (unspecified-default? (input-default input)))
+ (input-default input)))))
,@(input-other input)))
(define-immutable-record-type
--
cgit v1.2.3