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."
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.
Another option is to change the printString for [Infinity negated] to be 'NegativeInfinity', and to create a NegativeInfinity global. Which is consistent with the naming of the class variables in Float
--- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.716 / Virus Database: 472 - Release Date: 08/07/2004
I would like to raise two points from your design.
I am really wondering the reason of adding a new global variable named Infinity. Adding such a global bindings with such a generic name looks like dangerous for me. If it is needed to have an infinity even with integer, why not to add it in the class Number? It seems that it makes things easier regarding the evaluation of string. I do not see this need strong enough to add new global variables. We have SmallInteger>>maxVal, why not to have Float>>infinity (without having ^ Infinity as implementation)
Changing the grammar in order to handle infinity easier? I am really against this proposition.
Note that I did not see the code (I can read it using the "code" button in the file list browser).
humm... When I reread my post, I think that I was perhaps too crude. If it is the case, I did not want. The late hours might probably be some something...
Regards, Alexandre
On Sun, Sep 19, 2004 at 10:58:06PM +0200, bergel@iam.unibe.ch wrote:
I would like to raise two points from your design.
I am really wondering the reason of adding a new global variable named Infinity. Adding such a global bindings with such a generic name looks like dangerous for me. If it is needed to have an infinity even with integer, why not to add it in the class Number? It seems that it makes things easier regarding the evaluation of string. I do not see this need strong enough to add new global variables. We have SmallInteger>>maxVal, why not to have Float>>infinity (without having ^ Infinity as implementation)
Changing the grammar in order to handle infinity easier? I am really against this proposition.
Note that I did not see the code (I can read it using the "code" button in the file list browser).
squeak-dev@lists.squeakfoundation.org