The Inbox: Collections-hk.360.mcz

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

The Inbox: Collections-hk.360.mcz

commits-2
A new version of Collections was added to project The Inbox:
http://source.squeak.org/inbox/Collections-hk.360.mcz

==================== Summary ====================

Name: Collections-hk.360
Author: hk
Time: 20 May 2010, 9:04:53.211 am
UUID: 75c4bea4-ca87-3a40-8a74-e89fc5b7b750
Ancestors: Collections-ul.359

changed String isAllDigits to return false on empty strings

=============== Diff against Collections-ul.359 ===============

Item was changed:
  ----- Method: String>>isAllDigits (in category 'testing') -----
  isAllDigits
+ "whether the receiver is composed entirely of digits and has at least one digit"
- "whether the receiver is composed entirely of digits"
  self do: [:c | c isDigit ifFalse: [^ false]].
+ self ifEmpty: [^false].
  ^ true!


Reply | Threaded
Open this post in threaded view
|

Re: The Inbox: Collections-hk.360.mcz

Frank Shearar
On 2010/05/20 07:05, [hidden email] wrote:

> A new version of Collections was added to project The Inbox:
> http://source.squeak.org/inbox/Collections-hk.360.mcz
>
> ==================== Summary ====================
>
> Name: Collections-hk.360
> Author: hk
> Time: 20 May 2010, 9:04:53.211 am
> UUID: 75c4bea4-ca87-3a40-8a74-e89fc5b7b750
> Ancestors: Collections-ul.359
>
> changed String isAllDigits to return false on empty strings
>
> =============== Diff against Collections-ul.359 ===============

Isn't the problem that the caller wants to know that some string
contains a number (in base 10, presumably)?

It seems perfectly sensible that '' isAllDigits returns true - because
it's vacuously true.

So shouldn't there be (and I haven't looked for existing functionality)
something like String>>isNumeric which says self isEmpty and: [self
isAllDigits] ?

I'm torn between my sense of logic and my desire to avoid bikeshedding.

frank

Reply | Threaded
Open this post in threaded view
|

Re[2]: [squeak-dev] The Inbox: Collections-hk.360.mcz

Herbert König
Hello Frank,


FS> Isn't the problem that the caller wants to know that some string
FS> contains a number (in base 10, presumably)?

no, it's deeper, a number may have sign, decimal separator .....

FS> It seems perfectly sensible that '' isAllDigits returns true - because
FS> it's vacuously true.

The change arose from the fact that I have written:

(aString notEmpty and: [aString isAllDigits]) if True: []

in various applications for e.g. 10 being valid for 10 o'clock or -,4
being a valid float.

FS> So shouldn't there be (and I haven't looked for existing functionality)
FS> something like String>>isNumeric which says self isEmpty and: [self
FS> isAllDigits] ?

Something like that would be my next resort, but "isNumeric" is
misleading as it's also true for '-3'.

FS> I'm torn between my sense of logic and my desire to avoid bikeshedding.

The reason to discuss it is, it might break existing code. My logic
would be that isAllDigits is a pointed form of isDigits and
'' isDigits is undoubtedly false (or so I hope).

At least I found a good name if I have to add yet another method to
String.



Cheers,

Herbert


Reply | Threaded
Open this post in threaded view
|

Re: The Inbox: Collections-hk.360.mcz

Andreas.Raab
On 5/20/2010 11:29 AM, Herbert König wrote:

> FS>  So shouldn't there be (and I haven't looked for existing functionality)
> FS>  something like String>>isNumeric which says self isEmpty and: [self
> FS>  isAllDigits] ?
>
> Something like that would be my next resort, but "isNumeric" is
> misleading as it's also true for '-3'.
>
> FS>  I'm torn between my sense of logic and my desire to avoid bikeshedding.
>
> The reason to discuss it is, it might break existing code. My logic
> would be that isAllDigits is a pointed form of isDigits and
> '' isDigits is undoubtedly false (or so I hope).

Yeah, it's an interesting semantic difference. Do we mean the method to
imply that "each character is a digit" (false for an empty string) or do
we mean "there are no non-digits characters in it" (true for an empty
string). I would lean towards the former but the argument for the latter
can certainly be made.

Cheers,
   - Andreas