top | item 43381195

Tcl Tutorial

161 points| Tomte | 1 year ago |tcl-lang.org | reply

73 comments

order
[+] antirez|1 year ago|reply
If you want to play with reading/recreating a very small Tcl interpreter, recently I put Picol (a 500 lines of C code Tcl interpreter) on Github. It was still on the web, but a bit more "hidden". I had a chance to re-read the code, and it is not in the category of code I regret writing :D Still relatively useful for newcomers, I hope.

https://github.com/antirez/picol

[+] analog31|1 year ago|reply
Thanks for that effort. Some time ago, I got Picol working on an Arduino-compatible microcontroller board with minimal effort. I was working towards making my own programmable calculator, and test-drove a number of simple interpreters, including yours and a couple others.

Project languished due to my attention span running out, but I still have my adaptations of those codes on my drive, in case I ever pick it up again.

[+] somekyle2|1 year ago|reply
Thanks for Picol! I saw it as a young engineer, and found the simplicity inspiring. It inspired me to write Tcl interpreters as starter projects in the next languages I was picking up, and I learned a lot by trying to push performance , functionality, and correctness. Your little project ended up inspiring cumulative months of joyful hacking.
[+] bulletmarker|1 year ago|reply
I wonder how this relates to Jim Tcl which you also originally authored?
[+] watersb|1 year ago|reply
The once-ubiquitous open-source package manager for macOS, MacPorts, is basically a Tcl app.

That is to say, its packages are Tcl.

I haven't used it in many years, as is has been largely replaced by Homebrew, which uses Ruby.

(I once maintained a MacOS port of a good-sized scientific analysis package. Hundreds of MacPorts packages, I have debugged.)

https://www.macports.org/

[+] jhbadger|1 year ago|reply
In the 1990s, an awful lot of Linux apps were Tk/Tcl. People complained then about them not being "native", but they were slimmer and better performing than the typical Java or Electron app of today.
[+] marxisttemp|1 year ago|reply
MacPorts has far more packages than Homebrew and was implemented by the creator of the original FreeBSD ports system, who was also an employee on Apple’s UNIX team. MacPorts is the standard macOS package manager.
[+] wglb|1 year ago|reply
I don't think homebrew has replaced MacPorts. I suspect that MacPorts has more ports.
[+] hiAndrewQuinn|1 year ago|reply
I like Tcl a lot, especially the Expect module. If you've ever wanted an Autohotkey for your terminal (I promise that phrase actually makes sense) it's well worth your time to look into either Expect itself or Python's `pexpect` module.
[+] aerostable_slug|1 year ago|reply
I love Expect.

Package owner: "These configuration choices are so important that a human must be present at the keyboard every time, without exception. Woe would befall us all were the will of the ancients ignored. So it was written, so it shall be done."

Me: "Yeah, nah."

[+] liveoneggs|1 year ago|reply
I thought with the rise of chatbots tcl/expect would see a big resurgence. It's definitely been on my to-do list in the last few months.
[+] WillAdams|1 year ago|reply
Wait, didn't Tcl/TK 9 just launch?

https://www.tcl-lang.com/software/tcltk/9.0.html

Any word on a nice binary release of it?

[+] kristopolous|1 year ago|reply
it's worth noting for those unfamiliar, tcl/tk 8.0 came out in 1997. So this isn't a normal thing, this is a 27 years in the making kind of thing.
[+] az09mugen|1 year ago|reply
This, when I wanted to try tcl, it was so difficult to find ! Somehow I was able to find a tcl executable in my distro. I challenge anyone to download an executable in less than 2 clics from the page "Binary distribution" of tcl official website [0]. Why is there so much difficulty to provide a binary for TCL ? [0] : https://www.tcl-lang.com/software/tcltk/bindist.html
[+] kras143|1 year ago|reply
Tcl offers a unique combination of embeddability and power, often underappreciated outside specific domains. While its general-purpose usage might be less prominent, its dominance in Electronic Design Automation (EDA) is undeniable.
[+] ChipsNDip|1 year ago|reply
Nice, a TCL post!

I use TCL often (forced to) since it's Cloverleaf Integration Engine's official scripting language and it works very well, but it is different from other languages in that its syntax is not modern, though, it's not difficult to learn if you really need to.

It's an older language that's fallen out of favor mostly for other scripting languages (Javascript, Python, etc) and understandably so. I'm by no means an TCL, but do consider myself an expert when using it with Cloverleaf.

Thanks!

[+] sureglymop|1 year ago|reply
Cool!

What I would recommend right off the bat is installing the handy tool `rlwrap` and starting `tclsh` using the command `rlwrap tclsh`. This wraps it with readline which imo is a better experience (especially if one is used to the readline keyboard shortcuts).

[+] zerr|1 year ago|reply
I skipped Tcl in favor of Perl. Is there any reason to reconsider nowadays?
[+] williadc|1 year ago|reply
Tcl is more-or-less required if you're involved with the physical design of silicon (most EDA tools only provide a Tcl interface). It's a good fit for that purpose. If you need a language which is easy to embed and you want non-programmers to be able to use it, Tcl is a good choice, though I've heard that Lua has supplanted Tcl for that purpose.
[+] wduquette|1 year ago|reply
I dropped Perl for TCL decades ago, after I realized that I could read and understand my TCL code months after I’d written it, but my Perl code was totally opaque.
[+] BoingBoomTschak|1 year ago|reply
Looks like this post I made can serve again: https://world-playground-deceit.net/blog/2024/10/why-tcl.htm...

But to be honest, while I feel like Perl has a lot of advantages (full perlre, full access to POSIX APIs, slightly better performance), I still can't look at it and keep my last meal down. Tcl having an event loop and Tk being native are pretty nice too.

[+] forinti|1 year ago|reply
I like both Perl and TCL. If I need an executable for Windows, I choose TCL, because I can easily make one with freewrap.
[+] esafak|1 year ago|reply
I first encountered Tcl when trying to use the network simulator, ns2. Any language that lends itself to such hideous code can't be good, I thought, and stayed clear of it ever since.

https://www.isi.edu/websites/nsnam/ns/

[+] AceJohnny2|1 year ago|reply
TCL is embeddable (in another program). In fact that's how it started.

That means it's a good language to extend your program. I don't know how it compares to Lua, which seems to have replaced it in that space.

[+] neotek|1 year ago|reply
So many fond memories of building eggdrop bots with Tcl scripts in the good old days of IRC. Trivia games, quote dbs, channel management, nick squatting, all sorts of shit.
[+] uwagar|1 year ago|reply
Tcl is such fun. except for using expr to do math. i mean in other languages

a + b

in Tcl its

expr $a + $b

thats my only beef.

[+] pwg|1 year ago|reply
Then switch to using "LISP like" math in Tcl:

   $ rlwrap tclsh 
   % namespace path {::tcl::mathop}
   % + 2 4
   6
   % - 6 1
   5
   % - [+ 6 3] [+ 1 1]
   7
[+] hieloz|1 year ago|reply
Nice. Tcl scripts are widely used in wireless communication,especially base station testing.
[+] twothamendment|1 year ago|reply
I haven't used TCL in a few decades and I don't miss it, but that is likely due to running it on storyserver. Worst web platform ever.
[+] ksynwa|1 year ago|reply
The syntax looks similar to that of fish shell