Colin.
Good heavens, "hidden or handy features."
Well, you did a good job on enumerating the hidden features; the
one you mentioned is the only intentional Easter Egg of which I'm
aware. (Did you know that I fixed a bug in it when I rewrote [clock]
in 8.5?)
As far as *handy* features go - we've got a Wiki full of 'em.
I'm not even sure where to begin without more information about what
the original poster wants to *do*.
--
73 de ke9tv/2, Kevin
Perhaps one can consider the small assortment of "magical" variables,
such as tcl_precision to be hidden features? (Or rather: the fact that
they are "magical").
Regards,
Arjen
>I'm sure you can come up with more answers to this:
>http://stackoverflow.com/questions/1024711/hidden-features-of-tcl
>
So I read the whinges about [expr] and thought for a while,
and then this popped into my head unbidden:
tclsh% proc unknown args {uplevel 1 [linsert $args 0 expr]}
Tcl never ceases to amaze and delight. Now I have a
desk calculator any time I want one, right there on the
tclsh command line. [Yes, I know it's far from perfect...]
--
Jonathan Bromley, Consultant
DOULOS - Developing Design Know-how
VHDL * Verilog * SystemC * e * Perl * Tcl/Tk * Project Services
Doulos Ltd., 22 Market Place, Ringwood, BH24 1AW, UK
jonathan...@MYCOMPANY.com
http://www.MYCOMPANY.com
The contents of this message may contain personal views which
are not the views of Doulos Ltd., unless specifically stated.
That's neat - I posted it on SO.
Colin.
The even neater version
proc unknown args { expr $args }
is already on the Wiki, though I think mine's better :-)
It raises another interesting question, though.
Suppose you have some proc ([unknown] in that case, but
could be anything) that you plan to redefine repeatedly.
And suppose you want to keep the existing implementation
as a fallback, so that each redefinition ADDS some new
capability to the proc:
rename stuff _stuff
proc stuff args {
if {it's a special case} {
do my own thing
} else {
# fall back to existing implementation
uplevel 1 [linsert $args _stuff]; # or uplevel 1 _stuff {*}$args
}
}
Now, suppose I want to be able to do that over and
over again so that I can extend "stuff" as often as I wish.
I need a sort of stack of renames. Is there a really neat
way to do this?
just use [info commands] to see if your renamed stuff exists
and keep changing it (in a repeatable, deterministic way) until
you get to an unused name and then us it as the target of the
rename and fallback call
Bruce
> On Mon, 22 Jun 2009 04:24:16 -0700 (PDT), Colin Macleod wrote:
>
>>I'm sure you can come up with more answers to this:
>>http://stackoverflow.com/questions/1024711/hidden-features-of-tcl
>>
>
> So I read the whinges about [expr] and thought for a while,
> and then this popped into my head unbidden:
>
> tclsh% proc unknown args {uplevel 1 [linsert $args 0 expr]}
>
> Tcl never ceases to amaze and delight. Now I have a
> desk calculator any time I want one, right there on the
> tclsh command line. [Yes, I know it's far from perfect...]
Here's a related page from the Wiki:
tclsh as a powerful calculator
http://wiki.tcl.tk/11933
-George
While we are on the subject of calculators, why not add
http://wiki.tcl.tk/23034 to the lot?
Okay, it is not simply Tcl, but it sure is a nice little trick.
(And http://wiki.tcl.tk/17308 and kin are another unexpected
use of Tcl/Tk ...)
Regards,
Arjen
I'd suggest starting with http://wiki.tcl.tk/2776 which focusses on
[unknown]. The other way (renaming and chaining) can work, but be
careful not to rename from one namespace into another; procedures have
the misfeature that they don't remember what namespace they were
defined in. (Yes, this has annoyed me a lot. I'm told that it can't be
fixed without breaking code...)
Donal.