String>>asInteger

Martin Wirblat sql.mawi at t-link.de
Wed Jan 21 13:05:17 UTC 2004


I would clearly rate this a bug, because there are negative Integers 
in class Integer, and the semantics of #asXyz is that Xyz is a class. 
Even in the rest of the computing world Integers mostly if not always 
include negatives. 

Integer readFrom: ( ReadStream on: '-1' ) answers -1, and that is 
the expected implementation. 

Furthermore the compiler converts '-1' to Integer -1, and so should do 
this method. Everything else is totally unexpected.

regards
Martin

Michael Roberts <mike at mjr104.co.uk> wrote on 21.01.2004 12:52:57:
>
>I was wondering if someone might help me out with the intent behind 
>String>>asInteger and String>>asSignedInteger. 
>
>I was puzzled for a while why '-1' asInteger returned '1'.  I was 
>about to ask about this when I stumbled across the second method - 
>aha! 
>
>The code for the two methods is largely identical with 
>asSignedInteger appearing two years later. 
>
>I was wondering why one would not want the signed behaviour most of 
>the time.  Do people always expect this to be unsigned?  I'm sorry if 
>that's a stupid question! 
>
>I was wondering about the consistency:
>-3 asInteger -> -3
>'-3' asInteger -> 3
>-1 asString asInteger -> 1
>
>So I was wondering what the usage would be like if the functionality 
>was reversed and the later called String>>asUnsignedInteger.  
>
>what a lot of wonderng....
>
>Cheers
>
>Mike





More information about the Squeak-dev mailing list