split : bug or feature ?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

split : bug or feature ?

laurent laffont
In Pharo:

':' split: 'one:two:three:'   => OrderedCollection( 'one' 'two' 'three' '' )
(':' split: 'one:two:three:') size => 4

Last element is an empty String

In Ruby:

>> 'one:two:three:'.split(':')
=> ["one", "two", "three"]
>> 'one:two:three:'.split(':').size
=> 3

Laurent Laffont

_______________________________________________
Pharo-project mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
Reply | Threaded
Open this post in threaded view
|

Re: split : bug or feature ?

Henrik Sperre Johansen
  On 01.05.2010 10:51, laurent laffont wrote:

> In Pharo:
>
> ':' split: 'one:two:three:'   => OrderedCollection( 'one' 'two'
> 'three' '' )
> (':' split: 'one:two:three:') size => 4
>
> Last element is an empty String
>
> In Ruby:
>
> >> 'one:two:three:'.split(':')
> => ["one", "two", "three"]
> >> 'one:two:three:'.split(':').size
> => 3
>
> Laurent Laffont
Well, technically speaking you could say it is correct.
Does Ruby drop all empty subsequences?
ie:
('.' split: 'hah...hah') size gives 4 or 2?

Personally I'm more annoyed that:
(#great split: #(bad great bad great bad great bad)) size = 1, but:
(#(great) split: #(bad great bad great bad great bad)) size = 4

Cheers,
Henry

_______________________________________________
Pharo-project mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
Reply | Threaded
Open this post in threaded view
|

Re: split : bug or feature ?

laurent laffont
On Sat, May 1, 2010 at 1:10 PM, Henrik Sperre Johansen <[hidden email]> wrote:
 On 01.05.2010 10:51, laurent laffont wrote:
In Pharo:

':' split: 'one:two:three:'   => OrderedCollection( 'one' 'two' 'three' '' )
(':' split: 'one:two:three:') size => 4

Last element is an empty String

In Ruby:

>> 'one:two:three:'.split(':')
=> ["one", "two", "three"]
>> 'one:two:three:'.split(':').size
=> 3

Laurent Laffont
Well, technically speaking you could say it is correct.
Does Ruby drop all empty subsequences?
ie:
('.' split: 'hah...hah') size gives 4 or 2?

It seems it drops only the last ones:

>> 'hah...hah'.split('.')
=> ["hah", "", "", "hah"]

>> '.hah...hah'.split('.')
=> ["", "hah", "", "", "hah"]

>> 'hah...hah.'.split('.')
=> ["hah", "", "", "hah"]

>> 'hah...hah..'.split('.')
=> ["hah", "", "", "hah"]
 
Laurent Laffont





 

Personally I'm more annoyed that:
(#great split: #(bad great bad great bad great bad)) size = 1, but:
(#(great) split: #(bad great bad great bad great bad)) size = 4

Cheers,
Henry


_______________________________________________
Pharo-project mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project


_______________________________________________
Pharo-project mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project