namespacex(3tcl)

πŸ“¦
version 2.0 Β· 3 versions
, in debian trixie, ubuntu questing, ubuntu resolute, ubuntu stonking

✨ 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:

  1. Hook commands β€” they provide and manipulate a chain of commands which replaces the single regular namespace unknown handler. (yes, the lone handler got a glow-up and now it's a whole group chat πŸ‘‘)
  2. An import command β€” the ability to import any command from another namespace.
  3. Information commands β€” querying of variables and child namespaces.
  4. State commands β€” a means to serialize variable values in a namespace. (save & restore, but for vibes πŸ”₯)

πŸŽ€ COMMANDS πŸŽ€

  • ::namespacex hook add ?namespace? cmdprefix β€” adds the cmdprefix to the chain of unknown command handlers that get invoked when the namespace would otherwise invoke its unknown handler. if namespace isn't specified, then cmdprefix is 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 command cmdname from the fromns namespace into the namespace of the caller. and the tea is: the cmdname command is imported even if fromns did 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 to namespace, and not fully qualified. (ikyk 😌)
  • ::namespacex normalize namespace β€” returns the absolute name of namespace, 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 the pattern argument is specified, then only variables matching pattern are returned. matching is determined using the same rules as for string 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 in namespaces must be the absolute normalized name of a child namespace of namespace prefix. 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 (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