Tcl the misunderstood (2006)
antirez.com
antirez.com
Everything else about web service backends in TCL is pretty sad and frustrating, though. Unless it's embedded, anyway.
(Understanding TCL lists are just delimited strings lets you do interesting things. Sometimes unintentionally.)
(The second of those isn't strictly part of what's meant by homoiconicity. You could, after all, write your own compiler, just as you might write a metacircular evaluator in Lisp. But it seems like an important part of the spirit of the thing.)
Tcl may be homoiconic -- it's been years since I looked at Tcl and I don't remember anywhere near enough details to try to pronounce on this -- but if so, it isn't merely because it represents everything as strings. It'll be to do with simple string operations being able to do all the parsing you need (on account of the syntax being simple and/or there being string operations that do things like parsing out a {...} block of code), and with there being a usable eval.
I should maybe clarify one point: I was not saying that Tcl isn't homoiconic (which is, e.g., why I said "Tcl may be homoiconic"). Only that the mere fact of representing everything as a string doesn't make it homoiconic.
For example the Tcl does not have try-catch-finally statement. If that happens in other languages you just need to accept it. In Tcl you can implement it yourself for example:
http://code.activestate.com/recipes/68396-try-catch-finally/
You can do macro like things in tcl, but very often the evals and uplevels all worked to make my brain hurt in ways that writing cl macros never has.
TCL lends easily shell-like syntax so it is great for adapting your DSL to a REPL and even maps fairly cleanly to REST.
Years ago, I built a REST-like API that had one URI to which one could POST a TCL script. That script in its most basic form would be a series of pipelined API calls. There was even limited transactional support. I saw this important for mobile applications as it would reduce latency.
While the scripts were technically TCL, it was easier for developers than Javascript or Ruby (which we also beta'ed). It didn't look as much like a programming language as it did a series of shell commands.
The biggest problem with the above is that TCL safe interpreter still allow loops and other blocking operations. It means that you need to write a reaper to kill long-running threads / processes.
Combining such techniques with ZeroVM (or even Docker, or both) would be interesting.
bch$ tclsh8.5
% interp limit {} time -seconds [expr {[clock seconds] + 15}]
% while 1 {set a 9} ;# 15s elapse, then...
time limit exceeded
bch$
edit: Add release date for Tcl 8.5It is an old language with lots of cruft, but it's been used in all sorts of places for something like 25 years. Perhaps people's experiences with the language are colored by using it as a means to customize behavior in some big hairy enterprise app.
I haven't written TCL in a few years, but back when I did (when I worked on MacPorts) I actually did think it was fun.
I haven't kept up with it and enjoyed seeing there's still those who find it productive
So we (some friends and me) created our own bot (with a very simple DSL) just for fun in pure C, and it was very fast (http://davis.sourceforge.net/). Of course, our DSL was never as well designed as Tcl.
Tcl in some ways was the cause of, and solution to a lot of problems on IRC.. I ended up becoming friends with some of the people who'd try to takeover a channel I might be in and we'd realize we had more in common than not, such as how to customize those damn bots. Still have some of those friends years later, and I'm not sure if I'm the only one. Tcl feel good story.
I just finished building a CAD-like visualization utility in Tcl/Tk which using a complex Tcl-based internal DSL to define complex multilayer geometries.
Tk and it's Canvas widget are great for things like this.
Many years ago I also wrote an IDE for Image Processing algorithm development in Tcl/Tk, which also heavily used Canvas. I was able to build a complex GUI Imaging application literally in the wish shell, all while learning Tcl/Tk and [Incr Tcl] OOP system.
The trick was to bind key like F11 to reload source files and redraw GUI.
For the Image Processing stuff or anything else compute intensive - Tcl was very slow, so I either spawned external processes or used native implemented Tcl commands.
Tcl versions changed native command API, so many native extensions weren't ported to newer Tcl versions. I have some code that uses old 2001-based Tcl, because the native packages weren't ported.
I know that there is a package manager for Tcl, but I don't think it's widely used.
So, if you need to glue many different utilities with simple control logic and put some GUI above it - Tcl/Tk is great.
I never encountered it again, but its elegance always stayed with me. Except for uplevel. Fucking evil.
re: uplevel - Interesting Perl5 has this feature via a CPAN module! - https://metacpan.org/pod/Sub::Uplevel Also another variation is https://metacpan.org/pod/Scope::Upper
No it doesn't... unless machine translation is "there" and built into Tcl.
> Every string is internally encoded in utf-8, all the string operations are Unicode-safe, including the regular expression engine. Basically, in Tcl programs, encodings are not a problem - they just work
Really? Perl's Unicode support is pretty much second-to-none, IME, but you still need to know the encoding of your file handles and so on. Once it knows this, Perl will Just Work(TM). How is this handled in Tcl?
The purpose of the comment seems clear enough to me: to point out two claims made by the article that seem implausibly optimistic:
1. That i18n "just happens", which as fuzzix says is surely impossible unless Tcl includes magical machine translation facilities.
2. That "encodings are not a problem - they just work", which would require Tcl to tell by some ingenious means what encoding is used by any given file -- something that Perl, despite being exactly the sort of language that doesn't mind the kind of heuristic complexity it would take to do this well, and being generally acknowledged to do a good job of handling Unicode, punts on).
If I open an ISO-8859-15 or UCS-2 file in a Tcl program, how is this handled? Does it seamlessly detect encoding and translate to UTF-8 or is there more to this issue than what's stated in the article? Also, are the strings stored in a canonicalised form? If not, how simple is it to perform normalisation?
I brought up Perl because it's my experience of a language with excellent encoding support and helps make the point that the issue is probably more complex than just how strings are stored and manipulated internally.
Perl's unicode support is excellent now. In 2006 5.10 wasn't out yet, and anything before 5.8.5 had all sorts of odd unicode bugs.
Or: Tcl got there significantly before we did.
To be clear, I'm not arguing against using Tcl in favour of Perl or anything else. It's just that my experience with a language with great encoding support doesn't jive with what's claimed here.
> The Tcl community developed a number of OOP systems, radical language modifications, macro systems, and many other interesting things, just writing Tcl programs
Well there's your problem. It becomes impossible to learn the language as a whole, because it is so flexible and everybody does things differently.
Comments in Tcl work perfectly fine.
I agree with what you're saying, but allow me to go meta.
Comments in Tcl are a bit strange. This works:
# say howdy
puts hello
But this does not: puts hello # say howdy
For the later, you have to insert a semicolon: puts hello; # say howdy
I get bitten by this time and time again.Once I visualized it that way, I never got tripped up by that again.
And regardless of this fact, comments exist. They may not be as convenient as using // or // in C its friends, but they exist. To say that tcl does not allow one to know what a complicated line of code means is absurd.
In my mind, that's an argument that at least something shouldn't be a command. But perhaps it simplifies implementation enough to be worth it.
> To say that tcl does not allow one to know what a complicated line of code means is absurd.
Fully agree with you there. And for what it's worth, in the Tcl I encounter, there's rarely a line of code that complicated. Perl is often accused of being a write-only language. I think Tcl, if anything, is the opposite. It always seems readable.
Another topic I would like to see introduced in a similarly friendly way is event loops. At my work I am dealing with some Tcl/Tk code that uses event loops and it's a bit of mental gymnastics to get my head around what gets executed when.