Re: Exception style
Available news archives: comp.lang.tcl - comp.lang.python - comp.security.firewalls - sci.crypt - comp.lang.php - comp.lang.javascript
Google
 
Web news.hping.org


comp.lang.tcl archive

Re: Exception style

From: Fredderic <put_my_name_here@optusnet.com.au>
Date: Sun Apr 30 2006 - 05:24:01 CEST

On Sat, 29 Apr 2006 20:51:48 GMT,
Darren New <dnew@san.rr.com> 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
Received on Sun Apr 30 06:36:23 2006