String -> Integer

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

String -> Integer

Ian Bartholomew-3
I'm not saying this is an error, it's obviously a deliberate modification,
but I was just wondering if there was any particular reason for the change?

Integer fromString: '23 24 25'
IntegerToText new convertFromRightToLeft: '23 24 25'

both will now fail as the String is not fully read before a non digit is
found.  In previous versions they would just answer the conversion of
characters up to the first non digit.

I was also wondering if the second example shouldn't answer a right
exc^H^H^H null value rather than raising an error?

Regards
    Ian


Reply | Threaded
Open this post in threaded view
|

Re: String -> Integer

Blair McGlashan
Ian

You wrote in message news:[hidden email]...
> I'm not saying this is an error, it's obviously a deliberate modification,
> but I was just wondering if there was any particular reason for the
change?

It is deliberate, though it seems to have bypassed the release notes.

(Integer fromString: aString) asString = aString

Should always be true. This also prevents any confusion over cases such as:

Integer fromString: '1A'.        "hex?"
Integer fromString: ''.            "0 or nil or an error"
Integer fromString: '1.4'.        "1"
Integer fromString: '1.6'.        "1, ignoring the .6, or 2 rounding it up"

One can simulate the previous behaviour as follows:

    Integer readFrom: aString readStream

This reads the first first integer off the stream, or answers 0 if there
isn't one. One can determine whether there was or wasn't actually an integer
by examining the stream position.

>
> Integer fromString: '23 24 25'
> IntegerToText new convertFromRightToLeft: '23 24 25'
>
> both will now fail as the String is not fully read before a non digit is
> found.  In previous versions they would just answer the conversion of
> characters up to the first non digit.
>
> I was also wondering if the second example shouldn't answer a right
> exc^H^H^H null value rather than raising an error?

There was (and is) confusion over the meaning of the 'exceptional' value,
hence it being renamed to the 'null' value. Its purpose was not to fill in
when the text could not be converted, but (for example) to convert from nil
to the empty string, and vice versa.

Regards

Blair


Reply | Threaded
Open this post in threaded view
|

Re: String -> Integer

Ian Bartholomew-3
Blair,

> It is deliberate, though it seems to have bypassed the release notes.

Thanks for the reply, it all makes good sense. It will also teach me (again)
not to take coding shortcuts relying on undocumented behaviour!.

Regards
    Ian