r/Tcl • u/Dechcaudron_ • 20h ago
First release of my Tcl package "overrides", to conveniently override command definitions
Hi all,
I wanted to share the first release of my Tcl package overrides, which enables users to override the definitions of arbitrary commands exclusively during the evaluation of a script in a convenient manner (as convenient as I thought it could be made).
The behavior is similar to what you get with the rename command, except you get all the following advantages:
- The command overrides automatically go out of effect the moment the evaluation of the given script finishes (even if due to an error).
- You can stack multiple override definitions on the same command name, and individual definitions can call those immediately below them in the stack (similar to the behavior of
nextcommand from theTclOObuilt-in package, or to the behavior ofsuperin other object-oriented programming languages). - You may use lambdas (the ones taken by
applyas the first argument) as command overrides instead of procedures, to avoid polluting the namespace of interest.
While my main motivation for developing this package was to help me at work, I would be delighted if others could benefit from it as well. Please, let me know if you check it out and happen to like it, and feel free to open PRs against it in Github.
