Hacker News new | past | comments | ask | show | jobs | submit login

Copy-pasting a "hype" checklist I made some eons ago:

* Extremely consistent and elegant syntax - whole syntax/grammar is described in 12 rules in a single man page (Tcl(n)) of 150 lines and there's no reserved keyword. Nearer to CL than Python on that point.

* Homoiconic through strings (like almost every language with eval) but most importantly, through "list-like" strings.

* Official man pages! No web-only and spec-like doc like cppreference nor lackluster "minimalist" stuff like pydoc (compare `pydoc print` with `man n puts`, for example).

* One of the simplest if not the simplest interaction with C, letting you write C plugins very easily (with critcl and swig to help).

* Not slow, not fast. In the same ballpark as cpython or Perl; doesn't need a tracing garbage collector, refcounting does the job since no cycles are possible by design (worse for throughput, but lighter runtime).

* Fun type system that is superficially "everything is a string" (like sh) but in reality "everything is a tagged union with on-the-fly conversion when needed and a guaranteed string representation". Allows for transparent serialization (`puts $mydict stdout` <=> `set mydict [read stdin]`), like CL's read/write.

* Powerful introspection through `info` (mainly). Allows for stuff like getting the name/body/arglist of a procedure, get all the registered procedures, know if a variable exists, get information on the stack frames and their content, etc... Together with `trace`, you can even write an internal debugger in few lines.

* Procedure arguments are passed by pointer with a copy-on-write system: don't modify the argument and you don't get any memory copy. To you, it just looks like regular passing by value.

* Modifying the procedure arguments is done via `upvar`: in Tcl, a variable reference is just a name (string) attached to a relative stack frame number, quite elegant considering the language's core concepts.

* If you use at least the builtin extensions (thread, http, tdbc, tcltest, msgcat) and the very basic tcllib/tclX/tclUdp/tklib packages, you're almost set for life. Personally, I also recomment the very convenient tclreadline, tdom, pipethread, tablelist and tclcurl.

* Channels is one of the cleanest I/O implementation I've ever used with some cool features:

- Transformations allowing filters like deflate/zlib/gzip or TLS to be put on a channel (see `transchan` for the API).

- Reflected aka virtual channels, to make your own channels. Basically like glibc/BSD's unportable fopencookie/funopen or CL's gray streams.

- Centralize a lot of ioctl/fcntl mess and even more (like defining the EOF char) in `chan blocked/configure/pending`.

- Integration with the event loop via `chan event/postevent` allows for a nice callback oriented approach to sockets and pipes.

- Other third-party channel types include pty (expect), random, memory or fifo (memchan).

* Builtin event loop (see `after`, `vwait`, `socket -server` and `chan event`) for powerful and seamless concurrency/command scheduling. Much simpler than Python's very "AbstractBeanFactory" asyncio.

* An elegant thread extension consisting of an interpreter per thread and no raw access to other thread's memory. Comes with both simple (`thread::send/broadcast/transfer`) and performant (`tsv`) synchronization/communication facilities.

* Finally a sane, light and portable (even more with Tile) GUI toolkit: Tk.

* One of the fastest Unicode aware regex implementations, written by Henry Spencer himself. Has its own greater-than-POSIX-ERE syntax called ARE, not as complete as PCRE (lacking lookbehind constraints, most importantly), but still great for an hybrid NFA/DFA engine. Performance comparison with Perl: https://github.com/mariomka/regex-benchmark/pull/44.

* `uplevel` (eval a script in a different stack frame) and `tailcall` (replace the current procedure with another command) let you augment the language by implementing control structures and keywords yourself. Inferior to CL's synergy between unhygienic macros, "naked AST" style homoiconicity, symbols as first-class objects, gensym and quasi-quoting, but still quite powerful.

* Safe interpreters let you do very fun things like config files in Tcl with limited access to the machine and master interpreter.

* Recent versions (>= 8.5) really embraced FP with:

- Real lambdas (but not closures, these have to be emulated) through apply.

- Purer hash maps (dict) than ugly sticking-out-like-a-sore-thumb arrays.

- Lisp style prefix arithmetic (allowing for `* 3 [+ 1 2]` instead of `expr {3 * (1 + 2)}`) including sane behaviour for more than two (reduce) or zero (neutral element) arguments.

- Builtin map/filter (lmap) with 8.6. See https://wiki.tcl-lang.org/page/Functional+Programming for more.

* Multiple more-or-less powerful OO systems (now based on the builtin TclOO): [incr Tcl] for C++ style OO, XoTcl for a take on CLOS or Snit for something Tk oriented.

* Some massive issues on the top of my head: lacking a LSP/SLIME equivalent, the warts of the weird type system (no way to differentiate between atoms and single element lists or evenly sized lists and dicts), missing metaprogramming facilities like quasi-quoting, no official support for UDP and UNIX domain sockets, no GC for class instances (cf https://core.tcl-lang.org/tips/doc/trunk/tip/550.md), no FFI in core, subtly broken exec (cf https://core.tcl-lang.org/tips/doc/trunk/tip/424.md and https://core.tcl-lang.org/tips/doc/trunk/tip/259.md)

Here are some project I made with it, still worth using compared to CL which is my true love, simply because its stdlib is better suited for a lot of tasks:

  https://git.sr.ht/~q3cpma/mangadex-tools
  https://git.sr.ht/~q3cpma/rymscrap
  https://git.sr.ht/~q3cpma/lemonbar-tcl
  https://git.sr.ht/~q3cpma/tcl-misc



This is a great list.

> * Safe interpreters let you do very fun things like config files in Tcl with limited access to the machine and master interpreter.

I keep looking for similar functionality in Python (the scripting language of choice for many, nowadays) but I am always disappointed.


The python-esque sandboxed language is Starlark: https://github.com/google/starlark-go#documentation


This is great, but unfortunately it means you have to work with something different than Python (in developing, in deploying, etc.), doubling your dependencies.


Lua is another language that lets you do this!


For the few interested people, took the time to make a final version in Markdown with lots of links and some improvements/proofreading: https://gist.github.com/q3cpma/a0ceb6a7c6a7317c49704630d69b7...


>refcounting does the job since no cycles are possible by design

So double-linked list is impossible to define?


You can't define new data structures as such in pure Tcl, as you don't have pointers. And as for cycles, you can't modify an object to add a reference to itself, since the copy-on-write will just create a new object.


Rosetta Code has examples of DBLs in Tcl and Tcl::OO.


Sold. I know what I'm doing this weekend.


Hey, you missed out coroutines :-)


I did, and I also missed coroinject/coroprobe being new in 9.0 (from the full release notes). Seems like a delightful new way to blow minds.


Indeed the backing implementation /generalization, stackless non-recursive engine (NRE)[0], developed by Miguel Sofer (RIP).

[0] https://wiki.tcl-lang.org/page/NRE




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: