namespacex(n)
β¨ namespacex(n) β Namespace utility commands β¨
okay bestie, sit down, hydrate, because we're about to talk about namespaces and honestly? this little package ate. it's called namespacex, it lives in the n manual section, and it's giving "I have a whole toolbox and I'm not afraid to use it" π
πΈ SYNOPSIS πΈ
package require Tcl 8.5 9
package require namespacex ?0.4?
::namespacex hook add ?namespace? cmdprefix
::namespacex hook proc ?namespace? arguments body
::namespacex hook on ?namespace? guardcmdprefix actioncmdprefix
::namespacex hook next arg...
::namespacex import fromns cmdname ?newname ...?
::namespacex info allchildren namespace
::namespacex info allvars namespace
::namespacex normalize namespace
::namespacex info vars namespace ?pattern?
::namespacex state get namespace
::namespacex state set namespace dict
::namespacex state drop namespace
::namespacex strip prefix namespaces
like. look at that list. it's a whole personality. π
π DESCRIPTION π
so this package hands you a bunch of utility commands for working with namespaces, and the way it organizes them is four whole categories, bestie:
- Hook commands β these provide and manipulate a chain of commands which replaces the single regular namespace unknown handler. yes, the ONE handler. we're upgrading it to a whole squad. π
- An import command β gives you the ability to import any command from another namespace. any. of. them. no gatekeeping. π¦
- Information commands β for querying variables and child namespaces. nosy in the best way. π
- State commands β a means to serialize variable values in a namespace. save it, load it, iconic. πΎ
π COMMANDS π
::namespacex hook add ?namespace? cmdprefixβ Adds thecmdprefixto the chain of unknown command handlers that get invoked when the namespace would otherwise invoke its unknown handler. Ifnamespaceisn't specified, thencmdprefixis added to the chain of handlers for the namespace of the caller. (yeah, it just knows where you are. main character energy.)
The chain of cmdprefix are executed in reverse order of addition, i.e. the most recently added cmdprefix is executed first. When executed, cmdprefix has additional arguments appended to it as would any namespace unknown handler. so it's last-in-first-out, no cap.
::namespacex hook proc ?namespace? arguments bodyβ Adds an anonymous procedure to the chain of namespace unknown handlers for the namespace.
If namespace is not specified, then the handler is added to the chain of handlers for the namespace of the caller.
The arguments and body are specified as for the core proc command. same rules, same energy.
::namespacex hook on ?namespace? guardcmdprefix actioncmdprefixβ Adds a guarded action to the chain of namespace unknown handlers for the namespace.
If namespace is not specified, then the handler is added to the chain of handlers for the namespace of the caller.
The guardcmdprefix is executed first. If it returns a value that can be interpreted as false, then the next unknown hander in the chain is executed. Otherwise, actioncmdprefix is executed and the return value of the handler is the value returned by actioncmdprefix. it's giving "bouncer at the door" honestly πͺ
When executed, both guardcmdprefix and actioncmdprefix have the same additional arguments appended as for any namespace unknown handler.
::namespacex hook next arg...β This command is available to namespace hooks to execute the next hook in the chain of handlers for the namespace. it's the "okay next π " button.::namespacex import fromns cmdname ?newname ...?β Imports the commandcmdnamefrom thefromnsnamespace into the namespace of the caller. Thecmdnamecommand is imported even if thefromnsdid not originally export the command. yeah. we don't care about export lists here, we're built different.
If newname is specified, then the imported command will be known by that name. Otherwise, the command retains is original name as given by cmdname.
Additional pairs of cmdname / newname arguments may also be specified. bring the whole friend group, why not.
::namespacex info allchildren namespaceβ Returns a list containing the names of all child namespaces in the specified namespace and its children. The names are all fully qualified. every last one of them, full name, no nicknames. β::namespacex info allvars namespaceβ Returns a list containing the names of all variables in the specified namespace and its children. The names are all given relative tonamespace, and not fully qualified. (yes, this is the opposite ofallchildren. no, we don't make the rules. π« )::namespacex normalize namespaceβ Returns the absolute name ofnamespace, which is resolved relative to the namespace of the caller, with all unneeded colon characters removed. decluttered. self-care. β¨::namespacex info vars namespace ?pattern?β Returns a list containing the names of all variables in the specified namespace. If thepatternargument is specified, then only variables matchingpatternare returned. Matching is determined using the same rules as forstring match. so glob away bestie π::namespacex state get namespaceβ Returns a dictionary holding the names and values of all variables in the specified namespace and its child namespaces.
Note that the names are all relative to namespace, and not fully qualified. don't forget this or you'll be sad, fr fr π
::namespacex state set namespace dictβ Takes a dictionary holding the names and values for a set of variables and replaces the current state of the specified namespace and its child namespaces with this state. The result of the command is the empty string.::namespacex state drop namespaceβ Unsets all variables in the specified namespace and its child namespaces. The result of the command is the empty string. it's giving "delete the whole group chat" π::namespacex strip prefix namespacesβ Each item innamespacesmust be the absolute normalized name of a child namespace of namespaceprefix. Returns the corresponding list of relative names of child namespaces. chop chop βοΈ
π«Ά BUGS, IDEAS, FEEDBACK π«Ά
okay so real talk: this document, and the package it describes, will undoubtedly contain bugs and other problems. lowkey inevitable. Please report such in the category namespacex of the Tcllib Trackers at http://core.tcl.tk/tcllib/reportlist. Please also report any ideas for enhancements you may have for either package and/or documentation β we want the glow-up ideas, bestie, bring them.
When proposing code changes, please provide unified diffs, i.e the output of diff -u. it's the love language of maintainers. π§
Note further that attachments are strongly preferred over inlined patches. Attachments can be made by going to the Edit form of the ticket immediately after its creation, and then using the left-most button in the secondary navigation bar. (yes, that specific button. the left-most one. we love a precise instruction.)
π KEYWORDS π
extended namespace, info, namespace unknown, namespace utilities, state (de)serialization, unknown hooking, utilities
π COPYRIGHT π
Copyright (c) 200? Neil Madden (http://wiki.tcl.tk/12790) Copyright (c) 200? Various (http://wiki.tcl.tk/1489) Copyright (c) 2010 Documentation, Andreas Kupries
aaaand that's the whole thing, bestie!! this page is from tcllib, version 0.4, and it goes by namespacex(n). now go forth and hook your unknowns responsibly ππΈππ¦β¨
π¦ where this page comes from
- fedora 43: tcllib 2.0-3.fc43 Β· TCL
- fedora 44: tcllib 2.0-4.fc44 Β· TCL
- nixos 26.05: tcllib 2.0
- nixpkgs unstable: tcllib 2.0
- Copyright (c) 2010 Documentation, Andreas Kupries
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms