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:
parent
0360843ace
commit
cd4c747fb8
3 changed files with 11 additions and 19 deletions
|
@ -575,24 +575,6 @@ SCM_DEFINE (scm_srfi1_delete_duplicates_x, "delete-duplicates!", 1, 1, 0,
|
||||||
}
|
}
|
||||||
#undef FUNC_NAME
|
#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_DEFINE (scm_srfi1_length_plus, "length+", 1, 0, 0,
|
||||||
(SCM lst),
|
(SCM lst),
|
||||||
"Return the length of @var{lst}, or @code{#f} if @var{lst} is\n"
|
"Return the length of @var{lst}, or @code{#f} if @var{lst} is\n"
|
||||||
|
|
|
@ -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_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 (SCM lst, SCM pred);
|
||||||
SCM_INTERNAL SCM scm_srfi1_delete_duplicates_x (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_length_plus (SCM lst);
|
||||||
SCM_INTERNAL SCM scm_srfi1_lset_difference_x (SCM equal, SCM lst, SCM rest);
|
SCM_INTERNAL SCM scm_srfi1_lset_difference_x (SCM equal, SCM lst, SCM rest);
|
||||||
SCM_INTERNAL SCM scm_srfi1_list_copy (SCM lst);
|
SCM_INTERNAL SCM scm_srfi1_list_copy (SCM lst);
|
||||||
|
|
|
@ -731,6 +731,17 @@ the list returned."
|
||||||
head
|
head
|
||||||
(loop (cdr lst)))))))
|
(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)
|
(define (take-while pred ls)
|
||||||
"Return a new list which is the longest initial prefix of LS whose
|
"Return a new list which is the longest initial prefix of LS whose
|
||||||
elements all satisfy the predicate PRED."
|
elements all satisfy the predicate PRED."
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue