Re: Tcl/Tk 8.5a4 released
- From: Michael Schlenker <schlenk@xxxxxxxxxxxxxxxx>
- Date: Fri, 28 Apr 2006 20:21:27 +0200
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
.
- Follow-Ups:
- Re: Tcl/Tk 8.5a4 released
- From: pedietz
- Exception style (was: Tcl/Tk 8.5a4 released)
- From: Cameron Laird
- Re: Tcl/Tk 8.5a4 released
- References:
- Tcl/Tk 8.5a4 released
- From: Don Porter
- Re: Tcl/Tk 8.5a4 released
- From: pedietz
- Tcl/Tk 8.5a4 released
- Prev by Date: Re: Tcl/Tk 8.5a4 released
- Next by Date: Re: Using foreach loop to create radiobutton menu
- Previous by thread: Re: Tcl/Tk 8.5a4 released
- Next by thread: Exception style (was: Tcl/Tk 8.5a4 released)
- Index(es):