manju sharma
manju sharma

Reputation: 35

Namespaces in TCL

I was reading about namespaces in TCL from the book Practical Programming in TCL The chapter opens up with the paragraph shown in the attached image : enter image description here

I have a doubt related to the second paragraph where author stated that "one global namespace for procedures" My doubt is : We have a global scope (where we can define procedures and variables) , local scope within procedures , and some namespaces (inside the global namespace , ::Namespc1) if we further create any namespaces. Then what is the author referring to by the same statement which I mentioned above ?

Please help me understand this.

Thanks

Upvotes: 0

Views: 156

Answers (2)

Alex P
Alex P

Reputation: 96

You might also acquire "The Tcl Programming Language: A Comprehensive Guide":

https://www.magicsplat.com/ttpl/index.html

It is really comprehensive and modern.

Upvotes: 0

Donal Fellows
Donal Fellows

Reputation: 137557

Originally, before Tcl 8.0, commands were all placed in the global scope, and variables were either in the global scope or local to a procedure. With Tcl 8.0, namespaces were introduced (they were adaptations of a feature that had previously been an extension) and the global scope became the global namespace. The only truly special features of the global namespace by comparison with all its children are that it is where commands are looked up by default when not found in the current namespace, and it is where the global command looks up variables.

These days, both scopes and namespaces are things that can be on the stack. The difference between them is that scopes are unnamed temporary things associated with a running procedure (or lambda or method; these use the same machinery under the hood) and namespaces are named permanent things that last until deleted. Also, scopes can only hold variables and are always associated with a particular namespace; for procedures, that's the namespace that the procedure's been placed within, for lambdas, that's the namespace that is declared in the descriptor (or the global namespace if none is given), and for methods, that's the namespace of the current instance object.

There are other things going on as well, but you can usually ignore them.

Upvotes: 2

Related Questions