[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 (library
(utils) (utils)
(export inc! (export inc! dec!
dec!
swap! swap!
slurp-file slurp-file
chomp chomp
hotpatch-sym hotpatch-sym
indirect-lambda indirect-lambda
set-lambda! set-lambda!
dlambda) dlambda
all? some? none?)
(import (chezscheme) (import (chezscheme)
(only (srfi s1 lists) drop-while)) (only (srfi s1 lists) drop-while))
@ -67,4 +69,24 @@
(apply (case m (apply (case m
[(name) (lambda params b1 b2 ...)] ...) [(name) (lambda params b1 b2 ...)] ...)
args))))) 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)))
) )