> Well, I've encountered this use case a few times in Lisp:...
> ...where a callback is used to collect various items.
This can be and is achieved by simple SQL-like query. Filter (flat) set of nodes by integerness and you even do not need a push_back.Despite that, I find article interesting. It shows that Tcl can truely be multiparadigm programming language.
Myself, I've implemented pattern matching [1] over algebraic-type-like values and used that here and there.
> modify the node in-place
I consider this anti-pattern [1].[1] https://web.archive.org/web/20070417190836/https://www.eecs....
Authors found themselves fighting with control flow graph modifications and replaced mutable graph with immutable one, modified by zippers. They achieved speed up of 11% in optimizing transformations, some of which they were unable to implement in mutable version. E.g., more complex optimizations were working faster.
Closures can also be used to return a group of methods that all act on the same set of variables; ie, objects.
So, in C++ you do actually get to pick what happens and there are plenty of options but for our purposes here all we want is a (mutable) reference capture.
However, experienced C++ programmers would never do this because C++ is all foot guns all the time, so you can express what you meant and it'll blow up and cause chaos because now our reference outlives the thing referred to. Oops.
In Rust we can write what we meant, but instead of the program exploding at runtime the compiler will politely point out that this can't work and why.
And so armed with the knowledge from that, we can (in Rust or with C++ although it's harder to spell in C++) write something that'll actually work.
We could move the captured variable. In Rust we just use the keyword `move`, now the captured variable is gone, moved inside the closure, and so as with the Tcl the same variable (the one moved into this closure) is used each time the closure is called, and if we make another closure that's got a different captured variable.
But we could do the "shared reference" trick, that type is spelled Rc in Rust.
dingnuts•2mo ago
7thaccount•2mo ago
It would be cool to have a Tcl revival though (although I don't see it happening - I'm not in the community though so hopefully someone more informed can post). The language itself seems more capable than most give it credit for. I'm more of a Python fan myself, but can appreciate Tcl after reading through a book on it and writing a few scripts.
bandoti•2mo ago
https://www.magicsplat.com/ttpl/index.html
For those who are not aware, Tcl is actually part of standard Python distribution through TKinter.
There are many things Tcl has built in that are quite amazing, like a robust virtual filesystem support, reflective channels, and less known these days Starpacks (stand alone runtime) that bundle sources with the binary.
I am current working on bringing back kitcreator for an AI project that uses Tcl as a scripting environment over llama.cpp.
https://github.com/tclmonster/kitcreator
Roy Keene is the original author, and has done some really clever stuff here, like encrypting the VFS appended to the executable. I added compression to this. It provides some manner of obfuscating sources.
And actually, I am also working on using tohil to compile a static Python and load it as a Tcl extension, with the goal to have standalone Python applications bundled with their sources and completely loadable from within the VFS. This will provide a means to bundle TKinter with a “frozen” Python app.
https://github.com/tclmonster/tohil
7thaccount•2mo ago
sph•2mo ago
7thaccount•2mo ago
bandoti•2mo ago
If you’re interested, I have various Tclkits available for download on GitHub. I have added dependencies to them like TLS for HTTPS and so-forth. It can be convenient to have them standalone; the TLS extension here is bundled with the ca certs from libcurl.
https://github.com/tclmonster/kitcreator/releases/latest
And here’s an example how I use the kits in the CI build. It uses the kit it builds to push the update using the TLS extension along with the GitHub REST API:
https://github.com/tclmonster/kitcreator/blob/main/.github/s...
mhd•2mo ago
[1]: https://wiki.tcl-lang.org or https://wiki.tcl.tk
ofrzeta•2mo ago
msephton•2mo ago
In the most recent big version update there was what I'd consider a breaking change regarding text encoding handling, but it was possible to go back to the old behaviour with an additional parameter .
monetus•2mo ago
pjmlp•2mo ago
Yet it has a special place on my heart and was one of the interpreters easiest to extend, in regards to the FFI API.
f1shy•2mo ago
IshKebab•2mo ago
sokoloff•2mo ago
I introduced it into some of our release tooling in the mid-2000s. Easy to integrate, easy to understand, unsurprisingly good string/text handling, expect was very useful, and it’s not going to be used by anyone else, so no worries about version conflicts.
It ran successfully largely unchanged for around a decade.
IshKebab•2mo ago
I like to use tools that more than merely work.
There's a reason nobody outside EDA uses it.
dlachausse•2mo ago
IshKebab•2mo ago
RHSeeger•2mo ago
cmacleod4•2mo ago
johnnyjeans•2mo ago
IshKebab•2mo ago
BoingBoomTschak•2mo ago
Yeah, Tcl has its design warts, but I don't think it has that many remaining that can't be fixed via metaprogramming. Even the popular Python manages to frustrate me with its idiotic statement/expression divide (they doubled down by making match() a statement...) and constant need to convert between generators/iterables and lists.
Thing is that R6RS Scheme (or R7RS-large if it comes out one day) is basically a better Tcl if you only consider scripting and don't need the event loop. If Tcl had played its cards right, it'd have competed with fish/rc/nushell/powershell instead, it was really ready to be a better shell well before any other.
------
To be honest, Common Lisp is the only language I've ever seen get this right without compromising on said purity by specifying the reader (parser): https://www.lispworks.com/documentation/HyperSpec/Body/02_.h...
Comments are then just the result of a readtable entry like any other, allowing this kind of voodoo:
johnnyjeans•2mo ago
IshKebab•2mo ago