5 ms·
Picol: A Tcl interpreter in 500 lines of code
- anthk 9mo agoJimTCL has more features and it's almost as small.
- catwell 9mo agoYou probably know but others might not: they have the same author.
- JSR_FDED 9mo agoI remember we had users at a chip foundry who were super deep into TCL. Is it still used anywhere else? Would you use it for a new project if you for instance already knew Python or Lua?
- danhor 9mo agoIt's still the lingua-franca of ASIC/FPGA/Simulation, especially for scripting the tools. I think it's slowly being replaced there by Python, but it's very slow.
- xantronix 9mo ago> but it's very slow The process of replacing Tcl, or Python itself?
- catwell 9mo agoAntirez (the author of this interpreter) uses it for the Redis test suite. 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 http://lua-users.org/lists/lua-l/2021-01/msg00067.html
- JSR_FDED 9mo agoThat was interesting to read. So in your case it came down to ecosystem depth, especially on Windows - where there was a TCL solution to talk ODBC, but the equivalent Lua functionality had issues on Windows.
- vodou 9mo agoIt is still used for operations procedures in, at least, European space industry. E.g., in mission control systems from Terma (CCS5 and TSC).
- sprash 9mo agoTcl/Tk to this day is the best tool to make GUI frontends for CLI applications. Besides that, in the past I used it in production for intranet database entry applications. It has since been replaced by Flask. In my opinion the higher complexity of the Flask version is no way justified and we should have kept the much simpler ~2k LOC Tcl/Tk solution.
- fuzztester 9mo ago>Tcl/Tk to this day is the best tool to make GUI frontends for CLI applications. 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?
- sprash 9mo ago> Why? 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.
- fuzztester 9mo agothanks.
- pwg 9mo ago> Why? Please elaborate. 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.
- rausr 9mo agoWe've got Check Point Firewalls at work, and during updates I see lots of .tcl in the web UI.
- AceJohnny2 9mo agoI'm looking to use TCL for an embedded platform, as the scripting shell. Its simplicity and small size is key, as is its easy integration with C.
- smartmic 9mo agoIt is at the core of the SQLite test suite and also a first-class citizen in interfacing to it.
- amelius 9mo agoBy the way, I'm guessing that Tcl was (is?) big in EDA because John Ousterhout also wrote the EDA tool Magic. https://en.wikipedia.org/wiki/Magic_(software) https://en.wikipedia.org/wiki/Magic_(software)
- w4der 9mo agoTcl's first "release" was in 1988 and Magic was released in 1984, but it seems like John Ousterhout then wrote Tcl to have a common interface across tools [https://web.stanford.edu/~ouster/cgi-bin/tclHistory.php https://web.stanford.edu/~ouster/cgi-bin/tclHistory.php]. It still is a big thing in EDA, because (in theory) it lets a chip designer run their designs by tools from different vendors
- shawn_w 9mo agoI like tcl as an alternative to shell for any non-trivial scripts. And its coroutines + built in event loop makes for really nice seamless async style programming.
- uwagar 9mo agoi like calling a function f without arguments simply as 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.
- mbirth 9mo agoThe MacOS hex editor HexFiend uses Tcl for its template language. > https://github.com/HexFiend/HexFiend/blob/master/templates/Tutorial.md https://github.com/HexFiend/HexFiend/blob/master/templates/T...
- netrap 9mo agoI recall my time in satellite control systems had a lot of TCL code.
- prinny_ 9mo agoThe previous company I was working at had quite a lot of TCL code for their back end logic. Betting sector, well known in US and Europe. They still actively hire people to maintain the codebase. Rock solid code, no surprises, was able to handle tens of thousands of concurrent bets.
- antirez 9mo agoRelated: https://github.com/antirez/aocla https://github.com/antirez/aocla
- iberator 9mo agobest thing about TCL is easy syntax and that everything is a string :) Unique and simple and easy language with very slow changes. 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
- IshKebab 9mo ago> best thing about TCL is easy syntax and that everything is a string :) What? That's the worst thing about TCL.
- iberator 9mo agoI love it. Living proof that languages doesn't need forced types. Data is Data. It's kinda object programming as visioned in the 70". So easy and trivial language.
- IshKebab 9mo ago> Living proof that languages doesn't need forced types. 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.
- bmacho 9mo agoTcl has these types as well. They are special strings. Number: string of digits. List: strings separated by space. Dictionary: key value pairs in a list.
- IshKebab 9mo agoNo they aren't. Everything is a string. The runtime does some optimisation where it actually does use different types under the hood but they don't change the semantics. If you try to pass a list into a function expecting a string it will just treat the list as a string. No type error or anything, not even at runtime. CMake is the same. Terrible design. Real types are useful.
- stevekemp 9mo agoSadly it seems the blog post that was released in the past is no longer available, but the wayback machine has a copy https://web.archive.org/web/20220303135439/https://oldblog.antirez.com/page/picol.html https://web.archive.org/web/20220303135439/https://oldblog.a... That provides background about the constraints/limitations in this code.
- antirez 9mo agoRestored. Recently I migrated all my stuff into a new server and missed to migrate the /pages of the old blog. Thanks.
- seyz 9mo agoClassic antirez. Does more in 500 LOC than most frameworks in 50k.
- thomasmg 9mo agoYes. His work is really inspiring, eg. the text editor less than 1000 lines, tiny language in less than 1000 lines etc. When I read this on HN, I converted his text editor to my hobby programming language [1] (330 lines), and then wrote a chess engine with terminal UI [2] (400 lines), Tetris clone [3] in 140 lines. I also have a QR code generator and parser [4] (700 lines, still in Java only), a PDF generator (200 lines), and now also a tiny programming language [5]. [1] https://github.com/thomasmueller/bau-lang/blob/main/src/test/resources/org/bau/converter/textEditor.bau https://github.com/thomasmueller/bau-lang/blob/main/src/test... [2] https://github.com/thomasmueller/bau-lang/blob/main/src/test/resources/org/bau/converter/chess.bau https://github.com/thomasmueller/bau-lang/blob/main/src/test... [3] https://github.com/thomasmueller/bau-lang/blob/main/src/test/resources/org/bau/converter/blockGame.bau https://github.com/thomasmueller/bau-lang/blob/main/src/test... [4] https://github.com/thomasmueller/bau-lang/blob/main/src/test/java/org/bau/stdlib/qrcode/QrCode.java https://github.com/thomasmueller/bau-lang/blob/main/src/test... [5] https://thomasmueller.github.io/bau-lang/at.html https://thomasmueller.github.io/bau-lang/at.html
- analog31 9mo agoQuite a few years ago, I was looking for a way to program microcontrollers via an onboard interpreted language, and happened on the picol code. I still have my version somewhere. It was delightfully straightforward and easy for an amateur to modify. So I first got it to compile on a Teensy, then added a REPL, floating point, and a few functions to do things like flip the GPIO bits and read the ADC. 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.
- antirez 9mo agoThanks for your comment! Maybe it's time for picol2.c, same amount of lines of code, but floats and [expr]. I'm going to use a few hours today to get there. Such small changes would make it more practical for real use cases where one wants to retain understandability.
- antirez 9mo agoReleased.
- Western0 9mo agoNice idea. picol is ideal for writing other language, for example esotheric language