Re: splitfields (fwd)

Lou Kates (louk@research.teleride.on.ca)
Sun, 16 Aug 1992 20:44:56 -0400

>
> >string.splitfields('abc','') appears to go into an endless loop. I would
> >have thought that it would return ['a','b','c'].
>
> What makes you think so? I believe a reasonable mathematical
> definition of splitfields(x, y) would return an infinite list if y==''.
>

The following seem to be reasonable properties for splitfields to
have for all strings s and t:

1. joinfields(splitfields(s, t), t) == s
2. splitfields(joinfields(s, t), t) == s
3. splitfields(s, t) finite

That is, for identical separators, t, splitfields commutes with
joinfields and is finite for finite s. In other words, joinfields
and splitfields are inverses of each other and splitfields is
finite for finite s.

Note that

joinfields(['abc'],'')
joinfields(['a','b','c'],'')
joinfields(['ab','c'],'')
joinfields(['a','bc'],'')
joinfields(['','abc'],'')
etc.

are all the same so that splitfields is not 1-to-1 and so has no
inverse (which is what properties #1 and #2 imply).

I suppose that going into an endless loop could represent the
fact that there is no unique inverse to any of the above;
however, I think it would be more useful to pick one of them
(this might correspond to picking the generalized inverse of a
matrix which is a similar situation) or else generate an
exception.

If we were to pick one of them

splitfields('abc','') == ['a','b','c']

seems generally the most useful since we already have an easy way
of converting 'abc' to ['abc'] simply by enclosing it in square
brackets.

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