Fun with Number readFrom: What should we do ?
Diego Fernandez
diegof79 at gmail.com
Thu Apr 27 13:59:58 UTC 2006
> My proposition is:
>
> Number>>readFrom: aStringOrStream
> ^self readFrom: aStringOrStream ifFail: [^self error: 'cannot read a
> number']
>
> If nil is what you want, you will have to write:
> value := Number readFrom: aStream ifFail: [nil].
> A little longer than your proposition:
> value := Number readfrom: aStream.
The mine is:
Number>>readFrom: aStringOrStream
^NumberParser new parse: aStringOrStream
NumberParser>>parse: aStringOrStream
"on failure"
NumberParsingException signal
"or just ParseException"
I think that #readFrom: must be an extension of Number.
So if you want more control of the parsing you can configure an
instance of NumberParser.
(may be you can have a FortranNumberParser :)).
More information about the Squeak-dev
mailing list
|