[Pharo-project] String>>beginsWith: with empty strings issue
Hi, I noticed that 'pharo' beginsWith: '' returns false. Is that Ok? I expect that this returns true, because the empty string is a prefix (and suffix) of any other string. Similar behavior exhibits endsWith:. This seems a bug to me. What do you think? In case we acknowledge it's a bug I can post an entry in the issue tracker and tonight upload a SLICE with the fix. Regards, Gabriel
I'm not sure, but in ANSI, indexOfSubcollection:startingAt: is defined as returning 0 (no match) for an empty collection. This doesn't necessarily mean that #beginsWith: needs to return false as well, of course, but it would be another data point. And I just checked VW and it returns true for both #beginsWith: and #endsWith: in this case so that may be an argument the other way (haven't checked Gnu or VA - not sure if they even implement it). Julian 2010/3/4 Gabriel Cotelli <g.cotelli@gmail.com>:
Hi,
I noticed that 'pharo' beginsWith: '' returns false.
Is that Ok? I expect that this returns true, because the empty string is a prefix (and suffix) of any other string. Similar behavior exhibits endsWith:.
This seems a bug to me. What do you think?
In case we acknowledge it's a bug I can post an entry in the issue tracker and tonight upload a SLICE with the fix.
Regards, Gabriel
_______________________________________________ Pharo-project mailing list Pharo-project@lists.gforge.inria.fr http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
Hi, VA implemented this behavior in the latest releases for Seaside compatibility and their implementation behaves similar to Pharo one. I think that conceptually both methods must return true, but that's my opinion. If we can get to a consensus I can make the necessary changes. So please comment on this!. Thanks, Gabriel On Thu, Mar 4, 2010 at 10:40 AM, Julian Fitzell <jfitzell@gmail.com> wrote:
I'm not sure, but in ANSI, indexOfSubcollection:startingAt: is defined as returning 0 (no match) for an empty collection.
This doesn't necessarily mean that #beginsWith: needs to return false as well, of course, but it would be another data point. And I just checked VW and it returns true for both #beginsWith: and #endsWith: in this case so that may be an argument the other way (haven't checked Gnu or VA - not sure if they even implement it).
Julian
2010/3/4 Gabriel Cotelli <g.cotelli@gmail.com>:
Hi,
I noticed that 'pharo' beginsWith: '' returns false.
Is that Ok? I expect that this returns true, because the empty string is a prefix (and suffix) of any other string. Similar behavior exhibits endsWith:.
This seems a bug to me. What do you think?
In case we acknowledge it's a bug I can post an entry in the issue tracker and tonight upload a SLICE with the fix.
Regards, Gabriel
_______________________________________________ Pharo-project mailing list Pharo-project@lists.gforge.inria.fr http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
_______________________________________________ Pharo-project mailing list Pharo-project@lists.gforge.inria.fr http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
hi gabriel
Hi, VA implemented this behavior in the latest releases for Seaside compatibility and their implementation behaves similar to Pharo one.
argh :)
I think that conceptually both methods must return true, but that's my opinion. If we can get to a consensus I can make the necessary changes. So please comment on this!.
I like your point of view. This is logical. Everything starts with nothing :)
Thanks, Gabriel
On Thu, Mar 4, 2010 at 10:40 AM, Julian Fitzell <jfitzell@gmail.com> wrote: I'm not sure, but in ANSI, indexOfSubcollection:startingAt: is defined as returning 0 (no match) for an empty collection.
This doesn't necessarily mean that #beginsWith: needs to return false as well, of course, but it would be another data point. And I just checked VW and it returns true for both #beginsWith: and #endsWith: in this case so that may be an argument the other way (haven't checked Gnu or VA - not sure if they even implement it).
Julian
2010/3/4 Gabriel Cotelli <g.cotelli@gmail.com>:
Hi,
I noticed that 'pharo' beginsWith: '' returns false.
Is that Ok? I expect that this returns true, because the empty string is a prefix (and suffix) of any other string. Similar behavior exhibits endsWith:.
This seems a bug to me. What do you think?
In case we acknowledge it's a bug I can post an entry in the issue tracker and tonight upload a SLICE with the fix.
Regards, Gabriel
_______________________________________________ Pharo-project mailing list Pharo-project@lists.gforge.inria.fr http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
_______________________________________________ Pharo-project mailing list Pharo-project@lists.gforge.inria.fr http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
_______________________________________________ Pharo-project mailing list Pharo-project@lists.gforge.inria.fr http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
Den 04.03.2010 14:40, skrev Julian Fitzell:
I'm not sure, but in ANSI, indexOfSubcollection:startingAt: is defined as returning 0 (no match) for an empty collection.
If a string can not contain the empty string, then how can (and does) it start/end with it? IMHO, to be consistent, the set of what I contain should be a strict superset of what I begin/end with. In that regards, according to the ansi-standard, returning false is correct. Cheers, Henry
ok see '' isDifferentFrom: Character space :) Stupid me Stef On Mar 4, 2010, at 3:27 PM, Henrik Johansen wrote:
Den 04.03.2010 14:40, skrev Julian Fitzell:
I'm not sure, but in ANSI, indexOfSubcollection:startingAt: is defined as returning 0 (no match) for an empty collection.
If a string can not contain the empty string, then how can (and does) it start/end with it? IMHO, to be consistent, the set of what I contain should be a strict superset of what I begin/end with.
In that regards, according to the ansi-standard, returning false is correct.
Cheers, Henry
_______________________________________________ Pharo-project mailing list Pharo-project@lists.gforge.inria.fr http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
Hi Henry, for the ANSI document on indexOfSubcollection:startingAt:, i think that 'aaaaa' indexOfSubcollection: '' startingAt: 1 must return 1, not 0. (and if the argument is empty the starting index must be returned) *Message: indexOfSubCollection: targetSequence startingAt: start Synopsis Answer the index of the first element of the receiver which is the start of a subsequence which matches targetSequence. Start searching at index start in the receiver. Answer 0 if no such subsequence is found. Definition: <sequenceReadableCollection> Each subsequence of the receiver starting at index start is checked for a match with targetSequence. To match, each element of a subsequence of the receiver must be equivalent to the corresponding element of targetSequence. Answer the index of the first element which begins a matching subsequence; no further subsequences are considered. Answer 0 if no such subsequence is found in the receiver, or if targetSequence is empty. The elements are traversed in the order specified by the #do: message for the receiver. * The problem here is probably that subsequence definition is missing in the standard. If an empty sequence is allowed as argument then I think that the index must be the result. ¿Anybody has a formal definition of subsequence? I don't know if the beginsWith: in SequenceableCollection must return true to #(1 2 3) beginsWith: #(), but for String I still think that must do. Obviously there's some part of the protocol that should remain consistent. I will try to analyze that in deeper detail later. Regards, Gabriel On Thu, Mar 4, 2010 at 11:27 AM, Henrik Johansen < henrik.s.johansen@veloxit.no> wrote:
Den 04.03.2010 14:40, skrev Julian Fitzell:
I'm not sure, but in ANSI, indexOfSubcollection:startingAt: is defined as returning 0 (no match) for an empty collection.
If a string can not contain the empty string, then how can (and does) it start/end with it? IMHO, to be consistent, the set of what I contain should be a strict superset of what I begin/end with.
In that regards, according to the ansi-standard, returning false is correct.
Cheers, Henry
_______________________________________________ Pharo-project mailing list Pharo-project@lists.gforge.inria.fr http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
Den 04.03.2010 16:03, skrev Gabriel Cotelli: /*Message: indexOfSubCollection: targetSequence startingAt: start */
/**Start searching at index start in the receiver. Answer 0 if no such subsequence is found. / *snip* / Answer 0 if no such subsequence is found in the receiver, or if targetSequence is empty. /
I don't see how that is ambigous regarding whether an empty collection is defined as a subsequence or not. Cheers, Henry
ouch! I missed that point from the definition :P .... Too bad that beginsWith: is not in the standard... I still feel that 'bbb' beginsWith: '' should return true... but it seems to be incompatible with indexOfSubCollection:startingAt: behavior... Gabriel. 2010/3/4 Henrik Johansen <henrik.s.johansen@veloxit.no>
Den 04.03.2010 16:03, skrev Gabriel Cotelli:
*Message: indexOfSubCollection: targetSequence startingAt: start *
*Start searching at index start in the receiver. Answer 0 if no such subsequence is found. *
*snip*
* Answer 0 if no such subsequence is found in the receiver, or if targetSequence is empty. *
I don't see how that is ambigous regarding whether an empty collection is defined as a subsequence or not.
Cheers, Henry
_______________________________________________ Pharo-project mailing list Pharo-project@lists.gforge.inria.fr http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
participants (4)
-
Gabriel Cotelli -
Henrik Johansen -
Julian Fitzell -
Stéphane Ducasse