'.5' asNumber gives an error

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

'.5' asNumber gives an error

James Foster-3
Adding a '0' to the beginning of the string fixes the error.

String>>asNumber
"Handle '.5' as a number"

^Number fromString: '0' , self

James Foster
Fargo, North Dakota, USA


Reply | Threaded
Open this post in threaded view
|

Re: '.5' asNumber gives an error

Bill Dargel
James Foster wrote:
> Adding a '0' to the beginning of the string fixes the error.
>
> String>>asNumber
> "Handle '.5' as a number"
>
> ^Number fromString: '0' , self

This reminds me that some time ago I achieved a similar result by making
a tweak to the Number class>>readSmalltalkSyntaxFrom: method. There's
something to be said for making the change at the lower level. For
instance Number>>readFrom: can also be used to read numbers in the ".5"
format.

This came up for me a couple of years ago when reading files that had
been creating using VisualBasic. Seems that VB's default in printing
floating point numbers between 0 and 1 was to leave off the '0' from in
front of the decimal point.

I wonder if allowing this number format is something that Object Arts
should incorporate into the base image?
 
-------------------------------------------
Bill Dargel            [hidden email]
Shoshana Technologies
100 West Joy Road, Ann Arbor, MI 48105  USA


Reply | Threaded
Open this post in threaded view
|

Re: '.5' asNumber gives an error

Ian Bartholomew-18
Bill,

> I wonder if allowing this number format is something that Object Arts
> should incorporate into the base image?

IMHO the ability to automatically convert from a non standard format [1]
doesn't really belong in the base image, at least not as part of the
default implementation of Number>>fromString:.  I would have thought it
better to add as a "per occasion" thing, in the same way that you now
have to add methods if you want to convert number strings that terminate
with non numeric characters.

[1] The ANSI spec (3.5.6) states "The decimal point must be preceded and
followed by at least one digit"

--
Ian

Use the Reply-To address to contact me.
Mail sent to the From address is ignored.


Reply | Threaded
Open this post in threaded view
|

Re: '.5' asNumber gives an error

Blair McGlashan-2
In reply to this post by Bill Dargel
"Bill Dargel" <[hidden email]> wrote in message
news:[hidden email]...

> James Foster wrote:
> > Adding a '0' to the beginning of the string fixes the error.
> >
> > String>>asNumber
> > "Handle '.5' as a number"
> >
> > ^Number fromString: '0' , self
>
> This reminds me that some time ago I achieved a similar result by making
> a tweak to the Number class>>readSmalltalkSyntaxFrom: method. There's
> something to be said for making the change at the lower level. For
> instance Number>>readFrom: can also be used to read numbers in the ".5"
> format.
> ...
> I wonder if allowing this number format is something that Object Arts
> should incorporate into the base image?

As Ian points out, this is not an error. Number>>fromString:, and the
subsidiary methods it relies on, are designed to read numbers in Smalltalk
syntax only. In fact these methods form the basis of the Compiler's parsing
of numbers, so this will certainly not be changing.

Regards

Blair