Hi,
The SRFI-1 library defines a procedure called "find-tail", which returns the first cons-cell of a list such that the head of that cell satisfies a given predicate.
SRFI-1 explains it with the following examples:
(find-tail even? '(3 1 37 -8 -5 0 0)) => (-8 -5 0 0)
(find-tail even? '(3 1 37 -5)) => #f
Recently I have defined a very similar function, but rather than being invoked on the cell's car, it is defined on the cell itself:
(define (sublist satisfying? elements)
(and (not (null? elements))
(if (satisfying? elements)
elements
(sublist satisfying? (cdr elements)))))
(e.g.
(sublist (lambda (cell)
(= (car cell) 3))
'(1 2 3 4 5))
(3 4 5))
It increases the expressive power of find-tail, because it can look at more than one element.
I wonder whether some of you have already been using such a function, and if so, what name do you use for it?
(Haskell's Hoogle shows that they have a similar function, named dropWhileList)
--- SoupGate-Win32 v1.05
* Origin: fsxNet Usenet Gateway (21:1/5)