History of Tcl (2009)
web.stanford.edu
web.stanford.edu
As far as complaints about the syntax being weird: It's far more consistent than Algol descendants in that everything is a string, much like everything in Lisp is a list. You don't have to learn a bunch of different syntactic constructs, everything is a string, and every string is a space-delimited list, and can be interpreted as a command. The hardest part of the language is the quoting rules, which the documentation affectionately refers to as "quoting hell". Once you wrap your head around that, everything becomes clear. The standard library is pretty easy to learn, and the documentation is good.
Check it out.
These kind of communities are fun.
{a b}
might represent any of the following data structures in JSON notation: "a b"
["a", "b"]
[["a"], ["b"]]
{"a": "b"}
{"a": ["b"]}
This can make reading some Tcl code quite a puzzle. {a b}
also represents something not possible in JSON: {["a"]: ["b"]}
The string a
can be treated as "a", ["a"], [["a"]], [[["a"]]], ...
by list operations.FWIW, the best handling I know of JSON in Tcl is the rl_json package (https://github.com/RubyLane/rl_json) which essentially makes JSON into what works like a native Tcl value type.
puts [ subst [ read [ open [ lindex $argv 0 ] ] ] ]
(Hint: `subst` applies Tcl's string substitution function, which substitutes variables like $varname and Tcl commands enclosed in square brackets. So, this one line program can be used as a templating system that is somewhat like PHP or eRuby.)https://vanderburg.org/old_pages/Tcl/war/0000.html
aside, I found Tcl/Tk along with with the extension Expect:
https://en.wikipedia.org/wiki/Expect
to be a powerful way to do automation. In the '90s, I automated a process of migrating data from a mainframe to Unix workstations using a Tk GUI run by end users which generated Tcl/Expect scripts to download, convert, and verify massive amount of files in a batch.
If you need to automate old terminal apps, you really can't do any better at the moment.
- AOLServer (https://en.wikipedia.org/wiki/AOLserver)
- Rivet (https://tcl.apache.org/rivet/)
- Vignette (https://en.wikipedia.org/wiki/StoryServer)
- Safelayer (our own in-house implementation, the core team later founded OutSystems)
I'm not sure why I'd reach for Tcl today when lua exists.
given a problem of fixed complexity, the simpler the language, the harder will the implementation of this problem have to be
There is a talk on youtube about it I know
> it takes forever to wrap my head around the syntax.
... which (from observation) is often from second-guessing or overthinking the rules.
Regular syntax, for one thing. Command-oriented sensibility, too.
This has been present for many years (for how long I do not know). Look up the "trace add variable ..." command.
> nested variable scopes within a proc,
This is possible (if a bit clunky) with Tcl of at least V8.5 vintage by using the "apply" command. According to this page (https://stackoverflow.com/questions/1478510/when-was-tcl-v8-...) 8.5 was first released Dec. 20, 2007, so this one has been possible for 13 years.
I suppose I should have been more explicit. I want to know when the value the variable holds goes away, so I can clean up the resources that value represents (for example, if the value names a unique namespace that groups related values, I want to delete the namespace once the name no longer exists).
I double-checked Tcl 8.6’s OO stuff and it says you need to explicitly destroy objects, they won’t be destroyed simply because they went out of scope, so even the core language isn’t doing this.
> This is possible (if a bit clunky) with Tcl of at least V8.5 vintage by using the "apply" command.
apply does not create a nested scope. It runs the code in the global namespace (or some other namespace you specify), so it has no access to the current scope unless you use upvar within the lambda. What I want is nested variable scopes that don’t require upvar to access the outer scopes.
"Tcl continues to be heavily used as an embedded scripting language, a domain where it still seems to be the best alternative"
That being said, it grew on me as a general scripting language kind of generally in the same space as Perl.
https://en.wikipedia.org/wiki/AOLserver
https://en.wikipedia.org/wiki/StoryServer
So back in the early days of Apache and server modules, Tcl was a good option to build web applications. :)
(At least the versions I used) do not print the exact line number if something fails. They print top of the enclosing loop. Super annoying.
$ tclsh test
line 1
line 2
line 3
error here
while executing
"error "error here""
(procedure "test-error" line 5)
invoked from within
"test-error"
(file "ttttt" line 9)
Where the contents of "test" were: $ cat -n ttttt
1 proc test-error {} {
2 puts "line 1"
3 puts "line 2"
4 puts "line 3"
5 error "error here"
6 puts "line 4"
7 }
8
9 test-error
Line 5 and line 9 match up exactly.