#BabelOfCode 2024
Week 5
Language: TCL
Confidence level: Medium high
PREV WEEK: mastodon.social/@mcc/113906616…
NEXT WEEK: mastodon.social/@mcc/114308850…
RULES: mastodon.social/@mcc/113676228…
TCL is an odd language. I think anyone who's tried developing a programming language has probably at some point thought "what if I just didn't bother with types and did all operations as string transformations?". I think TCL is just that language.
Officially, TCL is supposed to be capitalized "Tcl". I will not be complying.
Questa voce è stata modificata (6 mesi fa)
Oblomov reshared this.
mcc
in reply to mcc • • •I have near zero experience with TCL. In the late 90s when I started using Linux it was already considered old; I had one program that used it, a Tk-based AOL Instant Messenger client that was, admittedly, the nicest piece of Linux GUI software I had.
TCL is almost gone today EXCEPT in the Verilog community, which uses it religiously because it's a single language they can use both for build scripts (because it's designed as a scripting language) and as a template language (it can do that too).
Oblomov reshared this.
Sepideh
in reply to mcc • • •mcc
in reply to Sepideh • • •mcc
in reply to mcc • • •Oblomov reshared this.
mcc
in reply to mcc • • •Oh… … I don't like this. I really don't like this.
(The thing I don't like is that {}, which you might want to use instead of quotes due to the balancing feature, also disable interpolation. There aren't a lot of language design concepts I got out of Perl that I still think are good ideas, but the one I still strongly believe is that every language needs easy-to-use balanced quote delineators. `qq` is the best thing in Perl.)
Brad 💀🧙♀️🎃
in reply to mcc • • •mcc
in reply to mcc • • •I have a programming language I was implementing for a while in the 00s named Emily. There were three versions of it, two of which got released, and all three passed through a phase in their development where they were basically "curried LISP without parentheses".
Every time I get exposed to Tcl, I become more convinced that "curried LISP without parentheses" as the whole concept for a minimal-size-interpreter language is actually a super good idea. (TCL isn't this.)
youtube.com/watch?v=gMZsc3cvwK…
- YouTube
www.youtube.comMichael Kohne
in reply to mcc • • •mcc
in reply to Michael Kohne • • •Michael Kohne
in reply to mcc • • •mcc
in reply to mcc • • •Oblomov reshared this.
Fi 🏳️⚧️
in reply to mcc • • •mcc
in reply to Fi 🏳️⚧️ • • •@munin It appears the correct usage of "expr" in tcl is
[expr {expression goes here}]
It also appears that [expr expression goes here] is allowed, but this is a coincidence/accident, and there are at least two reasons to never do it, one of which is a security flaw
Sgeo
in reply to mcc • • •mcc
in reply to Sgeo • • •Aarni
in reply to mcc • • •Sgeo
in reply to mcc • • •fops Now On Merping Synth Download
in reply to mcc • • •mcc
in reply to fops Now On Merping Synth Download • • •mcc
in reply to mcc • • •mastodon.social/@mcc/113975863…
mastodon.sdf.org/@sgeo/1139758…
Currently terrified by the possibility that at some point I will wind up writing a TCL linter
mcc
2025-02-09 20:41:04
mcc
in reply to mcc • • •Oblomov reshared this.
king toot uncommon
in reply to mcc • • •mcc
in reply to mcc • • •Okay. I actually was able to get through the TCL docs very quick. I would have got through it even quicker if I occasionally hadn't had to stop and do something else for a while because something pissed me off.
I am tempted to call this an "elegant" spec. I think I would actively like this language if the syntax were restricted somewhat for safety (e.g. if {} were *required* for things such as expr, if, for instead of "you can leave them out but then it probably does something horribly wrong").
mcc
in reply to mcc • • •Here are my TCL questions:
- I see that there are "integer", "wide integer", "float", "list" and string types in TCL. Is there a builtin that can discern which type a variable has and/or discern which type[s] a variable can be coerced to?
- Is there a string concatenation operator? (besides "$a$b").
- What is the difference between an array¹ and a dict? The tutorial makes it clear both exist and explain the difference very poorly.
¹ This refers to an associative array not a list
mcc
in reply to mcc • • •Answers to the above questions per #tcl on libera:
- Type compatibility in tcl can be tested with [string is …]. "Actual" (interpreter level) type is apparently not exposed. tcl-lang.org/man/tcl8.6/TclCmd…
- Strings can be concatenated with [string cat …].
- Arrays are "weird"; they live in a single scope and can't be exported or passed to a function except by breaking things with "upvar". Additionally, dicts are ordered. "arrays" feel like an old version of "dicts" and I think I intend to avoid them
string manual page - Tcl Built-In Commands
www.tcl-lang.orgmcc
in reply to mcc • • •My TCL notes file:
{} => ""
[] => ``
set x y => x = y
[expr {…}] => "act like a programming language"
[subst {…}] => {act like ""}
$ and [] work within "" but not {}
eq ne in ni
einter => coerce
proc parameter named "args" is variadic if last
first $ in $$a does nothing
format => sprintf
lsearch and regexp are different
for {} {} {} => for(;;)
[subst $$a] => dereference $a
[string is …] => typecheck
strings are not strings
Before running:
sudo apt install rlwrap
alias tclrl='rlwrap tclsh'
Oblomov reshared this.
Sgeo
in reply to mcc • • •mcc
in reply to Sgeo • • •Sgeo
in reply to mcc • • •If you have a part of a command, like "string compare foo" in a variable a, you can invoke it as {*}$a bar
And can construct it via [list string compare foo]
wiki.tcl-lang.org/page/command… goes into depth about them.
command prefix
wiki.tcl-lang.orgmcc
in reply to mcc • • •наб
in reply to mcc • • •TÔ DE MUDANÇA
in reply to mcc • • •I miss my TCL days. It was the language of choice for extending the functionality of 'eggdrop’, a popular (in its niche, and late-90s) IRC bot.
As a language for extending other softwares, I feel that TCL was succeeded by Lua, a language created here in Brazil. Do you intend to test it too?
mcc
in reply to TÔ DE MUDANÇA • • •TÔ DE MUDANÇA
in reply to mcc • • •mcc
in reply to TÔ DE MUDANÇA • • •TÔ DE MUDANÇA
in reply to mcc • • •mcc
in reply to mcc • • •mcc
in reply to mcc • • •This isn't so bad though? Like at least I *can* check each call against the docs, because the docs are very good. And maybe I can even make my "use strict tcl" by forking molt docs.rs/molt/latest/molt/
Anyway, my "final" program:
github.com/mcclure/aoc2024/blo…
…not final. Because the code doesn't *work*, but I think that's due to an unclear problem statement (the code gives correct results on the given sample input and a sample input I wrote, but fails on the "real" input. AOC is like this sometimes.)
aoc2024/05-01-ordering/src/puzzle.tcl at 93a42f88f0a6e6f156b5980a1f2120cc6f504ffb · mcclure/aoc2024
GitHubmcc
in reply to mcc • • •Incidentally, re mastodon.social/@mcc/113975786… , I spent all night thinking about the question "what if Emily, but more like TCL?" and I think I've come up with a *brutally* simple yet actually usable language design which would be unusually easy to design a JIT compiler for (the thing that killed Emily 2 was me not being able to make the interpreter->compiler jump). I actually really want to drop everything and implement this as a JIT learning exercise but unfortunately there is too much everything
mcc
2025-02-09 20:21:18
mike sugarbaker
in reply to mcc • • •mcc
in reply to mcc • • •Coach Pāṇini ®
in reply to mcc • • •I just caught “AOC 2024” and was simultaneously intrigued and disappointed.
As you were 🫡
mcc
in reply to mcc • • •Oblomov reshared this.
Peter Brett
in reply to mcc • • •mcc
in reply to mcc • • •Couldn't sleep so I got up and tried part 2. It took like… minutes. Thank goodness for Perl/Python style sort comparison functions. Now seriously wondering how many of the things I like from Perl/Python are actually just adopted from TCL.
github.com/mcclure/aoc2024/blo…
True final code's a mess, due to both scars of me making random changes trying to figure out what the problem spec wanted and commented-out debug prints. I think TCL code could be quite clean if you went about it properly.
Glrbfghf
aoc2024/05-02-ordering/src/puzzle.tcl at dc6ec74c929dad3a33ed97b004d233d94d2ede34 · mcclure/aoc2024
GitHubgizmomathboy, FC
in reply to mcc • • •Justin 😸
in reply to mcc • • •mcc
in reply to Justin 😸 • • •@onyxraven I think if I had to make a specific case for Lua over Tcl, it is much easier to write incorrect code in Tcl and when you do it's harder to debug it. There are fewer guardrails.
This said, I don't think the "lua displaces tcl" was as direct as all that. I feel it went like "TCL is popular for scripting and embedding" -> "perl and python eat tcl's space, but perl can't be embedded, and embedding python is obnoxious" -> "Lua arises and becomes popular for embedding, but not scripting".
mcc
in reply to mcc • • •Kristoffer Lawson
in reply to mcc • • •mcc
in reply to mcc • • •Oblomov reshared this.
Ingvar
in reply to mcc • • •Andre Weissflog
in reply to mcc • • •it's been a long time... but IIRC in Tcl 'everything is a string', and you can evaluate Tcl code inside a string (what's known as 'f-strings' today in other languages):
onecompiler.com/tcl/438sr4qpa
...maybe today not so impressive anymore since a lot of languages got those f-strings too.
438sr4qpa - Tcl - OneCompiler
onecompiler.comNetwork == Abstraction Layer
in reply to mcc • • •spinalhdl.github.io/SpinalDoc-…
I know about it from following VexRiscV
github.com/SpinalHDL/VexRiscv
GitHub - SpinalHDL/VexRiscv: A FPGA friendly 32 bit RISC-V CPU implementation
GitHubmcc
in reply to Network == Abstraction Layer • • •Network == Abstraction Layer
in reply to mcc • • •mcc
in reply to Network == Abstraction Layer • • •mcc
in reply to mcc • • •# Here is the script I came up with for
# "interpret a file like a TCL template".
if { $argc != 2 } {
puts stderr "Need in-file and out-file args."
exit 1
}
proc x {} {
return ""
}
set input [open [lindex $argv 0] r]
set output [open [lindex $argv 1] w]
puts $output [subst [read $input]]
dr 🛠️🛰️📡🎧
in reply to mcc • • •Yes. We had a "plugin" feature that was basically storing Tcl in the db. You could do anything the "outer" program could do, including delete itself from the db. Perfect for malware!
But on the cybersecurity form we said it was "plugins".
mcc
in reply to dr 🛠️🛰️📡🎧 • • •Kristoffer Lawson
in reply to mcc • • •I have personally used [subst] in exactly that way: as a templating language for stuff. It's very effective for some basic things. Also really easy to build around it and do even more powerful things due to how #Tcl allows you to build your own language constructs.
So like in addition to [foreach] I could do a [webForeach] (for wont of a better name) that returns whatever string is in it, concatenated for each iteration, but runs [subst] on it for each round.
lambdageek
in reply to mcc • • •mcc
in reply to lambdageek • • •mcc
in reply to mcc • • •mcc
in reply to mcc • • •lambdageek
in reply to mcc • • •oh no!
FWIW, I seem to recall merge-sort isn't too too terrible in a dependently typed language - you convert the input into a big dependently typed tree where the dependent indices are the upper and lower bounds for the contents of that subtree and then flatten it. Something like that...
Edit: I think this is either missing a complicated bit, or it's actually describing insertion sort. Looking at other developments online, there's more to it
mcc
in reply to lambdageek • • •✧✦Catherine✦✧
in reply to mcc • • •mcc
in reply to ✧✦Catherine✦✧ • • •@whitequark In fact, it is the other way around 🙁 If you say
procname $a
You are passing in the value, and if you say
procname a
You are passing in the string "a", and procname will use upvar to scoop the variable $a out of your scope and modify it. The docs make this consistently clear by naming parameters either "stringvalue" or "stringvariable", but I had to figure out that pattern on my own.
✧✦Catherine✦✧
in reply to mcc • • •mcc
in reply to ✧✦Catherine✦✧ • • •zspotter
in reply to mcc • • •totally agree it's too clever, which also makes it so fun to use! @omar wrote a bit about why he chose it for folk.computer's datalog-style language
github.com/FolkComputer/folk/b…
folk/docs/design.md at main · FolkComputer/folk
GitHubJared Counts
in reply to mcc • • •mcc
in reply to Jared Counts • • •mcc
in reply to mcc • • •Jared Counts
in reply to mcc • • •Yes hA HA YES!
Kristoffer Lawson
in reply to mcc • • •nev
in reply to mcc • • •mcc
in reply to nev • • •mcc
in reply to mcc • • •nev
in reply to mcc • • •mcc
in reply to nev • • •nev
in reply to mcc • • •…I'm not sure Firefox ever had newsgroup support? Maybe a very long time ago?
Still works fine on Thunderbird
mcc
in reply to nev • • •Roni Rolle Laukkarinen
in reply to mcc • • •Timo the timo
in reply to mcc • • •(i have no reason to assume this actually does anything)
Tim Panton
in reply to mcc • • •"An Elegant Weapon for a More Civilized Age.”
I wrote a whole id card printing system for a govt in TCL (then printed my own card with it).
Then when the foolishly tight ministerial deadline had passed we re-wrote it in C (or was it java - I forget).
Kristoffer Lawson
in reply to mcc • • •fraggLe!
in reply to mcc • • •TCL is awesome like that. Back in the day I installed some fun script on my eggdrop and when I had [afk] in my nick I noticed in the bot logs "afk unknown command".
Changing your nick to have [die] in it had pretty funny results, on far more than just my bot. Apparently it was really easy to mess this up.
Last time I told this story some TCL nerd went "🤓 ackchually `die` isn't a valid TCL command", to which I said "shut the hell up nerd, it's a valid *eggdrop* command."
Boba Yaga
in reply to mcc • • •Riley S. Faelan
in reply to mcc • • •Oblomov reshared this.
mcc
in reply to Riley S. Faelan • • •Oblomov reshared this.
nick
in reply to mcc • • •reshared this
mcc e Oblomov reshared this.
BrazMogu (i.e. Bruno Guedes)
in reply to nick • • •Oblomov reshared this.
nick
in reply to BrazMogu (i.e. Bruno Guedes) • • •for when reading the source will just ruin the surprise.
reshared this
Oblomov reshared this.
James Widman
in reply to mcc • • •Bitslingers-R-Us
in reply to mcc • • •expr { expr {$1 * 10} }faster thanexpr {$1 * 10}?mcc
in reply to Bitslingers-R-Us • • •Dragon-sided D
in reply to Bitslingers-R-Us • • •@AnachronistJohn
Is 1+0+0 faster than 1+0?
Of course not; there are few opcodes on the right expression, so the left is constant-order slower by the number of "+"
Same here, but compounded two similar ways:
First, your left expression has an extra code block, which means storing off exception stack, local variable scratchpad, etc, and then restoring them all when done.
Second, I would expect "expr" itself to be a heavyweight opcode, having to prep for a whole new execution context.
Dragon-sided D
in reply to Dragon-sided D • • •@AnachronistJohn IIRC TCL is kinda doing the opposite of what you'd expect from the syntax in any other language; the braces are telling it to keep the stuff inside in the *current* execution context
(but I could be wrong; haven't used TCL in a loooong time)
Dragon-sided D
in reply to Dragon-sided D • • •@AnachronistJohn Hold up, finally reading the thread more carefully:
> {} ... disable interpolation
But wait if interpolation is disabled, I expect "$i" to be a literal string, not a variable with some numeric value.
Right?
So
{$i * 10}
Should either error out, or evaluate to 0 assuming Perl-like treatment of nonnumeric strings as 0 value
mcc
in reply to Dragon-sided D • • •Dragon-sided D
in reply to mcc • • •@AnachronistJohn FML
So yeah, eval is itself even more expensive than I assumed
TCL was useful only as a way to deliver Tcl/Tk
Now... I mean, we have Befunge
dixego
in reply to mcc • • •what
whhwhwat
mcc
in reply to dixego • • •Chris Ammerman
in reply to mcc • • •mcc
in reply to Chris Ammerman • • •@cammerman It was actually quite usable as a programming language, although I'm not happy that you had to carefully keep track of when to use () and when to use {}
(TCL also has this problem a little.)
Chris Ammerman
in reply to mcc • • •I think it would be really interesting to try to write something in Emily. Or to try to learn an Emily codebase.
I think it would be tough for me coming from a C-family language background, we love our commas and curly brackets. Losing them feels almost like losing an eye.
mcc
in reply to Chris Ammerman • • •Ellyse
in reply to mcc • • •mcc
in reply to Ellyse • • •@ellyxir it is trying to be dynamically typed ML, and ML is haskell lite.
(the name is a reference to ML. ML-y.)
Ellyse
in reply to mcc • • •mcc
in reply to Ellyse • • •Ellyse
in reply to mcc • • •mcc
in reply to Ellyse • • •@ellyxir If you look at it, my advice is:
Short term advice: opam is very nice and I recommend using it early
Longer term advice:
- You can ignore the OOP extensions, I never used them
- Do not use ocamlp4. If you are tempted to ocamlp4, use ppx.
- Do not be afraid of ref
dr 🛠️🛰️📡🎧
in reply to mcc • • •You can [eval { ... }] to get the interpolation back...
But yeah, it's terrible compared to today's languages. And don't get me started on the lack of libraries.
You can see why it would be great as a better shellscript, tho.
mcc
in reply to dr 🛠️🛰️📡🎧 • • •CatSalad🐈🥗 (D.Burch)
in reply to mcc • • •Kristoffer Lawson
in reply to mcc • • •there’s a very important reason for that. Remember, everything is a string. Code is too. Passing a code body to e.g. [proc] is just that. You are not passing a block, but a string wrapped in {} so as to avoid evaluating variables and everything else inside the body parameter. You could pass it in “ but you would have to escape lots of stuff.
#Tcl takes a while to fully understand, but it is very consistent which allows a lot of very nice things.
Oblomov
in reply to mcc • • •«this year I'm going to do AOC by choosing the worst fit language for each of the tasks»
Joking aside, I wonder what are the chances that picking languages at random* one ends up with the worst possible pairings?
*Or at least independently from the task
[_]
in reply to mcc • • •It feels like there are "ideal" versions of babel of code where languages are matched either ideally or optimally badly to their problems. I imagine one would feel incredible—until you tried to use a language for anything else—while the other would feel awful the entire time but make it surprisingly pleasant if you ever used one of those languages again.
I would've guessed more random pairings would be the best way to avoid that disenchantment but it sounds like that just hits both extremes. v_v
mcc
in reply to [_] • • •Gilles Grüngürtel
in reply to mcc • • •Meanwhile, in the Wild World of HPC: github.com/envmodules/modules
(Just had this 'splained at FOSDEM, use it daily at the $DAYJOB.)
GitHub - envmodules/modules: Environment Modules: provides dynamic modification of a user's environment
GitHubOblomov reshared this.
Oblomov
in reply to Gilles Grüngürtel • • •Gilles Grüngürtel
in reply to Oblomov • • •FOSDEM 2025 - Environment Modules: why this old idea is still useful today and what's next
fosdem.orgOblomov reshared this.
Brian Campbell
in reply to mcc • • •Interestingly, it survived well into the 2000s on macOS in the form of MacPorts, which was one of the more popular macOS distributions of free software until it was supplanted by Homebrew: guide.macports.org/#developmen…
You keep on finding Tcl in these weird little niches, like MacPorts and the Verilog community.
Interestingly, @cliffle has recently mentioned that he has two different embedded Tcl-like languages that he maintains, written in Rust: github.com/cbiffle/wartcl and github.com/cbiffle/remolt
It seems like one of these little languages that's never really prominent, but will never really go away either.
GitHub - cbiffle/wartcl: Very tiny embeddable Tcl-like language in safe Rust
GitHubJoe Groff
in reply to Brian Campbell • • •Oblomov reshared this.
mcc
in reply to Joe Groff • • •Mark Bessey
in reply to Joe Groff • • •Sensitive content
@joe @unlambda @cliffle TCL is weird in that a lot of its (relative) success came not because of the language design, but almost in spite of it.
I did some significant development in TCL a few decades ago, and chose it *entirely* because of "expect", which was the best tool for what we wanted to build (an automated test for a full C/assembly debugger suite).
Similarly, back in the day, a lot of people used Tcl because it was the preferred way to get access to Tk, which was just the best UI framework for Unix machines.
mcc
in reply to Mark Bessey • • •simon
in reply to mcc • • •Agree, Tcl has become a niche language.
It's quite small and easily linked into C projects if you want to add configuration and scripting. I suspect that Lua has overtaken it in that area, too.
There's one closely related language which I constantly come back to: Expect en.m.wikipedia.org/wiki/Expect
I've found nothing better for automating interactive programs.
extension to the Tcl scripting language
Contributors to Wikimedia projects (Wikimedia Foundation, Inc.)Oblomov reshared this.
mym
in reply to mcc • • •mcc
in reply to mym • • •crzwdjk ✅
in reply to mcc • • •mcc
in reply to crzwdjk ✅ • • •bluqxu
in reply to mcc • • •Ed Soldat
in reply to mcc • • •One of the other niches where TCL persists is in spacecraft testing, particularly in Europe, where it is the scripting language for a popular test automation software suite.
I found TCL hideous to begin with (and still do for anything intensely numerical), but found more things to like about it as time went on. I particularly like that its homoiconic nature supports writing seamless script language extensions - something I miss when working in Python and similar languages.
Pippa Brooks
in reply to mcc • • •Peter Amstutz
in reply to mcc • • •It is a close cousin to shell script except command lines call functions instead of programs.
I don't know if they ever fixed this but at the time I used it, "what if it was all strings?" specifically meant C strings and as a result you couldn't handle binary data with zero bytes because they would be treated as string terminators.
mcc
in reply to Peter Amstutz • • •mcc
Unknown parent • • •mcc
Unknown parent • • •Josh Jersild
in reply to mcc • • •Tom Forsyth
in reply to mcc • • •mcc
Unknown parent • • •Riley S. Faelan
in reply to mcc • • •You see, in the '60s, a breakthrough was done in linguistics, Noam Chomsky & his pals developed generative grammar theory, and it turned out so useful that Niklaus Wirth and his pals made it into a whole theory of how to make nice programming languages.
Unfortunately, the way it's commonly taught "looks like maths". There's a type of people who hate this look, and there have been several waves since late '1960s to build programming languages while avoiding the fun theory. Making everything into a string is typically a common starting point, even though it only really works well in the context of shell scripts, preprocessors, and, arguably,
m4. In REXX's world, it's probably defensible, because REXX is primarily a shell scripting language (for some weird kinds of shells, out of the IBM's world). In SAS macro language's world, it's somewhat defensible, on the basis that it's "supposed to be" a preprocessor. I wouldn't dare to argue for it in any of the contexts that Tcl is used, though.A sad irony is, while a lot of people imagine Tcl to have come out before solid competitors to it were available, this is also not the case. Tcl is way younger than, for example, AWK. (And AWK was carefully hand-designed using Wirthian theory, until somebody at Bell Labs shaved enough yaks to make yacc.) If not for the early flames of copyright wars, Tcl would probably have died within a few years the way most bad ideas are supposed to.
Brian Beach
in reply to mcc • • •Back in the early days at TiVo we used a lot of Tcl. I finally printed out the one page in the documentation that describes the string substitution rules and taped it to the wall.
The thing that hurt my head the most, coming from a Lisp background, is that a list containing one thing and the one thing have exactly the same representation.
mcc
in reply to Brian Beach • • •Poul-Henning Kamp
in reply to mcc • • •The thing people missed about Tcl was that it was meant to be a language you built into things, a foundation for creating DSLs.
It did happen, there is a number of routers&switches which you configure in Tcl, and it pops up in odd-ball industrial and medical equipment configurations as well.
Lua came five years after Tcl, aiming for the same niche.
The world would have been a much better place if Intel had used Tcl or Lua instead of inventing the kludge ACPI.
mcc
Unknown parent • • •mcc
Unknown parent • • •mcc
Unknown parent • • •@gutmunchies
1. Yes
2. Yes
Pa🇵🇸
in reply to mcc • • •Sensitive content