Prelude function suggestions

Marcin 'Qrczak' Kowalczyk qrczak at
Wed Jul 28 08:11:07 EDT 2004

W liście z śro, 28-07-2004, godz. 10:44 +0100, Keith Wansbrough napisał:

> There should be two versions of this, one which treats repeated delimiters the same as single ones and ignores initial and final delimiters, and one which treats repeated delimiters as creating an empty field.  Thus
> split  isSpace " foo  bar baz " = ["foo","bar","baz"]
> split' isSpace " foo  bar baz " = ["","foo","","bar","baz",""]

I just wanted to name such functions for my language and they are called
Split and Split1. I like the name split, as it's used in Python, Perl
and Ruby; I don't like the name split1 but don't have anything better.

Python interprets the terminating separators as separators and never
returns an empty list, while Perl and Ruby ignore them:

[qrczak ~]$ python -c 'print "aabbcc".split("a")'
['', '', 'bbcc']
[qrczak ~]$ python -c 'print "aabbcc".split("c")'
['aabb', '', '']
[qrczak ~]$ perl -e 'print join(",", split(/a/, "aabbcc")), "\n"'
[qrczak ~]$ perl -e 'print join(",", split(/c/, "aabbcc")), "\n"'
[qrczak ~]$ ruby -e 'p "aabbcc".split("a")'
["", "", "bbcc"]
[qrczak ~]$ ruby -e 'p "aabbcc".split("c")'

I prefer the Python semantics. The other can be obtained by removing
trailing empty elements from the result, for which there should be an
equivalent of dropWhile working from the other end...

   __("<         Marcin Kowalczyk
   \__/       qrczak at

More information about the Libraries mailing list