diff --git a/libguile/srfi-1.c b/libguile/srfi-1.c index 39291a439..1651bcd5b 100644 --- a/libguile/srfi-1.c +++ b/libguile/srfi-1.c @@ -575,24 +575,6 @@ SCM_DEFINE (scm_srfi1_delete_duplicates_x, "delete-duplicates!", 1, 1, 0, } #undef FUNC_NAME -SCM_DEFINE (scm_srfi1_find_tail, "find-tail", 2, 0, 0, - (SCM pred, SCM lst), - "Return the first pair of @var{lst} whose @sc{car} satisfies the\n" - "predicate @var{pred}, or return @code{#f} if no such element is\n" - "found.") -#define FUNC_NAME s_scm_srfi1_find_tail -{ - SCM_VALIDATE_PROC (SCM_ARG1, pred); - - for ( ; scm_is_pair (lst); lst = SCM_CDR (lst)) - if (scm_is_true (scm_call_1 (pred, SCM_CAR (lst)))) - return lst; - SCM_ASSERT_TYPE (SCM_NULL_OR_NIL_P (lst), lst, SCM_ARG2, FUNC_NAME, "list"); - - return SCM_BOOL_F; -} -#undef FUNC_NAME - SCM_DEFINE (scm_srfi1_length_plus, "length+", 1, 0, 0, (SCM lst), "Return the length of @var{lst}, or @code{#f} if @var{lst} is\n" diff --git a/libguile/srfi-1.h b/libguile/srfi-1.h index fa21dc42a..3faaaa428 100644 --- a/libguile/srfi-1.h +++ b/libguile/srfi-1.h @@ -33,7 +33,6 @@ SCM_INTERNAL SCM scm_srfi1_delete (SCM x, SCM lst, SCM pred); SCM_INTERNAL SCM scm_srfi1_delete_x (SCM x, SCM lst, SCM pred); SCM_INTERNAL SCM scm_srfi1_delete_duplicates (SCM lst, SCM pred); SCM_INTERNAL SCM scm_srfi1_delete_duplicates_x (SCM lst, SCM pred); -SCM_INTERNAL SCM scm_srfi1_find_tail (SCM pred, SCM lst); SCM_INTERNAL SCM scm_srfi1_length_plus (SCM lst); SCM_INTERNAL SCM scm_srfi1_lset_difference_x (SCM equal, SCM lst, SCM rest); SCM_INTERNAL SCM scm_srfi1_list_copy (SCM lst); 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."