Fun with Number readFrom: What should we do ?

nicolas cellier ncellier at ifrance.com
Wed Apr 26 21:34:26 UTC 2006


Hello all,

i noticed that Number readFrom: silently answers 0 when it does not encounter 
some digits:

    Number readFrom: '' readStream.
    Number readFrom: 'foo-bar' readStream.
    Number readFrom: '.' readStream.

will all answer 0. Well, i believe there must have been discussions whether or 
not raising an exception in this case, at least recently in vw list.
But let us say that answering 0 is a feature.


Then try:

    Number readFrom: 'rules are made for the others' readStream.

fail with an error: 'Invalid radix'.
Well, well, don't tell me it is a feature.


And just for fun, this one:

    Number readFrom: '.e' readStream.

ah, another feature UndefinedObject doesNotUnderstand: #digitValue.


Still want to play ? Try this one:

    Number readFrom: '--1' readStream.

Amazing what we can do with just one readFrom:...


Funny, it also accept some un-Smalltalk-ish syntax:

    Number readFrom: '.1e2'.
    Number readFrom: '1.e1'.

will answer a Float (10.0 like FORTRAN).
I suppose this one is intentionnaly a feature.


I will not analyze here the cases when the stream advance, and the cases when 
it does not... That would be boring...


Now i am trying to implement Float readFrom without accumulating rounding 
errors, and this can be the right time for deciding about these cases.

What do you vote for ? exception, answering 0, any other idea ?
What to do with the stream in case of error ? rewind, keep in place ?
I'am waiting for your comments.

Nicolas




More information about the Squeak-dev mailing list