[ENH] Case independent numbers

Bert Freudenberg bert at isgnw.CS.Uni-Magdeburg.De
Wed Mar 1 10:23:07 UTC 2000


On Mon, 28 Feb 2000, Dan Ingalls wrote:

> >who of you really would expect that 16r1e5 equals 1048576 while 16r1E5 is
> >485? If not too many, I propose to make hex numbers case independent, and
> >exponent notation, too. 
> 
> I have a problem with this, Bert.
> The way it is, there is a simple syntactic rule for numbers.
> Your changes imply a rule that is not syntactic, but value-dependent:
> 
> 16r1E5 = 485, but
> 14r1E5 = 537824

I know. But the current solution is value-dependent, too. 14r1E5,
according to syntactic rules, is a number. But if parsed, it is a message
send with selector #E5 to the number 14r1. (I'm referring to
http://minnow.cc.gatech.edu/squeak/SqueakLanguageDefinition).

I just keep running into case problems because I usually use lower
case letters in hex numbers. It took me ten minutes to find out why the
html color code "#00ee00" was not green.

What if we define that the exponent notation is only valid if the base is
<= 10? It's a semantic, value dependant rule, more flexible, but IMHO not
more ambiguous than the current one. Exponent notation is only currently
used for base 10 floats and base 2 integers, so we wouldn't break
anything.

The current definition for number is
--------old--------
number = [radix "r"]["-"]digits["." digits]["e"["-"]exponent].

NOTE: the set of digits allowed in a number of radix N is the first N
characters of the string '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'; default
radix = 10, for all others you must explicitly specify the radix;

digit = decimal_digit | uppercase.
--------old--------

This could be changed to:

--------new--------
number = [radix ("R"|"r")]["-"]digits["." digits][("E"|"e")["-"]exponent].

NOTE: the set of digits allowed in a number of radix N is the first N
characters of the string '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ' in upper
or lower case; the exponent notation is only allowed if radix is <= 10; 
default radix = 10, for all others you must explicitly specify the radix;

digit = decimal_digit | letter.
--------new--------

What does the ANSI standard say? I guess it's the "old" definition. But
even then, if exporting to the Smalltalk interchange format, literals
could be brought into the canonical form.

  -Bert-





More information about the Squeak-dev mailing list