LIST-LENGTH & circular lists
Olin Shivers 18 Feb 1999 21:13 UTC
From: Doug Currie <xxxxxx@flavors.com>
One thing I have found useful is a version of list-length that terminates
on circular-lists, perhaps returning #f or 0 (or -N) for circular lists. It
kills two birds with one stone, and isn't much harder to implement than
circular-list?.
We could extend LIST-LENGTH to return #F on circular lists.
This does have the effect of screwing up type inference on LIST-LENGTH -- you
can no longer conclude that it returns a fixnum.
Alternately, I could allow LIST-LENGTH to continue to diverge or cause an
error when applied to circular lists, and introduce a new function with the
fancy behaviour. Some people might not like the fact that they will now have
to throw in false-tests after their calls to LIST-LENGTH if they need to rule
out circular lists. What would be a good name for the variant that handled
circular lists? I thought up
LIST-LENGTH? (Some won't like this as it returns non-#t true vals.)
LIST-LENGTH+ ("+" for "extra" version)
FINITE-LIST (Don't like it -- looks like a constructor to me.)
FINITE-LIST? (Some won't like this as it returns non-#t true vals.)
I'm not really fond of any of these names, but among them, would choose
LIST-LENGTH+.
My preference would be to add a new function, named LIST-LENGTH+, and
allow LIST-LENGTH to diverge or report an error on circular lists.
But it's a mild preference.
Support/disapproval/opinions?
-Olin