mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-06-10 22:10:21 +02:00
(length+): Rewrite using scm_ilength.
This commit is contained in:
parent
15d36a3438
commit
de51f5955d
3 changed files with 13 additions and 13 deletions
|
@ -370,6 +370,18 @@ SCM_DEFINE (scm_srfi1_delete_duplicates_x, "delete-duplicates!", 1, 1, 0,
|
||||||
#undef FUNC_NAME
|
#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"
|
||||||
|
"circular.")
|
||||||
|
#define FUNC_NAME s_scm_srfi1_length_plus
|
||||||
|
{
|
||||||
|
long len = scm_ilength (lst);
|
||||||
|
return (len >= 0 ? SCM_MAKINUM (len) : SCM_BOOL_F);
|
||||||
|
}
|
||||||
|
#undef FUNC_NAME
|
||||||
|
|
||||||
|
|
||||||
/* Typechecking for multi-argument MAP and FOR-EACH.
|
/* Typechecking for multi-argument MAP and FOR-EACH.
|
||||||
|
|
||||||
Verify that each element of the vector ARGV, except for the first,
|
Verify that each element of the vector ARGV, except for the first,
|
||||||
|
|
|
@ -36,6 +36,7 @@ SCM_SRFI1_API SCM scm_srfi1_delete (SCM x, SCM lst, SCM pred);
|
||||||
SCM_SRFI1_API SCM scm_srfi1_delete_x (SCM x, SCM lst, SCM pred);
|
SCM_SRFI1_API SCM scm_srfi1_delete_x (SCM x, SCM lst, SCM pred);
|
||||||
SCM_SRFI1_API SCM scm_srfi1_delete_duplicates (SCM lst, SCM pred);
|
SCM_SRFI1_API SCM scm_srfi1_delete_duplicates (SCM lst, SCM pred);
|
||||||
SCM_SRFI1_API SCM scm_srfi1_delete_duplicates_x (SCM lst, SCM pred);
|
SCM_SRFI1_API SCM scm_srfi1_delete_duplicates_x (SCM lst, SCM pred);
|
||||||
|
SCM_SRFI1_API SCM scm_srfi1_length_plus (SCM lst);
|
||||||
SCM_SRFI1_API SCM scm_srfi1_map (SCM proc, SCM arg1, SCM args);
|
SCM_SRFI1_API SCM scm_srfi1_map (SCM proc, SCM arg1, SCM args);
|
||||||
SCM_SRFI1_API SCM scm_srfi1_for_each (SCM proc, SCM arg1, SCM args);
|
SCM_SRFI1_API SCM scm_srfi1_for_each (SCM proc, SCM arg1, SCM args);
|
||||||
SCM_SRFI1_API SCM scm_srfi1_member (SCM obj, SCM ls, SCM pred);
|
SCM_SRFI1_API SCM scm_srfi1_member (SCM obj, SCM ls, SCM pred);
|
||||||
|
|
|
@ -414,19 +414,6 @@
|
||||||
|
|
||||||
;;; Miscelleneous: length, append, concatenate, reverse, zip & count
|
;;; Miscelleneous: length, append, concatenate, reverse, zip & count
|
||||||
|
|
||||||
(define (length+ clist)
|
|
||||||
(if (null? clist)
|
|
||||||
0
|
|
||||||
(let lp ((hare (cdr clist)) (tortoise clist) (l 1))
|
|
||||||
(if (null? hare)
|
|
||||||
l
|
|
||||||
(let ((hare (cdr hare)))
|
|
||||||
(if (null? hare)
|
|
||||||
(+ l 1)
|
|
||||||
(if (eq? hare tortoise)
|
|
||||||
#f
|
|
||||||
(lp (cdr hare) (cdr tortoise) (+ l 2)))))))))
|
|
||||||
|
|
||||||
(define (append-reverse rev-head tail)
|
(define (append-reverse rev-head tail)
|
||||||
(let lp ((l rev-head) (acc tail))
|
(let lp ((l rev-head) (acc tail))
|
||||||
(if (null? l)
|
(if (null? l)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue