Sujet : Re: Lost in Ashok's teachings
De : rich (at) *nospam* example.invalid (Rich)
Groupes : comp.lang.tclDate : 27. Sep 2024, 03:48:38
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <vd56e6$in6f$1@dont-email.me>
References : 1 2 3 4 5
User-Agent : tin/2.6.1-20211226 ("Convalmore") (Linux/5.15.139 (x86_64))
Luc <
luc@sep.invalid> wrote:
I was aware of math operations, but have used them very rarely if ever,
so I didn't make the connection. Most important, I had no idea we could
overload our entire code with all the math operations by importing a
namespace. I'm not sure I like it, but it's good to know.
Small nitpick, "namespace path" is not "importing a namespace".
Importing is an entirely different operation, with its own command to
cause an 'import' (i.e., 'namespace import').
The "namespace path" works in a way analagous to the "PATH="
environment variable for Unix shells. It gives the Tcl interpreter a
list of "places" to look for commands when your code within the
namespace attempts to call the command. I.e., what it does is when the
command you are calling in your current namespace is not defined in
that same namespace, then the interpreter looks in each namespace in
the "path", and if it finds the command defined in one of those
namespaces, that is the command that gets called.
So, if you have this:
namespace eval ::example {
namespace path {::tcl::mathop}
variable a [+ 3 5]
}
Then what happens when the interpreter is executing the variable
command is it see's a call to "+". So first it looks for:
::example::+
But that is not defined (assume the above is the totality of the
definition of ::example).
So next it looks to each namespace in the "namespace path". I.e. it
now looks for:
::tcl::mathop::+
And since that one *is* defined (by Tcl itself) it then executes
::tcl::mathop::+ with parameters 3 and 5.