Emulating Closures in Tcl: A Clever Hack

2025-05-03

This article explores implementing closure-like behavior in Tcl, a language lacking native closure support. The author cleverly leverages namespaces and the TclOO object system to create a class that mimics closures. This class captures external variables and maintains their validity outside their original scope, effectively achieving closure-like functionality. While differing slightly from C++ closures, this approach provides a practical solution for those needing closures in Tcl.

Read more
Development

Keyword Parameters in Tcl Procs: An Elegant Solution and a Metaprogramming Headache

2025-04-21

Frustrated by the lack of keyword parameters and the inaccessibility of built-in features in some programming languages, the author tackled the challenge of implementing keyword parameters in Tcl. The article presents a clever `proc*` command enabling keyword arguments in Tcl procs and details its implementation. However, due to Tcl's weak metaprogramming capabilities, the author resorted to regular expressions for string templating, resulting in complex and unwieldy code, highlighting Tcl's limitations in metaprogramming.

Read more
Development keyword parameters