[ENH] floatGlobals-ls

Lex Spoon lex at cc.gatech.edu
Fri Sep 17 09:24:40 UTC 2004


It bothers me that the print string of [Float infinity] is 'Infinity',
but you cannot evaluate 'Infinity'; it comes out as an undeclared global
variable.  Additionally, I find "infinity" to be a useful concept even
when working with integers; it seems awkward to write "Float infinity"
in the middle of a bunch of integer operations, especially since we
don't necessarily need to implement infinity using floats.

This changeset fixes the above situation in one simple way: it adds a
global variable named #Infinity.  It also adds NaN while at it. 
Unfortunately, this does not handle '-Infinity', because the Squeak
compiler only does unary negation for numbers, not on general
expressions.

Does anyone have a feel for whether things like [-(x + y)] should be
considered proper Smalltalk code?  If so, then this changeset is
complete and we just need to tweak the parser.  But, for example, does
Tony Hannon's new compiler already generalize in this way?

If [-(x+y)] is not proper Smalltalk code (and I'm sympathetic to the
idea, simply to keep the grammer small), then I suggest we tweak the
parser in a different way and have it recognize [-Infinity] as a single
literal, just the way it does with [-3] or [-99.44].  This is also
consistent with the Smalltalk strategy of having tremendously
complicated literals in order to keep to keep the syntax simple.


Either way, this changeset is incomplete, but I thought I'd share the
two-line thing as food for thought.

"Change Set:		floatGlobals-ls
Date:			17 September 2004
Author:			Lex Spoon

Adds globals variables Infinity and NaN.  This makes most floats print
out to something that is re-readable.  An exception is -Infinity, which
still does not evaluate."
-------------- next part --------------
A non-text attachment was scrubbed...
Name: floatGlobals-ls.cs.gz
Type: application/octet-stream
Size: 303 bytes
Desc: not available
Url : http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20040917/ca1679f8/floatGlobals-ls.cs.obj


More information about the Squeak-dev mailing list