Version 4 of Pure numbers

Updated 2002-12-24 18:39:36

FW: A "pure number" (compare pure list) is a number with no string representation in memory (though of course it can be manipulated as a string - and the second it is, it gains a string form).

Any integer value computed by Tcl rather than provided by the user will be in pure integer form. The easy way to attain this is taking a numeric value (let's call it x) and performing an incr x 0, which will cause Tcl to compute the value of $x plus zero (which is hopefully just $x), and since the result iks a number computed by Tcl, there's no need for a string form.

The situation where this is needed is arcane indeed, though - since invoking expr to perform any calculation on a value will also do this (as long as you do actually perform some operation - if it's just expr {$x} that wouldn't cause Tcl to calculate anything, so it would just return the original value of $x intact). Presumably every time you create an integer you're going to be performing some calculation on it, so the times when you'll need to use the incr technique are few and far between.

The only time I could think of when doing this would be productive is when one is reading a large number of large numbers from a file into a list or such, without necessarily changing their value, and doesn't want to take up much memory.

Donal Fellows (whose explanations were mighty helpful in the creation of this page) points out, however, that if you take into account Tcl_Obj overhead, the most a string representation could add - for an integer, at least - is a 2x gain in memory profile.