Re: Exception style
- From: Fredderic <put_my_name_here@xxxxxxxxxxxxxxx>
- Date: Sun, 30 Apr 2006 13:24:01 +1000
On Sat, 29 Apr 2006 20:51:48 GMT,
Darren New <dnew@xxxxxxxxxx> wrote:
I am for having a -nocomplain (or any other name) switch :)I think that makes much more sense for commands that take variable
names rather than values. It's not uncommon that I accidentally [incr
$x] when I meant [incr x]. Right now, that usually gets caught.
I actually have a favourite little proc of mine to handle times when I
*do* want automatic initialisation...
proc incr2 {vari {incr 1} {init *} } {
upvar 1 $vari var
if { ! [catch [list incr var $incr] res] } {return $res}
if { [string is digit -strict $init] } {return [set var $init]}
set var $incr
}
There are probably better ways to do it, but it neatly handles every
case I've ever needed it to, including cases where the increment
value isn't obvious. That proc has a default "initialiser" value of
zero (pre-incr), but if you want it to be something different, you just
set it to exactly what you want it to be.
But I still use the standard [incr] wherever possible for exactly the
reason Darren mentioned (I've thrown a value at [incr] rather than the
variable name far too many times, and having TCL spit it back at me
is rather handy in a large script).
Fredderic
.
- References:
- Tcl/Tk 8.5a4 released
- From: Don Porter
- Re: Tcl/Tk 8.5a4 released
- From: pedietz
- Re: Tcl/Tk 8.5a4 released
- From: Michael Schlenker
- Exception style (was: Tcl/Tk 8.5a4 released)
- From: Cameron Laird
- Re: Exception style (was: Tcl/Tk 8.5a4 released)
- From: Wojciech Kocjan
- Re: Exception style
- From: Darren New
- Tcl/Tk 8.5a4 released
- Prev by Date: Re: Handling paths of length > 260 in Tcl on Windows
- Next by Date: Re: Handling paths of length > 260 in Tcl on Windows
- Previous by thread: Re: Exception style
- Next by thread: Re: Tcl/Tk 8.5a4 released
- Index(es):
Relevant Pages
|