From cd4c747fb8cd6c65f18471aad54427d87b884ebc Mon Sep 17 00:00:00 2001 From: Ludovic Courtès Date: Wed, 17 Jun 2020 17:33:28 +0200 Subject: 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. --- module/srfi/srfi-1.scm | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'module/srfi') diff --git a/module/srfi/srfi-1.scm b/module/srfi/srfi-1.scm index e5b28e777..1fc7a0e26 100644 --- a/module/srfi/srfi-1.scm +++ b/module/srfi/srfi-1.scm @@ -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." -- cgit v1.2.3