Ludovic Courtès escreveu: > Hello, > > This is a followup to this discussion: > > http://thread.gmane.org/gmane.lisp.guile.devel/7194 > > The attached patch changes several list-related functions so that they > don't validate their input with `SCM_VALIDATE_LIST ()' since it's O(n). > > A side-effect (besides performance improvements) is that all these > functions will now happily traverse circular lists, and will silently > deal with dotted lists. This is acceptable behavior IMO. > > Nevertheless, the second patch below implements the "tortoise and the > hare" in `list-copy' so that it detects circular list; it seems > worthwhile to check that here since `list-copy' would otherwise exhaust > memory. > > (Note that SRFI-1's `list-copy' *does* accept improper lists, including > circular lists, although SRFI-1 does not explicitly mention that it > should handle improper list.) > > Also, in some cases, the `wrong-type-arg' message is different (but the > exception key is the same). > > OK to apply to both branches?
- return scm_c_memq (x, lst); + for (; !SCM_NULL_OR_NIL_P (lst); lst = SCM_CDR (lst)) + { + SCM_VALIDATE_CONS (2, lst); Looks cleaner to use SCM_CONS_P (or whatever it is called) as loop guard, so it is obviously correct, and crash if the lst is not properly terminated after the loop (- perhaps only if we're not compiling in optimizing mode). On a tangent, is anyone still seriously considering to run Emacs atop GUILE? (It looks a bit like a travesty if we're trying to accomodate elisp while also trying to follow standards like SRFI-x and RxRS) - SCM from_here; + SCM from_here, hare; you could do the init to lst right here. IMO it's neater not to have uninitialized memory locations during program execution. ;;;; list.test --- tests guile's lists -*- scheme -*- -;;;; Copyright (C) 2000, 2001, 2006 Free Software Foundation, Inc. +;;;; Copyright (C) 2000, 2001, 2006, 2008 Free Software Foundation, Inc. Can we do this in one fell swoop, adding 2008 to all files? After all publishing a commit is a release in some sense. Then, we don't have to worry about the file headers anymore. -- Han-Wen Nienhuys - [EMAIL PROTECTED] - http://www.xs4all.nl/~hanwen