QUES: 'abc' asNumber => 0 ?

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

QUES: 'abc' asNumber => 0 ?

John Treble


Why does VW 7.4 return 0 for expressions like:
        'abc' asNumber
        '&$#' asNumber...

I was expecting an error (which is what I get using Dolphin 6 and Squeak
3.7).  Thanks.


John Treble
Ottawa, Ontario, Canada




Reply | Threaded
Open this post in threaded view
|

AW: QUES: 'abc' asNumber => 0 ?

Georg Heeg
John,

When you debug the code you can see all the details. Basically the system
creates a readstream on the string and reads as many digits it finds. As
there are no digits there the number is 0.

Georg

-----Ursprüngliche Nachricht-----
Von: John Treble [mailto:[hidden email]]
Gesendet: Montag, 10. April 2006 18:41
An: [hidden email]
Betreff: QUES: 'abc' asNumber => 0 ?



Why does VW 7.4 return 0 for expressions like:
        'abc' asNumber
        '&$#' asNumber...

I was expecting an error (which is what I get using Dolphin 6 and Squeak
3.7).  Thanks.


John Treble
Ottawa, Ontario, Canada





Reply | Threaded
Open this post in threaded view
|

Re: QUES: 'abc' asNumber => 0 ?

Vassili Bykov
In reply to this post by John Treble
John Treble wrote:
>
> Why does VW 7.4 return 0 for expressions like:
> 'abc' asNumber
> '&$#' asNumber...
>
> I was expecting an error (which is what I get using Dolphin 6 and Squeak
> 3.7).  Thanks.

For historical reasons. This is how that method (or rather Number
class>>readFrom: that does the real work) was defined in Smalltalk-80
when there were no real exceptions. Fixing something like this is not
easy with 20 years' worth of customer code potentially relying on quirky
behavior.

--
Vassili Bykov <[hidden email]>

[:s | s, s printString] value: '[s: | s, s printString] value: '

Reply | Threaded
Open this post in threaded view
|

RE: QUES: 'abc' asNumber => 0 ?

John Treble


Thanks Vassili.

John Treble
Ottawa, Ontario, Canada


-----Original Message-----
From: Vassili Bykov [mailto:[hidden email]]
Sent: April 10, 2006 1:00 PM
To: [hidden email]
Cc: [hidden email]
Subject: Re: QUES: 'abc' asNumber => 0 ?

John Treble wrote:
>
> Why does VW 7.4 return 0 for expressions like:
> 'abc' asNumber
> '&$#' asNumber...
>
> I was expecting an error (which is what I get using Dolphin 6 and Squeak
> 3.7).  Thanks.

For historical reasons. This is how that method (or rather Number
class>>readFrom: that does the real work) was defined in Smalltalk-80
when there were no real exceptions. Fixing something like this is not
easy with 20 years' worth of customer code potentially relying on quirky
behavior.

--
Vassili Bykov <[hidden email]>

[:s | s, s printString] value: '[s: | s, s printString] value: '