Tcl Source Code

View Ticket
Login
Ticket UUID: 625103
Title: more ways to avoid shimmering
Type: RFE Created on: 2002-10-18 08:41:35
Submitter: jcw Assigned to: msofer
Subsystem: 47. Bytecode Compiler Severity:
Priority: 6 Last modified: 2008-07-30 07:06:16
Status: Open Closed by:
Resolution: None Closed on:
Version: None
Description:
Snipped from an email sent to Miguel, repeated here for persistence...

I worry about shimmering a lot.  One that really annoys me is creating strings from ints.  Not even losing the internal representation, but simply the fact of having to turn an int into a string to be usable in contexts like:
if {$a eq ""} { ... }
Or in the case I need now:
if {$a eq "#"} { ... }

The point being that since neither of the above is a possible int, there is not even a point in forcing an int-to-string conversion to perform the comparison.  In other words: one operand is of type X, while the other is constant and not possibly convertible to type X.

It may seem like a very special case, but in what I'm doing ints matter a lot - as loopign construct iterators, and list/vector indices.

Here's a more common example, in today's Tcl world, I suppose:
if {$a eq "end"} { ... }

The point is that it would be nice as optimization to decide that things cannot possibly match, without necessarily bringing them into the same type, not even both as strings.

Much further down the line, perhaps 9.0 timeframe, one could consider adding an extra member to the existing 4 dispatch functions of each type, being a function which takes an object, and returns false *QUICKLY* if the given object is most certainly not convertible to that type.  It might even be generalized to strings - meaning an object has no string rep and hence must be treated as precious (and non-writable, non persistable, etc).  It is then up to each type to implement as sophisticated checks as it likes - i.e. the int type could reject objects which have a string rep right now, but which do not start with +-0--9.  But that's just a start - it could also reject list objects if their size is anything but one element.  Both checks are really cheap.