[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: bug in (ANY ... )
Procedures ANY? and ANY have a bug, at least on the zoo, in that they
will only work with unary predicates:
I remember seeing someone else send a fix for that once (Meehan?).
The following procedure works properly and may be used to shadow the
official T procedures:
(DEFINE (any pred? . L)
(COND ( (null? (car L))
nil)
( (apply pred? (map car L))
T)
(ELSE
(apply any (cons pred? (map cdr L))) ) ) )
A few changes should be made:
(DEFINE (any pred? . L)
(COND ( (memq? nil L) ; change 1
nil)
( (apply pred? (map car L)) ) ; change 2
(ELSE
(apply any pred? (map cdr L)) ) ) ) ; change 3
1) you want to stop as soon as any of the lists is empty
(what I wanted to write was (any? null? L) but...)
2) any should return pred?'s value, not always T
3) apply takes the form (apply fun arg arg ... arg-list)
Change 3 is minor, but the other two are needed for correctness.
Hope this helps.