1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-04-30 03:40:34 +02:00

srfi-1: Rewrite 'find-tail' in Scheme.

* libguile/srfi-1.c (scm_srfi1_find_tail): Remove.
* libguile/srfi-1.h (scm_srfi1_find_tail): Likewise.
* module/srfi/srfi-1.scm (find-tail): New procedure.
This commit is contained in:
Ludovic Courtès 2020-06-17 17:33:28 +02:00
parent 0360843ace
commit cd4c747fb8
3 changed files with 11 additions and 19 deletions

View file

@ -731,6 +731,17 @@ the list returned."
head
(loop (cdr lst)))))))
(define (find-tail pred lst)
"Return the first pair of @var{lst} whose @sc{car} satisfies the
predicate @var{pred}, or return @code{#f} if no such element is found."
(check-arg procedure? pred find)
(let loop ((lst lst))
(and (not (null? lst))
(let ((head (car lst)))
(if (pred head)
lst
(loop (cdr lst)))))))
(define (take-while pred ls)
"Return a new list which is the longest initial prefix of LS whose
elements all satisfy the predicate PRED."