A => composable-predicates.scm +75 -0
@@ 0,0 1,75 @@
+;; Composable predicates
+
+(define-module (composable-predicates)
+ #:use-module ((srfi srfi-1) #:select (fold))
+ #:export (compose-pred))
+
+(define (compose-pred pred . preds)
+ (define (chain-it proc chain)
+ (lambda (arg)
+ (if (proc arg)
+ (chain arg)
+ #f)))
+ (fold chain-it pred preds))
+
+
+
+(define-syntax define-with-arg-return
+ (syntax-rules ()
+ ((_ (name orig) ...)
+ (begin
+ (define (name arg)
+ (and (orig arg) arg))
+ ...
+ (export! (name . orig) ...)))))
+
+
+(define-with-arg-return
+ ;; chars
+ (cchar? char?)
+ (cchar-alphabetic? char-alphabetic?)
+ (cchar-is-both? char-is-both?)
+ (cchar-lower-case? char-lower-case?)
+ (cchar-numeric? char-numeric?)
+ (cchar-upper-case? char-upper-case?)
+ (cchar-whitespace? char-whitespace?)
+
+ ;; lists and pairs
+ (llist? list?)
+ (nnull? null?)
+ (ppair? pair?)
+
+ ;; numerics
+ (ccomplex? complex?)
+ (eeven? even?)
+ (eexact? exact?)
+ (eexact-integer? exact-integer?)
+ (iinexact? inexact?)
+ (iinf? inf?)
+ (iinteger? integer?)
+ (nnegative? negative?)
+ (nnumber? number?)
+ (oodd? odd?)
+ (ppositive? positive?)
+ (rrational? rational?)
+ (rreal? real?)
+ (zzero? zero?)
+
+ ;; ports
+ (iinput-port? input-port?)
+ (pport? port?)
+ (ooutput-port? output-port?)
+ (ttextual-port? textual-port?)
+
+ ;; String
+ (sstring? string?)
+ (sstring-null? string-null?)
+
+ ;; symbols
+ (ssymbol-interned? symbol-interned?)
+ (ssymbol? symbol?)
+
+ (ssyntax? syntax?)
+ (vvector? vector?)
+
+ )