131 points · by tosh · 9mo ago · 72 comments
Today of course there are things like CircuitPython, and I enjoy using it too, but it's such a beast that it's really impenetrable for someone at my skill level if I want to add low level functions.
https://web.archive.org/web/20220303135439/https://oldblog.a...
That provides background about the constraints/limitations in this code.
[1] https://github.com/thomasmueller/bau-lang/blob/main/src/test... [2] https://github.com/thomasmueller/bau-lang/blob/main/src/test... [3] https://github.com/thomasmueller/bau-lang/blob/main/src/test... [4] https://github.com/thomasmueller/bau-lang/blob/main/src/test... [5] https://thomasmueller.github.io/bau-lang/at.html
Something like Python in good old days of 2.x before young internet javasceipt devs started pouring A LOT of new features to the language (feature creep).
Nowadays Python is so complex and flooded with ex C, C++, Java, JavaScript, Haskell programmers adding so many features, so fast that it's impossible to follow and understand them :(
Languages should not evolve on that rate. No time to master it :(
/rant
> In earlier versions of Tcl, strings were used as a universal representation; in Tcl 8.0 strings are replaced with Tcl_Obj structures ("objects") that can hold both a string value and an internal form such as a binary integer or compiled bytecodes.
http://www.ira.inaf.it/Computing/manuals/tcl/man-8.0/Changes...
I remember this quite well, because as part of the core team tasked with writing native C extensions, the migration to Tcl 8 had quite an impact on our code.
I learned Python with version 1.6, and have a few O'Reilley books proving the point the language wasn't really that simple, those that never bothered reading the reference manuals end-to-end though it was.
I guess that's why Tcl is so popular in the EDA arena. I can stick some custom JTAG tooling in a Cyclone II design and talk to it by Tcl-scripting the 15-year-old software - and be confident that the same code (both in the FPGA and on the host computer) would work with the latest software and a current device.
Having said that, Tcl's not entirely free of compatibility and fragmentation frustrations: I sometimes wish that OpenOCD used full-fat Tcl rather than JimTcl, just so that I could make use of Tk. Being able to plot a histogram of data collected from the FPGA or make clickable buttons to trigger events is very useful.
What? That's the worst thing about TCL.
Data is Data. It's kinda object programming as visioned in the 70".
So easy and trivial language.
The opposite surely? TCL is practically dead, and only lingers on in the EDA industry (which has zero taste). Virtually every successful language today has at least a few different basic types for numbers, arrays, strings, maps and so on.
When "everything is a string" then you have no choice but to literally treat everything as a string. Painful. Very cool project though.
For a syntax example, compare python to Tcl. In python, there's a compact array lookup operator, and dictionaries allow string keys:
mydata["channel"][2]
Tcl, however, requires a function call to access an array index, resulting in nested function calls with magic numbers for the simplest expressions: lindex [lindex $mydata 35] 2 # Tcl
Then there isn't any static type checking so you have to run code to see if it would work; the shape of a return may surprise you. Connecting to hardware may be your only opportunity to exercise certain code paths.So for any non trivial task, Tcl becomes effectively write-only.
Some tools allow you to export Tcl scripts that automate tasks like project creation to help you avoid tracking intermediate objects in source control, but because the Tcl cwd path can change throughout a script, they export every source path as a hard coded absolute path, including whatever developer's home directory it might be residing in. This is not suitable for source control (because it would preclude building on any other machine) so then you have to post process these scripts before tracking them. But since it's Tcl there aren't good scriptable tools for programmatic Tcl AST manipulation, so you have to modify these files with some sort of a state machine, looking for various sentinels to trigger the various string replace behaviors you need. It's not all Tcl's fault, but if a vendor is only using Tcl for automation and you need automation, you have a battle ahead of you.
Outside the language, you'll often find that your runtime tool locks the UI thread to run your scripts, so long running operations are impossible to pause or cancel. And I've never seen a vendor expose adequate objects to allow full control, so often, the critical actions you hoped to automate are only possible through the GUI.
In the 90s, an integrated Tcl interpreter was a good sign that your vendor cared about developers. Today it's more a sign of neglect.
I couldn't tell you exactly all the thing that are wrong with it. Let's just say that a language where this is ok:
puts "Hello"
But this is not:
puts "Hello" # A comment
shouldn't exist.
(I still remember the excitement of EDA tools _starting_ to support TCL and replacing the custom scripting engines they used to have)
Personally, I know Lua and Python very well but I still used TCL a few years ago for something very specific: using ODBC on Windows. I gave more details on the Lua mailing list here: http://lua-users.org/lists/lua-l/2021-01/msg00067.html
Why? Please elaborate. I've heard others say this, but would like to know more.
>Besides that, in the past I used it in production for intranet database entry applications.
GUI apps?
CLI applications typically read text from stdin and write text to stdout. The tcl model of "everything is a string" makes exactly the right abstraction to create GUI frontends for CLI applications rapidly and keep them simple at the same time.
Tk's GUI object model is sitting at a reasonable maxima between trivial to make use of vs. triggering the events necessary to make the GUI active.
Small example. You want a button on your GUI that triggers a procedure called "process" when it is clicked, this is the code you need (if you are fine with the remaining defaults) (and assuming you used 'pack' as the geometry manager):
button .process -text "Process Entries" -command process
pack .process -side top
And a fully active GUI button will now appear at the bottom of your Tk window, with a label of "Process Entries" and when you click it, a Tcl procedure named "process" will be executed.I was looking into this for v9 and gave up on finding a binary which was:
- easily found
- agreed upon as the one to use
- available for and easy to install on all three platforms
Should I look again?
For jimtcl (the production-ready minimalistic tcl implementation which antires started (with full closures & gc'able lambdas) - probably an outgrowth of picol), you can get static "(some) batteries included" binaries at:
https://github.com/dbohdan/jimsh-static
For full tcl with the kitchen sink, bathtub & shower included, for android (hence the name) & regular Linux:
I think it's slowly being replaced there by Python, but it's very slow.
The process of replacing Tcl, or Python itself?
And its coroutines + built in event loop makes for really nice seamless async style programming.
> https://github.com/HexFiend/HexFiend/blob/master/templates/T...
f # first word in TCL command line is a command
rather than
f ();
if there was also a function called g, i like to do things like
set a f
$a # calls f
so i can now
set a g
$a # calls g
cool i think.
picol is ideal for writing other language, for example esotheric language