Tcl - a great engineering language
Archive - Originally posted on "The Horse's Mouth" - 2010-03-17 06:21:53 - Graham Ellis
Tcl is a very stable language that's great for engineers and we quietly get a lot of web site traffic looking at the examples on our web site. It's because one of those examples bubbles up to over 50 accesses per day that I've been reminded just how important the language remains.
Here's part of that popular page: [full example]
if [expr $cost > 100] {
set cost [expr $cost * 0.8]
puts "SPECIAL Group ticket at $cost"
} elseif [expr $cost > 20] {
set cost [expr $cost * 0.9]
puts "Group ticket at $cost"
} else {
puts "Total Price will be $cost"
}
Although the code looks fairly conventional, Tcl is actually a command base language rather than an operator based one. And that means that in the code above, spaces and line breaks are significant. if is a command. It takes a minimum of two space separated parameters - in this case there's one in square brackets, and one in curly braces. The curly brace parameter lasts severla lines ...
There are five more parameters to if in this particular example - "elseif", a "[]" condition, a "{}" block, "else" and finally another "{}" block. You'll note that only the "{}" blocks carry on from line to line - normally a new line is teh end of a Tcl command, and that means that placing the "{" on the end of the first line (and preceded by a space) is vital.
I really enjoy working with Tcl / giving courses in the language. For sure, I do more training on the likes of Lua, Python, Ruby and PHP these days, but please get follow the course links or get in touch if you would like a Tcl course!