Re: Silent overriding of the command?

From: Victor Wagner (vitus_at_45.free.net)
Date: 11/13/03


Date: Thu, 13 Nov 2003 15:10:02 +0000 (UTC)

Cameron Laird <claird@lairds.com> wrote:

: I know Victor's experienced with Tcl, and I wonder if there's some
: deeper story afoot here. I've certainly heard others mention re-

Story is just simple:

Some novice user was caught in this trap - he wrote procedure named
"scan" in some Tk script and thus destroyed behavoir of Up/Down arrows
in text widget.

He wrote in Russian Tcl mailing list very complete report of this
problem.

It took me some time to track down cause of error. And this with my
eight years of Tcl experience and some more with full-time work in
softwore engineering.

Earlier today I've discovered that some new commands are available in Tk
8.4 (I forget to upgrade tk8.3-doc package to tk8.4-doc) also with
names which are quite easy to override, such as labelframe.

Now, I've just thought of how easy it is to not remember, or not know
that there is some core command with certain name, which is used in
standard library procedures. There are lot of them in the Tk and they
are quite complex.

You just call your procedure some obvois name, like scan or format, or
seek, and behold - behavoir of standard Tk widgets is broken.

Perl folk give some more thought to this problem. So they provided magic
namespace CORE::, which allows to call standard builtin command even
if user desired to override it in root namespace .

In Tcl such approach possibly would clash with interp alias mechanism,
which is essential for safe interpreters. But something simular is
desirable.

If people want to override behavoir of library routines, they would
override upper level, documented functions, or, in case of Tk, use bind
scripts.

So, it wouldn't harm anybody if internal calls from library scripts
would be explicitely made to core commands.

: I suspect if I spent time, I could find "prior art" for a modified
: [proc] that refuses to overwrite existing commands. It should only
: take a dozen lines, in any case.

Of course, Tcl makes it easy to protect from overriding commands in your
application. If I'd allow user scripting, I probably would use slave
interpreter for it.

But package authors are helpless in this situation. Command can be
overriden even before package, which depends on it, is loaded.

-- 
I think it's a new feature.  Don't tell anyone it was an accident.  :-)
         -- Larry Wall on s/foo/bar/eieio in <10911@jpl-devvax.JPL.NASA.GOV>


Relevant Pages

  • Re: Tcl C extn - Scoping in extended cmds - how to?
    ... no tcl command (C function registered as tcl ... create a new scope, so that it may access all local variables inside ... There are "raw" or low level tcl commands representing the WIN32 API ...
    (comp.lang.tcl)
  • Re: looking for tcl based Cisco like command line interface
    ... TinyTcl and Jim would be fine to save resources, but first is missing some newer tcl sub-/commands and later has no exec-command at all. ... Only want to install one single tcl/etcl/tclkit interpreter and a single tcl script. ... Funny, the cli can be run from any computer remote,using snmp get/get-next/set for communication to the network device, therefore got a remote console program too. ... extreme environments) based on ARM or Coldfire processor using Debian Linux/ucLinux should be extended with a CLI that is similar in behaviour, handling and naming conventions to the well known cisco command line interface (several user-visible application-specific commands, along with a help, different management operation levels like "enable", "config", line driven only, tab expansion, no special graphics or ascii terminal commands) ...
    (comp.lang.tcl)
  • Re: Language Specification - Where is it?
    ... >> the Endekalogue, the semantics aren't described ... > commands have semantics. ... The first is the semantic of the Tcl syntax and the behaviour and order ... all the rest of the language can be in theory implemented using this ...
    (comp.lang.tcl)
  • Re: Constants for catch return values?
    ... > proc like [tokenize]. ... As an aside, in TCL 8.5, I figure you could do the inverse conversion ... 101 commands that each deal with one aspect of it (except where those ... of pattern matching) Two examples of my own; I had a script that had ...
    (comp.lang.tcl)
  • Re: looking for tcl based Cisco like command line interface
    ... commands, along with a help, different management operation levels like ... As tcl is very powerful a smaller tcl to achieve faster startup may be ... cli commands to snmp get/get-next/set. ... is based on tcl it would even be possible to extend the rights of this ...
    (comp.lang.tcl)