Remix.run Logo
zvr 21 hours ago

Besides Tk and the ease of creating GUIs, Tcl has some unique advantages. As I have written before, a favorite of mine, which I have not found in other languages (besides LISP, obviously) is the ability to treat data as code combined with the existence of safe slave interpreters.

This is extremely useful for configuration files: they can use some functions you have defined, but may also include arbitrary code. In order to load them, you simply fire up a safe slave interpreter to execute the code and you're done!

Imagine a config file like:

    host machine.example.org
    port 9000
    dbhost server.example.org
This can obviously be manually parsed easily, but this is also valid Tcl code, if one has defined the functions "host", "port", and "dbhost". And this allows people to extend the config file to something like:

    set mydomain example.org
    set type prod
    host machine.$mydomain
    dbhost server.$mydomain
    if {$type == prod} {
        port 9000
    } else {
        port 9999
    }
Having a "full-blown programming language" for free in config files is sometimes desirable.

I'm writing much more Python than Tcl these days, but this is a feature I sorely miss. I keep looking for similar functionality in Python, but I am always disappointed. Starlark has been proposed in the past, but unfortunately it means you have to work with something different than Python (in developing, in deploying, etc.), doubling your dependencies.