fix: correct combinators for supporting more use-cases and be more readable
parent
34ba4ca9fe
commit
2a845008da
Binary file not shown.
|
@ -1,41 +1,39 @@
|
|||
(define-module (radix combinators)
|
||||
#:use-module (srfi srfi-26)
|
||||
#:use-module (ice-9 curried-definitions)
|
||||
#:use-module (ice-9 match)
|
||||
#:export (all?
|
||||
any?
|
||||
#:export (all-of
|
||||
any-of
|
||||
conjoin
|
||||
disjoin
|
||||
inclusive-disjoin))
|
||||
|
||||
(define (all? pred lst)
|
||||
(define ((all-of pred) lst)
|
||||
(null? (filter (negate pred) lst)))
|
||||
|
||||
(define (any? pred lst)
|
||||
(define ((any-of pred) lst)
|
||||
(cond ((null? lst) #f)
|
||||
((pred (car lst)) #t)
|
||||
(else (any? pred (cdr lst)))))
|
||||
|
||||
#| (conjoin (list (conjoin '()) predicates)) = (conjoin predicates) |#
|
||||
(define (conjoin . predicates)
|
||||
(lambda args
|
||||
(if (null? predicates) #t
|
||||
(match-let loop (((head-pred . tail-preds) predicates))
|
||||
(cond ((null? tail-preds) (apply head-pred args))
|
||||
((apply head-pred args) (loop tail-preds))
|
||||
(else #f))))))
|
||||
(define ((conjoin . predicates) . args)
|
||||
(if (null? predicates) #t
|
||||
(match-let loop (((head-pred . tail-preds) predicates))
|
||||
(cond ((null? tail-preds) (apply head-pred args))
|
||||
((apply head-pred args) (loop tail-preds))
|
||||
(else #f)))))
|
||||
|
||||
#| (disjoin (list (disjoin '()) predicates)) = (disjoin predicates) |#
|
||||
(define (disjoin . predicates)
|
||||
(lambda args
|
||||
(if (null? predicates) #f
|
||||
(null? (cdr (filter (cut apply <> args)
|
||||
predicates))))))
|
||||
(define ((disjoin . predicates) . args)
|
||||
(if (null? predicates) #f
|
||||
(= 1 (length (filter (cut apply <> args)
|
||||
predicates)))))
|
||||
|
||||
(define (inclusive-disjoin . predicates)
|
||||
(lambda args
|
||||
(if (null? predicates) #f
|
||||
(match-let loop (((head-pred . tail-preds) predicates))
|
||||
(cond ((null? tail-preds) (apply head-pred args))
|
||||
((not (apply head-pred args)) (loop tail-preds))
|
||||
(else #f))))))
|
||||
(define ((inclusive-disjoin . predicates) . args)
|
||||
(if (null? predicates) #f
|
||||
(match-let loop (((head-pred . tail-preds) predicates))
|
||||
(cond ((null? tail-preds) (apply head-pred args))
|
||||
((not (apply head-pred args)) (loop tail-preds))
|
||||
(else #f)))))
|
||||
|
||||
|
|
Loading…
Reference in New Issue