[functional-tests/utils] add all?, some? and none?

They only work with one list though.  Use every from srfi1.
This commit is contained in:
Joe Thornber 2017-10-04 10:19:46 +01:00
parent 331303fe03
commit 8b7e5acc48

View File

@ -1,14 +1,16 @@
(library
(utils)
(export inc!
dec!
(export inc! dec!
swap!
slurp-file
chomp
hotpatch-sym
indirect-lambda
set-lambda!
dlambda)
dlambda
all? some? none?)
(import (chezscheme)
(only (srfi s1 lists) drop-while))
@ -67,4 +69,24 @@
(apply (case m
[(name) (lambda params b1 b2 ...)] ...)
args)))))
;; FIXME: why aren't these in core scheme? what do people use instead?
(define (all? pred xs)
(let loop ((xs xs))
(if (null? xs)
#t
(if (pred (car xs))
(loop (cdr xs))
#f))))
(define (some? pred xs)
(let loop ((xs xs))
(if (null? xs)
#f
(if (pred (car xs))
#t
(loop (cdr xs))))))
(define (none? pred xs)
(not (all? pred xs)))
)