Re: more on splitfields

Lou Kates (louk@research.teleride.on.ca)
Wed, 19 Aug 1992 13:35:34 -0400

> >
> > a = string.splitfields(s, sep)
> >
> I currently think that the best thing to do is to raise an exception
> when sep is ''. First, any one of the possible results are easy to
> get with other means. Since almost all calls will specify a literal
> as separator argument, I doubt that people will want to use
> splitfields() for what they can express easier. Second, there is an

Actually the way this entire thing came about what that I wanted
to derive a list of single characters from a string. Of course, I
could write a simple loop but thought that perhaps there might be
an easier way using some library function/method. Is there such
an easier way?

> anomaly for splitfields('',''): in to your previous proposal it should
> return [], but joinfields([], sep ) is ill-defined: the list must have
> at least one element! So an exception seems to be the best solution.
>

OK. I agree with you.

While we are on the topic of infinite loops in library
functions/methods the following will also cause infinite looping:

a = [2, 'abc']
a.append(a)

There are a number of possibilities:

1. let it loop infinitely as it does now

2. allow circularity

3. regard this to be the same as:

a.append(deepcopy(a))

in which case there is no circularity. In this
example we would get:

[2, 'abc', [2, 'abc']]

4. detect circularity and raise an exception

I suppose that there are significant implementation issues here
as well as desirability ones.

Lou Kates, louk@research.teleride.on.ca