Since

'abc' includesSubstring: ''.
 "true"
'abc' indexOfSubCollection: ''.
 "0"

and following basic principles, my first reaction would also be that

'abc' beginsWith: ''.
'abc' endsWith: ''.

should both be true.

On the other hand, this is really a degenerate case. You know the answer 
upfront (it does not depend on the actual receiver) and thus it does not tell 
you much.

I vote for this to be a bug.

> On 20 Apr 2022, at 14:07, Richard O'Keefe <rao...@gmail.com> wrote:
> 
> I've just tracked down a nasty little problem
> porting some code to Pharo.  As a result, I
> have added to the comments in my own versions
> of these methods.    beginsWith: aSequence
>       "Answer true if aSequence is a prefix of the receiver.
>        This makes sense for all sequences.
>        There is a compatibility issue concerning 'abc' beginsWith: ''
>        + VisualWorks, Dolphin, astc, GNU ST (where the method is
>          called #startsWith:) and VisualAge (where the method
>          is called #wbBeginsWith:)
>          agree than EVERY sequence begins with an empty prefix.
>        - Squeak and Pharo
>          agree that NO sequence begins with an empty sequence.
>        # ST/X chooses compatibility with Squeak, heaving a big unhappy
>          sigh, and adds #startsWith: to have something sensible to use.
>        Now ST/X *thinks* it is compatible with VW, though it isn't, so 
>        I wonder if this was a bug that VW fixed and Squeak didn't?    
>        astc goes with the majority here.  This is also compatible with
>        Haskell, ML, and with StartsWith in C# and startsWith in Java."
>       ^self beginsWith: aSequence ignoringCase: false
> 
>     endsWith: aSequence
>       "Answer true if aSequence is a suffix of the receiver.
>        This makes sense for all sequences.
>        There is a compatibility issue concerning 'abc' endsWith: ''.  
>        + VisualWorks, Dolphin, astc, GNU ST, and VisualAge (where     
>          the method is called #wbEndsWith:)
>          agree that EVERY sequence ends with an empty suffix.
>        - Squeak and Pharo
>          agree that NO sequence ends with an empty suffix.
>        # ST/X chooses compatibility with the majority, apparently
>          unaware that this makes #beginsWith: and #endsWith: inconsistent.
>        astc goes with the majority here.  This is also compatible with
>        Haskell, ML, C#, and Java."
>       ^self endsWith: aSequence ignoringCase: false 
> 
> Does anyone have any idea
>  - why Squeak and Pharo are the odd ones out?
>  - why anyone thought making #beginsWith: and #endsWith:, um, "quirky"
>    was a good idea (it's pretty standard in books on the theory of
>    strings to define "x is a prefix of y iff there is a z such that
>    y = x concatenated with z")
>  
> I was about to try to file a bug report for the first time,
> then realised that maybe other people don't think this IS a bug.
> 
> 
> 

Reply via email to