Recent online articles about Tcl/Tk.

Learn Tcl by writing a simple game

James Farrell 2023-02-23

Explore the basic language constructs of Tcl, which include user input, output, variables, conditional evaluation, looping, and simple functions.

Learn Expect by writing and automating a simple game

James Farrell 2023-02-13

Code a "guess the number" game in Expect. Then, learn the real power of Expect with a separate script to automate playing the game.

Learn Tcl/Tk and Wish with this simple game

James Farrell 2023-04-24

Here's an easy coding project to get you started with Tcl/Tk.

Tcl 8.7 feature updates

A series of posts describing enhancements in Tcl 8.7.

Using async/await to parallelize sequential code

Ashok P. Nadkarni 2018-12-29

A previous post in our series on promises introduced the async and await commands. That post focused on how these commands further simplify asynchronous programming with promises. This post takes a different angle on their utility - how they can be used to speed up sequential code with minimal effort. more...

Parsing via metaprogramming

Ashok P. Nadkarni 2018-12-21

What is metaprogramming? Roughly speaking, metaprogramming involves writing a program that in turn writes a program to do the desired task. In some cases metaprogramming makes for simpler or more succinct code while in others it optimizes performance by generating specialized code at runtime. Tcl lends itself naturally to this style of programming. This article illustrates one such use. more...

Using async/await to simplify promises

Ashok P. Nadkarni 2017-11-03

In a series of prior posts, I had introduced the promise abstraction along with the promise Tcl package and how it can greatly certain forms of asynchronous computation. As mentioned there, the Tcl package is roughly based on the promise framework implemented in ES6 (ECMAScript, aka Javascript). ES7 introduced the async and await functions which further simplify asynchronous programming with promises in certain scenarios. Accordingly, the Tcl promise package has been updated to include the equivalent commands. This post introduces their use. more ...

Tk Cocoa 2.5

Kevin Walzer 2017-12-14

Nearly three years ago I made announced a significant overhaul of Tk on the Mac that amounted to a redesign of major portions of the GUI library. The changes were intended to address flaws that had emerged in the initial, whole-cloth migration of Tk from the Carbon to the Cocoa API by Daniel Steffen.

Ah, the best-laid plans of developers. Tk on the Mac in fact was NOT in a complete place, and later that summer, Marc Culler, who contributed many of the critical patches for Tk-Cocoa 2.0, and I did some additional major refinements. At that point Marc's contributions were so substantial that he essentially became the co-maintainer of Tk on the Mac, and I added his name to the author list.

Over the past six months, we have gone through an additional heavy round of development on Tk, to the point where I consider this yet another major iteration of the toolkit and not just an incremental set of updates. Should this round be called, informally at least, Tk-Cocoa 2.5? I think so. more ...

Recursion to Iteration via Coroutines

Ashok P. Nadkarni 2017-09-10

Many programming tasks are very simply expressed and implemented through recursive algorithms, traversing a tree data structure being just one example. The primary reason recursion simplifies implementation is that the state of the computation is implicitly maintained, freeing the programmer from the burden of explicitly tracking the computational state of the program. For example, in a recursive tree walking implementation, the "current location" in the tree is implicitly tracked.

However, there are situations where a recursive model does not fit the needs of an application. For example, the application may want to traverse a tree in iterative fashion, retrieving one node at a time, operating on it and then potentially doing some unrelated computation before retrieving the next node at some unknown point in the future.

Here is where coroutines can bridge the impedance mismatch, presenting an iterative interface to a naturally recursive algorithm more ...

Exploring Tcl internals from script - Part II

Ashok P. Nadkarni 2017-08-04

A previous blog post described the representation command and its use for introspecting Tcl's internal structures for storing data. I promised a follow-up post that talked about Tcl's compiled byte code and the disassemble command for inspecting it. Well, only two years later, here is that post as promised more ...

Exception handling in promises

Ashok P. Nadkarni 2016-01-23

In a prior post I had illustrated the use of the Tcl promise package for asynchronous computing with some examples. There we had ignored the possibility of errors and exceptions and how they are handled in promise-based code. In this post, we build on the examples in that post to illustrate how promises greatly simplify handling of errors in async code more ...

Promises by example

Ashok P. Nadkarni 2016-01-20

I had previously described an experimental implementation of promises for Tcl. On re-reading my earlier post, I was somewhat dissatisfied with the treatment there in that I did not feel it fully reflected the value of the promise abstraction, getting somewhat caught up in the details. This post takes a somewhat different approach, concentrating more on examples and refraining from going into detail about each command or method. Here I am more interested giving you a flavor of programming with promises and motivating you to explore further. more ...

Making promises in Tcl

Ashok P. Nadkarni 2016-01-08

This post is obsoleted by the promise package (based on the code is this post) and by newer posts on the topic. Nevertheless it may still hold some tutorial benefit.

There is quite a bit of hoopla in the Javascript world around the promise abstraction for asynchronous code. Implemented in various forms in third party libraries, it proved sufficiently useful to be formally defined and incorporated into ECMAScript 6.

Other languages, from Python and Scala to C#, C++ and Java, have implementations of promises in various flavors (sometimes separated into promises and futures). Not finding one for Tcl (we cannot let Tcl lag!), I started on an experimental implementation described in this post. more ...

Older articles are on Tcl Articles page.