
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"' ,,bbcc [qrczak ~]$ perl -e 'print join(",", split(/c/, "aabbcc")), "\n"' aabb [qrczak ~]$ ruby -e 'p "aabbcc".split("a")' ["", "", "bbcc"] [qrczak ~]$ ruby -e 'p "aabbcc".split("c")' ["aabb"] 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@knm.org.pl ^^ http://qrnik.knm.org.pl/~qrczak/