namespacex(3tcl)
β¨ namespacex β Namespace utility commands β¨
okay bestie, welcome to namespacex from the tcllib crew π this is the manual page for it, and yes it is that girl. it's giving "namespaces but make it a whole toolkit".
πΈ 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
π¦ DESCRIPTION π¦
so this package is literally a little bag of utility commands for working with namespaces π
it needs Tcl 8.5 and up (the synopsis says Tcl 8.5 9, no cap), and the package itself is version 0.4 (you can ask for namespacex ?0.4?).
the commands fall into four categories, and honestly, we love a well-organized icon:
- Hook commands β they provide and manipulate a chain of commands which replaces the single regular namespace
unknownhandler. (yes, the lone handler got a glow-up and now it's a whole group chat π) - An import command β the ability to import any command from another namespace.
- Information commands β querying of variables and child namespaces.
- State commands β a means to serialize variable values in a namespace. (save & restore, but for vibes π₯)
π COMMANDS π
::namespacex hook add ?namespace? cmdprefixβ adds thecmdprefixto the chain of unknown command handlers that get invoked when the namespace would otherwise invoke itsunknownhandler. ifnamespaceisn't specified, thencmdprefixis added to the chain of handlers for the namespace of the caller (hi, that's you π«Ά).
the chain of cmdprefix is executed in reverse order of addition, i.e. the most recently added cmdprefix is executed first. when it runs, cmdprefix has additional arguments appended to it, exactly as any namespace unknown handler would get.
::namespacex hook proc ?namespace? arguments bodyβ adds an anonymous procedure to the chain of namespace unknown handlers for the namespace.
if namespace isn't specified, then the handler is added to the chain of handlers for the namespace of the caller.
the arguments and body are specified just like for the core proc command.
::namespacex hook on ?namespace? guardcmdprefix actioncmdprefixβ adds a guarded action to the chain of namespace unknown handlers for the namespace.
if namespace isn't 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 handler in the chain is executed. otherwise, actioncmdprefix is executed, and the return value of the handler is the value returned by actioncmdprefix.
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 so they can execute the next hook in the chain of handlers for the namespace. (pass the mic π€)::namespacex import fromns cmdname ?newname ...?β imports the commandcmdnamefrom thefromnsnamespace into the namespace of the caller. and the tea is: thecmdnamecommand is imported even iffromnsdid not originally export the command. we don't gatekeep πͺβ¨
if newname is specified, then the imported command will be known by that name. otherwise, the command retains its original name as given by cmdname.
additional pairs of cmdname / newname arguments may also be specified.
::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.::namespacex info allvars namespaceβ returns a list containing the names of all variables in the specified namespace and its children. these names are all given relative tonamespace, and not fully qualified. (ikyk π)::namespacex normalize namespaceβ returns the absolute name ofnamespace, which is resolved relative to the namespace of the caller, with all unneeded colon characters removed. so many colons, gone, deleted, not invited ποΈπ::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.::namespacex state get namespaceβ returns a dictionary holding the names and values of all variables in the specified namespace and its child namespaces.
heads up bestie: the names are all relative to namespace, and not fully qualified. don't come for me when you forget this π
::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.::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. (absolute in, relative out, that's the trade π)
π BUGS, IDEAS, FEEDBACK π
ngl, this document, and the package it describes, will undoubtedly contain bugs and other problems. it's giving "we know, we know". please report such in the category namespacex of the Tcllib Trackers at http://core.tcl.tk/tcllib/reportlist. and please also report any ideas for enhancements you may have for either the package and/or the documentation β we want the glow-up suggestions fr fr π«Ά
when proposing code changes, please provide unified diffs, i.e. the output of diff -u.
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 one. the left-most one. π)
β 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
and that's the whole page bestie π this one lives in tcllib, version 0.4, filed under namespacex(3tcl). go forth and namespace responsibly, you absolute main character πβ¨π
π¦ where this page comes from
- debian trixie: tcllib 2.0+dfsg-4 Β· Tcl
- ubuntu questing: tcllib 2.0+dfsg-4
- ubuntu resolute: tcllib 2.0+dfsg-5 Β· Tcl
- ubuntu stonking: tcllib 2.0+dfsg-6 Β· Tcl
- 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