diff options
author | Kevin Ryde <user42@zip.com.au> | 2003-07-28 23:54:39 +0000 |
---|---|---|
committer | Kevin Ryde <user42@zip.com.au> | 2003-07-28 23:54:39 +0000 |
commit | de51f5955dbafe5e857bcc4a19171e00c634c6dc (patch) | |
tree | a65d9589cc0cbe89aedd859af07ce5019ad13ea6 | |
parent | 15d36a34384879f927e3de31b4bd74292d1bb86c (diff) | |
download | guile-de51f5955dbafe5e857bcc4a19171e00c634c6dc.tar.gz |
(length+): Rewrite using scm_ilength.
-rw-r--r-- | srfi/srfi-1.c | 12 | ||||
-rw-r--r-- | srfi/srfi-1.h | 1 | ||||
-rw-r--r-- | srfi/srfi-1.scm | 13 |
3 files changed, 13 insertions, 13 deletions
diff --git a/srfi/srfi-1.c b/srfi/srfi-1.c index db35eb92b..27f7dd12d 100644 --- a/srfi/srfi-1.c +++ b/srfi/srfi-1.c @@ -370,6 +370,18 @@ SCM_DEFINE (scm_srfi1_delete_duplicates_x, "delete-duplicates!", 1, 1, 0, #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. Verify that each element of the vector ARGV, except for the first, diff --git a/srfi/srfi-1.h b/srfi/srfi-1.h index e082ba4aa..a92f51b9b 100644 --- a/srfi/srfi-1.h +++ b/srfi/srfi-1.h @@ -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_duplicates (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_for_each (SCM proc, SCM arg1, SCM args); SCM_SRFI1_API SCM scm_srfi1_member (SCM obj, SCM ls, SCM pred); diff --git a/srfi/srfi-1.scm b/srfi/srfi-1.scm index 507ebb3f6..c9555bff6 100644 --- a/srfi/srfi-1.scm +++ b/srfi/srfi-1.scm @@ -414,19 +414,6 @@ ;;; 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) (let lp ((l rev-head) (acc tail)) (if (null? l) |