Exploring Programming Languages — Tcl
Let’s continue our exploration of programming languages with an old but often overlooked one: Tcl.
Exploring Programming Languages — Tcl

Generated by Google’s Gemini
Let’s continue our exploration of programming languages with an old but often overlooked one: Tcl.
Not a Medium subscriber? 😕 You can read this post for free here 🥳
Tcl is not as old as other languages; it first appeared in 1988, 38 years ago.
I learned of Tcl around 2007, but I haven’t played with it since then.
Fun fact: Tcl stands for Tool Command Language because everything in Tcl is a command.
Second Fun fact: You may know about Tk, which is a widely used Graphic Library, but Tk is part of Tcl/Tk 😉
The application should work like this: we input 1977, and it returns:

LED Numbers output
Now, keep in mind that we want to show this to newcomers to Tcl, not to seasoned developers.
The first thing we’re going to do is to create a Hash that holds lists(Similar to a Map or a Dictionary in other languages), to hold all the components of the LED numbers:
array set leds {
'0' " _ ,| | ,|_| "
'1' " ,| ,| "
'2' " _ , _| ,|_ "
'3' "_ ,_| ,_| "
'4' " ,|_| , | "
'5' " _ ,|_ , _| "
'6' " _ ,|_ ,|_| "
'7' "_ , | , | "
'8' " _ ,|_| ,|_| "
'9' " _ ,|_| , _| "
}
Wait…I said a Hash, right? Why are we seeing an array declaration? Well, in Tcl, every array is actually a HashMap 😏
We’re separating each number into three lines. So, for example, if we were to print the number 6, we could do it like this:
set line [split $leds('6') ","]
lassign $line field1 field2 field3
puts $field1
puts $field2
puts $field3
Let’s analyze what is going on here:
- We’re going to get the contents of $leds using the key ‘6’.
- Then, we’re going to split the content by “,” and assign the results to the line variable, which is a list.
- Using lassign (list assign), we’re going to assign each value into their own variable and finally print them.
The result is going to be:
_
|_
|_|
Of course, we would like to print more than one number, so the idea would be to concatenate each number’s line and then print them:
set line [split $leds('6') ","]
lassign $line field1 field2 field3
set line [split $leds('2') ","]
lassign $line field4 field5 field6
puts "$field1$field4"
puts "$field2$field5"
puts "$field3$field6"
The result is going to be:
_ _
|_ _|
|_| |_
Of course, we need a way to automate this, as we don’t want to keep reading every new value and then adding these variables to the puts command.
Ok, we have then 3 lines that need to be printed. But an unknown number. It’s important to know at runtime how many digits our number has so that we act accordingly. Let’s say we want to print the number 1593, so we have 4 digits, and we need to print 3 lines, each line with sections of those 4 digits, so here’s our application code:
array set leds {
'0' " _ ,| | ,|_| "
'1' " ,| ,| "
'2' " _ , _| ,|_ "
'3' "_ ,_| ,_| "
'4' " ,|_| , | "
'5' " _ ,|_ , _| "
'6' " _ ,|_ ,|_| "
'7' "_ , | , | "
'8' " _ ,|_| ,|_| "
'9' " _ ,|_| , _| "
}
puts -nonewline "Enter a number: "
flush stdout
set num [gets stdin]
set numArray [split $num ""]
for {set i 0} {$i < [llength $numArray]} {incr i 1} {
set line [split $leds('[lindex $numArray $i]') ","]
lassign $line field1 field2 field3
append line1 $field1
append line2 $field2
append line3 $field3
}
puts $line1
puts $line2
puts $line3
Here, we define our array (hash map) and then ask the user for a number. The -nonewline is used so that the question and the input are on the same line.
flush stdout clears the input stream, allowing us to print the question to the user.
We’re going to split the number we receive as a parameter into an array named numArray, since we need each digit.
We’re going to use a for loop to iterate over each digit of the number parameter.
This loop will start at 0 and will end at the length of the digits array. The loop value will be incremented by 1 using incr.
To make things easier, let’s debug our application and see which values would be present on each iteration:
- We’re going to split the content of $leds that we get from using each digit as the key.
- We’re going to assign each value to a variable by using lassign.
- Using append, we will concatenate the value we get from $leds into a line variable.
- Finally, we print all three variables.
- For the first digit, which is 1, we’re going to read the content of $leds and extract the first element of the string. We’re going to concatenate this on line1—the second element on line2, and the third element on line3.
|
|
- For the second digit, which is 5, we’re going to read the contents of led and extract the first element of the string. We’re going to concatenate this on line1—the second element on line2, and the third element on line3.
_
| |_
| _|
- For the third digit, which is 5, we’re going to read the contents of led and extract the first element of the string. We’re going to concatenate this on line1—the second element on line2, and the third element on line3.
_ _
| |_ |_|
| _| _|
- For the fourth and last digit, which is 5, we’re going to read the contents of led and extract the first element of the string. We’re going to concatenate this on line1—the second element on line2, and the third element on line3.
_ _ _
| |_ |_| _|
| _| _| _|
If we name our application LEDNumbers.tcl, we can call it from the terminal window like this:
tclsh LEDNumbers.tcl

That’s it 🤓 I hope you liked it, and I will see you again on the next installment, where I will present Chapel.
— — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — —
Follow me on X: @Blag Follow me on BlueSky: @blag.bsky.social Connect with me on LinkedIn: Blag aka Alvaro Tejada Galindo
메타데이터
- post_id
- e63c4a5bc904
- slug
- exploring-programming-languages-tcl-e63c4a5bc904
- url
- https://blog.devgenius.io/exploring-programming-languages-tcl-e63c4a5bc904
- canonical_url
- https://blog.devgenius.io/exploring-programming-languages-tcl-e63c4a5bc904
- author_url
- https://medium.com/@atejada
- status
- ok
- fetched_at
- 2026-06-13 16:00:06