NumberParser and exponent

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

NumberParser and exponent

Henrik-Nergaard

Hi,


Apperently the number parser cannot parse '2E+2' correctly, is this a bug or a feature.

('2E+2' asNumber = '2e2' asNumber)


Is there any reason to why parsing numbers with uppercase exponent letter is not allowed? 

(see NumberParser >> #exponentLetters)


The parser has a method named #allowPlusSignInExponent sending self >> #allowPlusSign which just returns false. 

Is there any reason for not allowing the pluss sign / having it as true instead?

(I guess it should at least be an ivar so it can be configured?).


Best regards,

Henrik


Reply | Threaded
Open this post in threaded view
|

Re: NumberParser and exponent

Sven Van Caekenberghe-2
It is all a question of definition, I guess.

(STON fromString: '2e2') = (STON fromString: '2E+2'). => true

(STONJSON fromString: '2e2') = (STONJSON fromString: '2E+2'). => true

(NeoNumberParser parse: '2e2') = (NeoNumberParser parse: '2E+2'). => true

I believe the 'old school' Smalltalk syntax was limited on purpose, to avoid certain ambiguities maybe related to the IDE/tools. It is an open question whether that assumption is still valid.

"Be clean & strict in what you produce, be flexible & liberal in what you accept." is a good motto.

> On 29 Mar 2017, at 13:31, Henrik Nergaard <[hidden email]> wrote:
>
> Hi,
>
> Apperently the number parser cannot parse '2E+2' correctly, is this a bug or a feature.
> ('2E+2' asNumber = '2e2' asNumber)
>
> Is there any reason to why parsing numbers with uppercase exponent letter is not allowed?
> (see NumberParser >> #exponentLetters)
>
> The parser has a method named #allowPlusSignInExponent sending self >> #allowPlusSign which just returns false.
> Is there any reason for not allowing the pluss sign / having it as true instead?
> (I guess it should at least be an ivar so it can be configured?).
>
> Best regards,
> Henrik


Reply | Threaded
Open this post in threaded view
|

Re: NumberParser and exponent

Ben Coman
On Wed, Mar 29, 2017 at 7:59 PM, Sven Van Caekenberghe <[hidden email]> wrote:
> It is all a question of definition, I guess.
>
> (STON fromString: '2e2') = (STON fromString: '2E+2'). => true
>
> (STONJSON fromString: '2e2') = (STONJSON fromString: '2E+2'). => true
>
> (NeoNumberParser parse: '2e2') = (NeoNumberParser parse: '2E+2'). => true
>
> I believe the 'old school' Smalltalk syntax was limited on purpose, to avoid certain ambiguities maybe related to the IDE/tools. It is an open question whether that assumption is still valid.

What was the original assumption/question?
Or do we need to build a planet and wait ten million years for the
white mice to discover this?

> "Be clean & strict in what you produce, be flexible & liberal in what you accept." is a good motto.

So we should allow 2E+2 ?  Its a natural expectation that I think a
few people get hit by.
We have a new compiler which may bypasses the original issue.
One consideration though would be cross-dialect compatibility.
Squeak/Cuis are presumably lowercase only. Anyone know about VW, Dolphin?

cheers -ben

>
>> On 29 Mar 2017, at 13:31, Henrik Nergaard <[hidden email]> wrote:
>>
>> Hi,
>>
>> Apperently the number parser cannot parse '2E+2' correctly, is this a bug or a feature.
>> ('2E+2' asNumber = '2e2' asNumber)
>>
>> Is there any reason to why parsing numbers with uppercase exponent letter is not allowed?
>> (see NumberParser >> #exponentLetters)
>>
>> The parser has a method named #allowPlusSignInExponent sending self >> #allowPlusSign which just returns false.
>> Is there any reason for not allowing the pluss sign / having it as true instead?
>> (I guess it should at least be an ivar so it can be configured?).
>>
>> Best regards,
>> Henrik
>
>