'-1' asInteger -> 1

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

'-1' asInteger -> 1

GLASS mailing list

'-1' asNumber asInteger -> -1

'-1' asInteger -> 1


Marten


_______________________________________________
Glass mailing list
[hidden email]
http://lists.gemtalksystems.com/mailman/listinfo/glass
Reply | Threaded
Open this post in threaded view
|

Re: '-1' asInteger -> 1

GLASS mailing list
If you think that's bad, try:

'abc123' asNumber

or:

'abc123def456' asNumber

On Mar 8, 2017, at 01:51, Marten Feldtmann via Glass <[hidden email]> wrote:

'-1' asNumber asInteger -> -1

'-1' asInteger -> 1


Marten



Glass mailing list
[hidden email]
http://lists.gemtalksystems.com/mailman/listinfo/glass

_______________________________________________
Glass mailing list
[hidden email]
http://lists.gemtalksystems.com/mailman/listinfo/glass
Reply | Threaded
Open this post in threaded view
|

Re: '-1' asInteger -> 1

GLASS mailing list

Your examples throw exceptions ... seems to be ok for me. '-1' is a correct number ...

Marten

Richard Sargent <[hidden email]> hat am 8. März 2017 um 16:25 geschrieben:

If you think that's bad, try:

'abc123' asNumber

or:

'abc123def456' asNumber



_______________________________________________
Glass mailing list
[hidden email]
http://lists.gemtalksystems.com/mailman/listinfo/glass
Reply | Threaded
Open this post in threaded view
|

Re: '-1' asInteger -> 1

GLASS mailing list
In reply to this post by GLASS mailing list

Richard noticed this back in January[1]. It is related to Pharo compatibility and Richard wrote a note to the Pharo list[2] on the subject, to which Guillermo Polito replied:

>> Now, I'd like to fix this, because it just introduces noise and probably a lot of strange code. But the problem is not fixing it on itself, but checking all possible users relying on such strange behaviour. I bet that fixing it naively could lead to break your image :).

I would suggest using NumberParser (SqNumberParser or ExtendedNumberParser depending upon your needs) for parsing numbers ...

Alternatively you could fix CharacterCollection>>#asInteger to behave as you'd like ... There are close to a hundred senders of #asInteger in my stone, and after a quick scan of the senders I don't see any existing uses of asInteger that rely on the odd behavior --- most appear to expect a string consisting of unsigned digits, which AFAICT is handled correctly by either implementation. But I would be aware that changing the behavior of CharacterCollection>>#asInteger could cause unexpected problems in other libraries ...

Dale

[1] https://github.com/GsDevKit/GsDevKit/issues/94

[2] http://forum.world.st/Can-anyone-explain-asInteger-for-Strings-tc4929502.html


On 03/08/2017 01:51 AM, Marten Feldtmann via Glass wrote:

'-1' asNumber asInteger -> -1

'-1' asInteger -> 1


Marten



_______________________________________________
Glass mailing list
[hidden email]
http://lists.gemtalksystems.com/mailman/listinfo/glass


_______________________________________________
Glass mailing list
[hidden email]
http://lists.gemtalksystems.com/mailman/listinfo/glass