## Version 7 of Pure numbers

Updated 2003-01-22 21:41:48

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 as soon as it is, it gains a string form).

Any integer value computed by the Tcl interpreter 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 is 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.