diff options
author | Mark H Weaver <mhw@netris.org> | 2014-09-30 03:50:47 -0400 |
---|---|---|
committer | Mark H Weaver <mhw@netris.org> | 2014-09-30 03:50:47 -0400 |
commit | 856d318a9f543d8a61fcf61caae7d07102586802 (patch) | |
tree | 10bd99500c027bbd472253f6cc34f8b1b516d4a1 /libguile/srfi-1.c | |
parent | f7582f9807d9a10fba86f54c4aeaa7444c51a315 (diff) | |
parent | 3157d455039f137ca5dfa8b9fbc4a3404ce00606 (diff) | |
download | guile-856d318a9f543d8a61fcf61caae7d07102586802.tar.gz |
Merge branch 'stable-2.0'
Conflicts:
benchmark-suite/benchmarks/ports.bm
libguile/async.h
libguile/bytevectors.c
libguile/foreign.c
libguile/gsubr.c
libguile/srfi-1.c
libguile/vm-engine.h
libguile/vm-i-scheme.c
module/Makefile.am
module/language/tree-il/analyze.scm
module/language/tree-il/peval.scm
module/scripts/compile.scm
module/scripts/disassemble.scm
test-suite/tests/asm-to-bytecode.test
test-suite/tests/peval.test
test-suite/tests/rdelim.test
Diffstat (limited to 'libguile/srfi-1.c')
-rw-r--r-- | libguile/srfi-1.c | 40 |
1 files changed, 36 insertions, 4 deletions
diff --git a/libguile/srfi-1.c b/libguile/srfi-1.c index aaa3efe6c..353a746f5 100644 --- a/libguile/srfi-1.c +++ b/libguile/srfi-1.c @@ -1,7 +1,7 @@ /* srfi-1.c --- SRFI-1 procedures for Guile * - * Copyright (C) 1995, 1996, 1997, 2000, 2001, 2002, 2003, 2005, 2006, - * 2008, 2009, 2010, 2011, 2013 Free Software Foundation, Inc. + * Copyright (C) 1995-1997, 2000-2003, 2005, 2006, 2008-2011, 2013 + * 2014 Free Software Foundation, Inc. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public License @@ -614,8 +614,40 @@ SCM_DEFINE (scm_srfi1_length_plus, "length+", 1, 0, 0, "circular.") #define FUNC_NAME s_scm_srfi1_length_plus { - long len = scm_ilength (lst); - return (len >= 0 ? SCM_I_MAKINUM (len) : SCM_BOOL_F); + size_t i = 0; + SCM tortoise = lst; + SCM hare = lst; + + do + { + if (!scm_is_pair (hare)) + { + if (SCM_NULL_OR_NIL_P (hare)) + return scm_from_size_t (i); + else + scm_wrong_type_arg_msg (FUNC_NAME, 1, lst, + "proper or circular list"); + } + hare = SCM_CDR (hare); + i++; + if (!scm_is_pair (hare)) + { + if (SCM_NULL_OR_NIL_P (hare)) + return scm_from_size_t (i); + else + scm_wrong_type_arg_msg (FUNC_NAME, 1, lst, + "proper or circular list"); + } + hare = SCM_CDR (hare); + i++; + /* For every two steps the hare takes, the tortoise takes one. */ + tortoise = SCM_CDR (tortoise); + } + while (!scm_is_eq (hare, tortoise)); + + /* If the tortoise ever catches the hare, then the list must contain + a cycle. */ + return SCM_BOOL_F; } #undef FUNC_NAME |