Re: Tcl/Tk 8.5a4 released



pedietz@xxxxxxxx schrieb:
* [TIP 215] Made [incr] auto-initialize.

Isnt this also a POTENTIAL_INCOMPATIBILITY ??

I have code that does:

if { [catch {incr BOB($x)} ] } {
set BOB($x) 1
#do other things because we know this is the 1st occurence of $x
lappend things $x
}


What if you added a flag instead ?

incr -noerror BOB($x) 1

Adding a flag instead was discussed, see the appropriate messages in the
Tclcore mailing list and in the TIP itself.
http://www.tcl.tk/cgi-bin/tct/tip/215.html

Yes, this is a potential incompatibility.

You can work around it in your code by redefining incr to throw an error
with non-existing vars.

One reason to really check what you want to know and not some side
effects of another command. [info exists BOB($x)] would be safer.

One could change your code to this style:
if {1 == [incr BOB($x)]} {
....
}

Depending on the amount of non-existing to existing vars this may be
quite a bit faster too.

Michael


.


Quantcast