Tcl Static Prime: experimental compiler for Tcl that produces C or Java code
github.com
github.com
Indeed the language is notable for great flexibility and adaptability, nearly every aspect can be modified to the point it resembles completely different programming languages.
Way back in the 90's I started using Tcl/Tk because it was easy to create GUI applications I needed for my business. Over the years I've employed it for many purposes, including client/server apps that today we might use Websockets to implement.
Tcl's stability is valuable. A couple of days ago, I was maintaining a "legacy" server which runs a key business app written in Tcl. The most recent timestamp of the Tcl source was >10 years old, and running glitch free for even longer. Sure doing it today I might do it differently, but I can't complain about "bang for the buck".
While in my day to day work I don't feel the need for the compiler (starkits are good enough) it might attract more performance concerned people to this powerful but forgotten language.
For me returning to Tcl is always an immense pleasure. This is what it gives out of the box:
- convenience of bash
- power and elegance of Lisp
- self-containing no-dependency nature of Go
- clarity of Python
- probably unique for the entire industry reliable cross-platform GUI toolkit
- simplicity of Dodecalogue
What Tcl is missing:- good handle on concurrency in bigger projects (with scale, events lead to spaghetti or mega state machines). I tried to address this one myself by developing Golang/CSP style concurrency library https://github.com/securitykiss-com/csp
- large community
As for why use Tcl, see: http://wiki.tcl.tk/what%20is%20tcl
As a matter of opinion, the embedding api is cleaner than most alternatives.
Though the TCL/TK combo for some has always been appealing and simple enough to work and come across it in area's for comm's to nice display interface and medical data processings. Cloverleaf being worth a mention and that is written in TCL and used that near on 20 years ago for processing medical important things from banks of modems - it worked. Sure could use something else but that is true of everything. Still TCL been around a while, back in a time in which perl was popular.
1. It is very easy to write DSLs in Tcl, you can turn it into a radically different on-purpose language. If you think Ruby is good at DSLs, try Tcl.
2. It has good I/O functions and is event-driven by default. The Redis test for example uses a server-client model using the event driven support of Tcl.
3. It has excellent ways to interact with other Unix commands, see for example the [exec] command: http://www.tcl.tk/man/tcl8.5/TclCmd/exec.htm
4. It has automatic memory management but does not use a garbage collector, reference counting is used instead. This means that the memory footprint is small and there are no GC pauses. Moreover the interpreter is extremely stable.
There are more reasons for using Tcl in certain projects, the above are the reasons I'm using it for Redis testing.
(PyPy and Jython are NOT reference counted - so saying "Python is reference counted" is wrong)
Knowing TCL enables me not only tool automation, but a huge deal of personalization and setup, by allowing me to access data and internal functions of the systems. Modelsim, for example, has its whole GUI made in TCL/TK and I can easily create new GUI elements in TCL to help me debugging.
Also, TCL is a very interesting language by itself. Ok, not modern or cool, but much more interesting than most people think of it. This blog post [1] tries to make this point, and was already discussed in HN [2].
[1] http://antirez.com/articoli/tclmisunderstood.html [2] https://news.ycombinator.com/item?id=7069642
It has a unique (wild and strange) feature called upvar that I haven't seen in python or lua. You "use" it to reference a previous frame in your call stack.
Also: it's Tcl, by the way, not TCL.
Lobster[0] also lets you write do/while loops and new conditionals, but does that in a different way that does not require upvar/uplevel, and is IMHO cleaner. (It is less capable in general, but captures 99% of the use cases that I've seen for upvar/uplevel in Tcl)
It is indeed Tcl, but it IS an acronym for "Tool Command Language", or at least started out that way.
I'm really curious what lead to the community settling on this. You'll occasionally see all-lowercase in some projects thanks to the fact that *nix commands are usually all-lowercase, but title-casing an acronym is weird.
If I had to hazard a guess, I'd say it's because "Tcl" is typically pronounced as a word ("tickle"), so it got de-acronymized like "radar" or "scuba". Then again, nobody writes SCSI as Scsi. I'd love to study this some more...
I personally think it should die a very quick (honorable) death.
Mind elaborating?
I can't think of one thing TCL does better than any of the languages that come after it that warrants keeping it around, outside of super easy C bindings and some light metaprogramming capability.
A lack of good resources on TCL also leads to people learning it all sorts of ways, and writing all sorts of (often buggy) code with it. Maybe that's just symptomatic of the companies at which I've used TCL, but I think it's pretty clear that there are way more good resources on something like lisp or python than there are on TCL (I mention lisp because if you squint and replace some [ ]s with ( )s, TCL looks almost like lisp)
A lot of my reasons aren't quite concrete, but in short, I think using an almost-dead language like TCL leads to stagnation of a code base. People aren't pushing boundaries, doing new things in TCL. There's definitely nothing wrong with having a no-surprises go-to language that just gets stuff done, but I just don't personally find TCL stimulating.
Maybe I'm just too much of a new-shiny-language hipster
No, I would disagree. I like Tcl. I like using Tcl. The community is very good as well. The Tcl maintainers are really good at what they do for Tcl and the community.
There is no reason IMO for it to die at all.
Why do you like TCL more than any other language (ex. Python, Lisp, etc)?
I love how simple the language is. Quick and easy to learn, small footprint, embeddable. For quite a while I used to prototype simple web services in Tcl, then convert to C for speed. The Tcl versions were so much easier to write, adapt, and debug, and had more features, because in C at some point I thought, meh, don't really need this...
For this question: I've used Tcl for 20+ years for various things, database, web, monitoring, prototyping - basically anything you'd use any other scripting language, it just happens to fit me well (I also use Python for some things). Tcl is not without its warts, but positives far out weigh any negatives. Translation to C or Java is done primarily for performance, other use cases would be for IP protections.
Also look at the the source files for the Tcl (tclsh) or Tk (wish) shells. They are fairly concise.
Although even that is not super recent.
Tcl's C API is very pleasant to work with, and its C code is a good read - except for the regex stuff, which are the first few files you'd see in an alphabetical listing.
The suite of first class objects in Tcl is very appropriate. But I have more experience with Tcl, so there's another bias.
There's a way to do state machine patterns with Tcl that I've not seen in any other language - arrays of code-strings indexed by state - you "eval $fsm($state)". I'm sure there are other languages that do this, so observer bias. That, with event-driven socket/serial port/file I/O is where it shines the most.
The strengths are really the Tcl core team, who have all been at it for a long time, have excellent backgrounds and don't ship a lot of problems. IMO, Tcl's "obscurity" ( relative to Perl ) was a saving grace - Tcl moved at a more deliberate pace. I also tend to trust my own Tcl code more than things developed in other ways - I've used it to find countless bugs in other peoples' stacks and libraries.
I have not used static compilation, so I'll withhold comment. There is freewrap at least for making a standalone Tcl application. It basically embeds a Tcl interpreter with the "executable".
Also - I think the way to learn Tcl is to use the Brent Welch book.
I wonder how that translates, at all or well, to compiling languages like Java.
Will have to read on. Sounds neat!