Tcl
In this part of the Tcl tutorial, we will introduce the Tcl programming language.Goal
The goal of this tutorial is to get you started with the Tcl programming language. The tutorial covers the core of the Tcl language. Variables, lists, arrays, control structures and other core features. It is not a complete coverage of the language. It is a quick, introductory material. The tutorial was created on Ubuntu Linux.Tcl
Tcl is a string based scripting language. The source code is compiled into bytecode, which is later interpreted by the Tcl interpreter. It was created by John Osterhout in 1988. The purpose was to create a language which is easily embeddable into applications. But it is often used outside its original area. The language is commonly used for rapid prototyping, scripted applications, GUIs and testing. The Tcl stands for tool command language, where the source code of a Tcl script consists of commands.Tcl is a procedural language. It has some functional features. OOP support is planned for the next official release.
The official web site for both Tcl and Tk is tcl.tk
Popularity
There are hundreds of programming languages in use today. Tcl does not belong to the most popular ones. It has its own niche, where it used. According to the langpop.com site it scored 21. On tiobeindex, it ended on the 96. place.Interactive interpreter
We can run Tcl commands in a script or in an interactive interpreter. In this tutorial, we will use the interactive Tcl session to demonstrate some smaller code fragments. Larger code examples are to be put in Tcl scripts.$ tclshThis is an example of the Tcl interactive session.
% puts $tcl_version
8.5
% puts $tcl_interactive
1
$ tclshWe start the interactive session with the tclsh command.
% puts $tcl_versionThe prompt changes to the % character. We print the value of a special tcl_version variable to the console. It is set to the version of the current Tcl in use.
8.5
% puts $tcl_interactiveThe tcl_interactive variable tells us whether we are in an interactive mode or not.
1
Tcl scripts
We will have our first simple example of a Tcl script.#!/usr/bin/tclshIn this script, we print a message to the console.
# first.tcl
puts "This is Tcl tutorial"
#!/usr/bin/tclshEvery script in the UNIX starts with a shebang. The shebang is the first two characters in the script: #!. The shebang is followed by the path to the interpreter, which will execute our script. The /usr/bin/ is the most common location for the Tcl shell. It could also be located in /usr/local/bin/ or elsewhere.
# first.tclComments in Tcl are preceded by a # character.
puts "This is Tcl tutorial"The
puts
command prints a string to the console. $ which tclshThe path to the Tcl interpreter can be found using the which command.
/usr/bin/tclsh
$ chmod +x first.tclWe make script executable with the chmod command. And execute it.
$ ./first.tcl
This is Tcl tutorial
Sources
The following sources were used to create this tutorial:In this part of the Tcl tutorial, we have introduced the Tcl language.
0 comments:
Post a Comment