Deutsch   English   Français   Italiano  
<vd56e6$in6f$1@dont-email.me>

View for Bookmarking (what is this?)
Look up another Usenet article

Path: ...!weretis.net!feeder8.news.weretis.net!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Rich <rich@example.invalid>
Newsgroups: comp.lang.tcl
Subject: Re: Lost in Ashok's teachings
Date: Fri, 27 Sep 2024 02:48:38 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 43
Message-ID: <vd56e6$in6f$1@dont-email.me>
References: <20240926050422.1458aed9@lud1.home> <ygabk0ahit1.fsf@akutech.de> <20240926101500.51d7520f@lud1.home> <vd4n61$d3p6$1@dont-email.me> <20240926225956.087d515c@lud1.home>
Injection-Date: Fri, 27 Sep 2024 04:48:39 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="dcce1bb59e982dc772b78d51c33e5b9d";
	logging-data="613583"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX1+NoG8plSHc9ypaBm7KPTfY"
User-Agent: tin/2.6.1-20211226 ("Convalmore") (Linux/5.15.139 (x86_64))
Cancel-Lock: sha1:7YiSCQzk9BeU/8VFZji2+a55/uU=
Bytes: 2620

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.