Tcl : Creating Array

Tcl array can be created by set command by specifying its key to array name.

From example above we define array named days with keys containing numbers and text values. If we try to do variable substitution with $days, it wont work. If we do variable substitution with key specified then it will work.

We can have text as array’s key. Tcl array is an associative array.

From sample above we know that a text key is case sensitive (ID is different with id).

Another way to create array is with array set command by passing list of key value pairs as 3rd parameter and array name as 2nd parameter.

Thats all how we create array in Tcl. Bye!

Tcl : for command

For command used on tcl to create looping with syntax below :

for start test next command

for command have 4 parameter. The first parameter is start block where we set an initial value to a variable (usually using set command). Second parameter is test block where we test a variable or condition(will be tested using expr command). The third parameter is next block which usually used to change variable value (can use incr command). The fourth parameter is command which will be executed in loop.

Basic example below , using i as variable :

Continue reading “Tcl : for command”

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 https://wiki.tcl-lang.org/page/Dodekalogue.

Script
A script is composed of commands delimited by newlines and semicolons, and a command is composed of words delimited by whitespace.
Evaluation
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 :

https://www.fossil-scm.org/home