Happy 25th Tcl
blog.tkdocs.com
blog.tkdocs.com
In other words, Tcl as a language is what would happen if Lisp and csh met at a party, got way too drunk, hooked up, got pregnant, and kept drinking throughout the pregnancy.
When I was using it (early 1990's) I really appreciated that Tcl provided C coders with an easy way to create a scripting environment for your libraries. And with Tk you could get a GUI running pretty quickly as well. The structure of the source code was also very neat and well managed making it easy to understand and extend.
In many ways I see Lua as the spiritual successor to Tcl; neatly designed for embedding and extension.
Below is one of the SICP authors writing on the lispish nature of Tcl. (TL;DR: Tcl is like a lisp that exchanged theoretical purity for pragmatic simplicity of implementation):
"""
If in reading this introduction, you've come to realize that "Hey, Tcl is just like Lisp, but without a brain, and with syntax on steroids", you might wonder why Lisp isn't a more popular scripting language than Tcl. Lisp hasn't been a complete failure, by the way; it is used as an extension language by users of some popular programs, notably AutoCAD. But Tcl has been much more successful. It has been compiled into hundreds of larger programs, including AOLserver, which is why we wrote this book.
As a software developer, you're unlikely to get rich. So you might as well try to get through your life in such a way that you make a difference to the world. Tcl illustrates one way:
* make something that is simple enough for almost everyone to understand
* give away your source code
* explain how to weave your source code in with other systems
In the case of AOLserver, for example, Jim Davidson and Doug McKee had only a few months to build the whole server from scratch. They wanted users to be able to write small programs that ran inside the server process. They therefore needed a safe interpreted language so that a programming error by one user didn't crash the server and bring down all the Web services for an organization.Tcl was available. Tcl was easy to download and designed to fit inside larger application programs. But the Tcl interpreter as distributed had one terrible bug: it wasn't thread safe, i.e., you couldn't have two copies of the Tcl interpreter running inside the same program at the same time. Doug and Jim had to read through the Tcl source code and modify it to be thread safe. So it was critically important for them that Tcl was open-source and simple enough so as to not require months or years of study to understand the whole system.
Compare this to Lisp. Some of the best and brightest computer scientists raised money to build commercial Lisp implementations that they then went out and hawked in an indifferent and confused marketplace. They succeeded only in breaking their hearts and their investors' wallets. A handful of academics produced free open-source implementations, notably CMU Common Lisp (see http://www.cons.org/cmucl/) and various versions of Scheme (see the links from http://en.wikipedia.org/wiki/Scheme_(programming_language); Scheme 48 is the closest to Tcl in spirit). But these multi-megabyte monsters weren't designed to fit neatly into someone else's program. Nor was there any document explaining how to do it.
Lisp developers have the satisfaction of knowing that they got it right 30 years before anyone else. But that's about all they have to show for 40 years of hard work and hundreds of millions of dollars in government and private funding. These days, most former Lisp programmers are stuck using Unix and Microsoft programming environments and, not only do they have to put up with these inferior environments, but they're saddled with the mournful knowledge that these environments are inferior.
"""
Tcl's C is very clean and pleasant code to read, by the way.
Despite its odd syntax which sometimes tends to get in the way, Tcl is one of the rare examples of a functional programming language actively used in the industry (I'm looking at you Lisp). Though I did often find myself wishing that something like Python would replace it instead for better readability.
Those of us actually using EDA tools are not necessarily so fond of Tcl. Not me anyhow. Tcl is awkward to debug, and its everything-is-string semantics make programming an exercise in quoting. Just when I think I understand the scoping, I screw it up.
> Despite its odd syntax
Tcl's syntax is one thing that I actually do like about the language. It's odd, yes, but it's simple and clean.
> Tcl is one of the rare examples of a functional programming language actively used in the industry (I'm looking at you Lisp).
Cadence actually uses a real Lisp in some of their tools; they call it Skill. Skill is, in fact, a joy to code in; and I greatly prefer it to Tcl. They also have a lexically scoped version called Skill+, which I've never got to use.
> wishing that something like Python would replace [Tcl]
Python, yes! Or Scheme. Or even Perl. I don't know Lua, but have always imagined it to be better than Tcl and it seems to occupy a similar niche. But no one even talks about Tcl getting replaced.
Is your code filled with literal strings? Otherwise why your code be "an exercise in quoting"?
re Python: Remember that EDA tools aren't libraries, they're actual command line program programs. So those tools will still need a command line language. Python is horribly unsuited as a command line language, so the tool will probably continue to have Tcl to present the text user interface.
So you'll then end up with two interpreters in the same tool. Hardly a desirable state of affairs. So yeah, I think the ROI of embedding Python in EDA tools is probably not doing to be worth it.
A lot of the C code backing the Tcl APIs directly build Tcl objects or store pointers to Tcl objects in C. It will be giant task to make those APIs work correctly with Python also.
That's just what my spider-sense says though - I've never actually looked at those things or their code.
There was the insanely useful event-loop built into tk (obviously, for GUI applications), but also in tclsh (see, for example, http://www.tcl.tk/about/netserver.html where [socket -server on_connect_callback_fct portnum] creates a listening tcp socket).
This made it (for me, in 1997...) an ideal glue-language for network management tasks (monitor events on a router, graph temperature on a UPS, see http://wiki.tcl.tk/691 ) but also for simple laboratory automation (GUI in tk for controlling a power supply), most often running simple line-oriented ASCII protcols between GUI and daemon.
Even later, I did research in a Physics collaboration that did automate their whole measurement apparatus on the HERA accellerator in Hamburg using a really scary and intricate mixture of tcl/tk, blt for data visualization and a obscure particle-physics database (ADAMO) made network aware: http://www-hermes.desy.de/pink/ ...
As I spend my time more and more in clojure these days I can't help but be reminded of some of the cool stuff you could do with TCL, which isn't surprising given its lisp heritage. Any language that cleanly lets you add new constructs is ok in my book!
Aolserver, that was fun too :) It's always amazing to me how TCL didn't stay more prominent. When Blizzard scripted WoW with TCL I was like "finally, someone gets it!" but that was more an anomaly than anything else.
And if you need something compex, do it C for chrissakes.
EDIT: And event loops are beautiful!
The code is available on CodePlex, under a BSD-like license: https://eagle.codeplex.com/
TCL + Vignette, takes me back to 1998.
I was met with blank, embarrassed stares, until the manager finally said, "Um, we're actually still using that ancient version built on Tcl."
So far as I know, they're still using it -- they never upgraded, switched, or developed an alternative. I'm not sure if that speaks to the company's ability to absorb pain, or to the excellent, long-term software engineering that went into that version of Vignette.
But... it was always sold and justified it's price on the basis of personalisation. Everywhere I ever saw Vignette the managers believed that they had purchased the holy grail of personalisation.
The personalisation stuff was based on server-side includes that pulled in uncached files, and used cookies to track individuals and then would build a file on the individual and tailor the SSI for the individual.
Sounds perfectly reasonable. Except I never saw it working outside of a demo for a single user.
Vignette was a great "web stack with static file caching", and on the 4 servers we had at British Telecom we could serve our 6 million customers the BTinternet portal when they all logged on the minutes after 6pm (remember when it was free internet in the evening? and BTinternet was the default home page in IE for our users).
But if you turned on personalisation, everything ground to a halt immediately.
Pretty cool.
Also at the time AOLServer was amazingly fast. Shame development stopped on it.
ACS got bought by Red Hat later on, but it still lives on as openACS http://openacs.org
The first web application server I used, between 1999 and 2001, was an in-house framework built on top of Apache + C + Tcl.
Quite similar in principles to AOL Server, actually.
let's hope the next 25 years don't ever contain tcl's breakout year.
I never loved Tcl, but it was a very clever language for its time, and did wonders to justify the acceptability of doing things in "just" a scripting language.
Tcl is a wheel worth reinventing.
There's somethings you can do when everything's a string that you can't easily do in many other languages, unless that language is Lisp-based of course.
Below is a walkthrough of Tk which compares identical implementations of examples in Pearl, Ruby, Python, and Tcl. See if you can spot which of the scripting languages are more concise. Hell, I'd even call Tcl more readable in most of the cases:
For a completely different comparison (non Tk) here is the first example (http://www.tkdocs.com/tutorial/firstexample.html) written in Rebol:
Rebol []
convert-to-metres: func [in-feet] [
(round 0.3048 * in-feet * 10000.0) / 10000.0
]
default-feet: 1
my-window: layout [
style input-feet field 80 left
style label lab 90 left
tabs [140 230]
across
tab feet: input-feet (to-string default-feet)
tab label "feet"
return
text "is equivalent to"
tab in-metres: text (to-string convert-to-metres default-feet)
tab label "metres"
return
tabs 230
tab button "calculate" [
in-metres/text: to-string convert-to-metres to-decimal feet/text
show in-metres
]
]
view/title my-window "Feet to Metres"
The above is written in the Visual Interface Dialect of Rebol 2. I made it look visually identical to the example provided however this was the first time I've ever written any VID code so I'm sure it can be improved upon :)