Tcl lsort command

lsort is a command to return a sorted list based on option. Default option is to sort alphabetically (-ascii) and ascending (-increasing). lsort can also sort numerically using -integer or -real option. lsort can also sort based on a element on sub list using -index option.

There are more options available. Here we will see some examples of lsort in action.

Tcl Octalogue

Octalogue is eight rules that describe Tcl language as found from

A script is composed of commands delimited by newlines and semicolons, and a command is composed of words delimited by whitespace.
After escapes and substitutions in each word are processed, words preceded by {*} are transformed into multiple words in the command, the first word of each command is used to locate a routine, and that routine is called with the remaining words as its arguments.

Continue reading “Tcl Octalogue”

Tcl Expr command

All in tcl is string, so expr exist as command to evaluate numeric value. On other language like ruby if we write 1+2 <enter> on the irb console will print 3, but thats not the case with tcl.

To get numeric calculation on Tcl we need to use expr command.

Evaluating logical also work with expr command. Examples below.

By remembering Tcl rule : “All is string”, we can conclude that expr result will be string as well.

Fossil version control

Recently bitbucket accounce that they will discontinue mercurial support on their hosting by 2020. This event make me move my existing mercurial repo on bitbucket to git which they also support.

Recently i also learning some about Tcl and come across that Tcl project use fossil as their version control. But fossil is more than version control !  Its also unique by using sqlite database as its repository storage. No wonder because fossil is created to support sqlite project by its creator D Richard Hipp.

So i came to study fossil SCM on its website and installing it on my linux, openbsd, and windows laptop. Installing on openbsd is done by pkg_add fossil. Fossil website also provide fossil as a precompiled binary file and all you do to install is by copying it to your path. Its simple and powerful.

Go to fossil website :


Tcl : lset

Tcl have lset command to change value of list’s element.

lset varname index newvalue

Some example of lset on variable named a is presented below.

Lset command can set value of nested list too.

Thats all …

Tcl : nested list

Here is various way to create nested list in tcl. Remember that every thing is a string in Tcl.

% set nestedlist1 { 1 2 { a b c } 3 { d e f } 4 5 }

%set nestedlist2 [list 1 2 [list a b c] 3 [list d e f] 4 5]

%set innerlist1 {a b c}

%set innerlist2 [list d e f]

%set nestedlist3 “1 2 $innerlist1 3 $innerlist2 4 5”

Lindex command can also used to extract an element of nested list.

%lindex $nestedlist1 2 1


Try it on tclsh by hand ! Bye …

Tcl list : creation, length, and extracting element

In Tcl everything is a string. List is also a string. The simplest form of list is a string with zero or more space separated words. Lets set a variable with 3 elements list containing 1,2, and 3.

% set var1 “1 2 3”

% set var2 [list 1 2 3]

% set var3 {1 2 3}

Here we set var1,var2, and var3 to a list, with 3 different way.

To return the number of elements in a list we can use llength command.

% llength $var1


To extract an element from list we can use lindex command.

% lindex $var1   1


As we can see list has zero based index. The first element is at index 0. Lindex command can accept end and end-? as argument.

% lindex $var1   end


% lindex $var1  end-1


Thats all for now.