
Learn X in Y minutes – Tcl - notduncansmith
http://learnxinyminutes.com/docs/tcl/
======
Johnny_Brahms
I haven't scrolled through more than a third and suddenly I have this strange
feeling of wanting to write an IRC bot.

Jokes aside, TCL was for a long time my goto language for anything quick and
dirty. As a result, I don't mind TCL at all. I still use Tk quite often. It
might not look pretty, but it works and more crossplatform than other ui
toolkits.

~~~
kingmanaz
Tk has come a long way since the 8.5 release. Tk now looks native. See
[http://www.tkdocs.com/tutorial/index.html](http://www.tkdocs.com/tutorial/index.html)
for an excellent tutorial.

------
amelius
I was hoping for a listbox with options for X and a slider controlling the
value for Y :)

~~~
sigzero
That's Tk. ;)

------
meeper16
Tcl is awesome.

~~~
tonyjstark
can you elaborate? I always wonder if I should learn it, how it would make me
think in new ways and how I would use it. Tcl looks strange and that makes it
very interesting for me so how do you use it and why do you use Tcl for it?

~~~
_pmf_
It offers the syntactic freedom of Lisp/Scheme without the parentheses.

~~~
_ph_
The top level of parenthesis-es is left out, the other levels replaced by
brackets :). But joking aside, I greatly enjoy both Lisp and Tcl as languages.

~~~
a8da6b0c91d
A huge, seriously annoying problem with TCL is lack of deterministic cleanup
for resources. If you don't manually close a filehandle, for example, it will
leak. Doing this sort of bookkeeping in 2015 is infuriating.

~~~
sebcat

      proc with {file as name block} {
        uplevel 1 [list set $name $file]
        uplevel 1 [list eval $block]
        uplevel 1 [list close $file]
      }
      
      with [open foo.txt w] as file {
        puts $file "Hello, World!"
      }
    

I'm sure it's possible to do it in a cleaner way without [set], but my Tcl is
a bit rusty.

~~~
a8da6b0c91d
Still leaks on an exception. That's also an annoying construct to be forced to
use.

~~~
nilkn
You could easily wrap the middle uplevel in a catch block to handle
exceptions, and this sort of "with" construct is pretty common in a lot of
very popular languages today.

While it would be nice if this were baked into the language, it's pretty
astonishing how extensible Tcl is without even having to touch the realm of C
extensions.

~~~
srean
I think this precisely one of Tcl's strengths. Few other languages apart from
Lisp and Tcl lets you write your own control flow syntax from within the
language (and at runtime).

------
josteink
Seems like an article ripe for pull-requests.

I've already sent one on a minor formatting issue, but about one third into
that article, the formatting goes permanently haywire.

Weird how no one has noticed until now?

~~~
Retr0spectrum
It looks like the syntax highlighter treated a * as the end of a comment,
causing a " in the comment to be treated as the start of a string. That causes
everything that isn't a string to be highlighted as one, and vice versa.

------
robertskmiles
I've just started at a place that uses a lot of Tcl for embedded scripting and
customisation, and I've never used it before so this was very handy.

That said, the document needs work - the syntax highlighting got very confused
at some point, and a bunch of the lines are much longer than the width of the
document, and don't wrap.

Tcl looks like a nice little language that makes it really easy to write
really horrible code. Probably with some discipline you could keep it tidy and
comprehensible though.

------
bitwize
Tk is great but Tcl itself... it's interesting but the difficulty in creating
real data structures (as opposed to just strings) makes me start reaching for
Scheme again...

~~~
srean
Tcl was never meant for that, the Ousterhout way would be to extend Tcl with
the data structure written in C. Now Lua has knocked Tcl crown of "designed
from scratch with embedding in mind" but at that time Tcl was indeed quite
unique and one of the easiest to embed. This in a backhanded way inspired
Guile: scheme intended to be embedded and/or extended.

Talking about Guile, lots of fun things happening there lately. wiki.tcl.tk is
a lot of fun too.

~~~
gioele
> at that time Tcl was indeed quite unique and one of the easiest to embed

Could you please explain why some languages are better at being "embedded
and/or extended"? Why would Guile be simpler to embed than Ruby?

~~~
bch
The Tcl shell itself (tclsh, which is many people's only interface with Tcl)
is just a REPL that uses libtcl. The Tcl library is written in C, and built to
be easy-to-use and powerful. Tcl also has an incredibly stable API/ABI which
allows for a "stubs mechanism"[0] which is quite a nice, powerful facility
that allows for seamless fixes to your Tcl-dependant work.

[0]
[http://www.tcl.tk/doc/howto/stubs.html](http://www.tcl.tk/doc/howto/stubs.html)

~~~
srean
Great points. Something I feel that Tcl really got right and Python did not is
handling concurrency. The Tcl way is to run the different interpreters in
different threads and communicate between them by message passing _but without
the need for serialization - deserialization_. They had this from the very
beginning.

~~~
bch
Yes. For multithreaded code, instead of deciding where/how to put interpreter
locks (like Python's infamous GIL (global interpreter lock)) to manage low-
level sanity wrt sharing data, Tcl punted and lets each interpreter run
unfettered.

This is called apartment model [0] threading.

[0] [https://msdn.microsoft.com/en-
us/library/aa261361(v=vs.60).a...](https://msdn.microsoft.com/en-
us/library/aa261361\(v=vs.60\).aspx) (this is a Microsoft VB article, with
nothing to do about Tcl specifically, but does nicely explain the apartment
threading model)

Edit: s/let's/lets/

------
tempodox
Before I say more: The “Tk” part of Tcl/Tk is the one redeeming quality about
Tcl. Tk gives you awesome bang-for-the-buck when it comes to building a UI.

That said, Tcl is the worst parody of a programming language since the
invention of BASIC and Brainfuck. All you need to know about it is two words:
Stay away.

~~~
gecko
I think you're being overdramatic, but since you didn't explain _why_ you
think Tcl is "the worst parody of a language since BASIC and Brainfuck", I
can't really evaluate that. I can name lots of things about Tcl that are
actually very pleasant, including the robust libraries, the homoiconic syntax,
the ease of extending the language, the quickness that newbies can pick it up,
and the performance (which is roughly on par with CPython, Perl and the like).
What things have you hit that resulted in such an amazingly strong negative
response?

~~~
tempodox
The fact that there are no data types but only strings. The necessity to
navigate dynamic scoping with `upvar` & siblings. The load of having to
simulate locality of reference with fancy array indexes. It may be nice for
simple string-crunching scripts but a complex application is living hell. You
wouldn't use /bin/sh for that, either.

~~~
tpoindex
Sounds like you haven't used Tcl since the early 1990's, you may want to check
your facts. Tcl has had boolean, integer, floating point, list, dictionary,
and other data types besides strings since 1997. The fact that Tcl will
convert all of these values into strings when asked is immensely useful.
Likewise, Tcl has had object oriented extensions since the early 1990's, and
as of the last few years has OO built into the core, so you can easily build
your data structures to suit.

