SketchyLISP Reference |
Copyright (C) 2007 Nils M Holm |
<<[even?] | [Index] | [explode]>> |
Conformance: R5.91RS Scheme
Purpose:
Test whether given property exists in a sequence of lists.
The property is expressed using an
n-ary
function
p.
P
is applied to a list consisting of the first
member of each given list. Hence there must be
exactly
n
lists. If
p
returns truth,
exists
returns
#t
immediately.
Otherwise it is applied to a list consisting
of the second member of each given list, etc.
If
p
returns falsity for all sets of members,
exists
returns
#f.
All lists passed to
exists
must have the same length.
When all lists passed to
exists
are empty, it returns
#f.
Arguments:
F - predicate expressing property
A* ... - lists
Implementation:
(define (exists p . a*) (letrec ((carof (lambda (a) (map-car car a))) (cdrof (lambda (a) (map-car cdr a))) (_exists (lambda (a*) (cond ((null? (car a*)) #f) (else (or (apply p (carof a*)) (_exists (cdrof a*)))))))) (_exists a*)))
Example:
(exists < '(5 5 5) '(5 7 5)) => #t
See also:
for-all,
memp,
filter.
<<[even?] | [Index] | [explode]>> |