Syntax, expressiveness and the beauty of Tcl
- From: Stephan Kuhagen <nospam@xxxxxxxxxx>
- Date: Mon, 30 Oct 2006 06:48:18 +0100
Good Morning Fellows
I just read the wiki-page about why Tcl syntax is so strange
(http://wiki.tcl.tk/2401). I already read it a while ago and the
discussion never really left my mind, since I'm often discussing and
comparing Tcl and Python with one of my colleagues.
My point is, that the very simple and straight syntax of Tcl (except,
maybe, for the very controversy {expand} in 8.5) makes it very simple
to learn the language for beginners. But only, I have to admit, if you
are not poisoned by other languages before. If you do not know any
other languages, IMO Tcl may be one of the most simple languages to
learn and understand. Very few syntax rules, very few different
concepts and a very clear semantics. It is so clear and simple, that I
often tend to write a complex expression (while programming in another
language or just when thinking about something) in a kind of pseudo
Tcl code, because of the clarity of Tcls expressiveness. It helps me
understanding, what I'm trying to think... (Nevertheless, there are
other reasons why it is hard today for beginners to learn and get used
to Tcl, but that was another thread here already)
+++
One point on the wiki-page was the syntax for math expressions like
x=a+b
in a "normal" language (whatever this means) which is
set x [expr $a+$b]
in Tcl. Okay, that _looks_ weird, but it isn't because it follows
perfectly the philosophy of Tcl. OTOH, when you have to write many
math expressions like this, the set-thing can be kind of
annoying. Some years ago, when it really annoyed me for one time, I
extended [unknown] to recognize math expressions and handle them with
expr, which was also suggested in the wiki. But that was _really_
strange... The most annoying thing about set... is, that it needs so
many finger movements, but the semantics is much clearer than the
first statement.
Anyway, in the wiki-article this was suggested to make it easier:
$ {c = a + b}
This looks very strange to me, since shell programming and Tcl in my
mind, always makes me think "$" is for variable substitution. Looking
at Perl or PHP where you can write
$c = $a+$b
really makes me sick. For me this is: set the variable, referenced by
the value of c to a+b. But the idea is interesting, only the syntax
does not fit into Tcl (IMHO). So i got the idea to do this:
---
proc : {args} {
if { [regexp {([^_0-9]\w*) *=} $args all vname] } {
uplevel set $vname [expr [string range $args [string length $all] end]]
} else {
uplevel eval expr $args
}
}
---
Now you can write:
: x = 10+10
or even
set result [: r=2+2]
which sets two variables at a time. I think I like that... - But stop,
what I really like here is not this new "syntax" extension. I will
stay with [set]. What I like is the flexibility of Tcl. This is, what
I really love.
+++
What Tcl makes really different for me compared to other languages is
the concept of having no keywords (yet...) and the very few syntax
rules which makes every statement as simple as possible. When I
learned programming, my first language was assembler (68k) and that
was very clear and obvious to me: You have one command with very few
arguments in one line. And a complete programm is simply (more or
less) a list of such statements. Remembering the old 68k days makes a
very warm and bright shimmering in my mind.
When I tried to learn C later, I simply did not get it. What do they
want from me? What kind of thinking is this? Struggling some years
with other languages and then being very pleased with the concepts of
Unix-Shells I found Tcl. That was a real enlightenment. This was the
way, programming should work: You have one command with some arguments
in one line (except for arguments which are lists) and a programm is
simply a list of such statements. Notice the similarity?
For me: Tcl is the assembler of scripting languages.
Nowadays I'm still programming in Tcl but most of the time in other
languages like C++ and Python and I like those languages, too. They
also have their beauty and I think, you should always choose a
language, that fits the problem. But looking at the beauty of the
languages itself, what is the philosophy of the concept behind it (if
any...) and the expressiveness of their statements, I often think:
This is really...kind of... weird cool...but why? I never think this
when looking at Tcl. Looking at Tcl, I'm often simply raptured about
it's beauty and how you can adapt Tcl to your structure of thinking
(or, for the serious programmer: to the structure of your problem).
+++
Well, never mind. Just some thoughts while waiting to get enough
motivation and wide awake to do something useful this early in the
morning...
Regards
Stephan
.
- Follow-Ups:
- Re: Syntax, expressiveness and the beauty of Tcl
- From: slebetman@xxxxxxxxx
- Re: Syntax, expressiveness and the beauty of Tcl
- From: Christian Gollwitzer
- Re: Syntax, expressiveness and the beauty of Tcl
- From: suchenwi
- Re: Syntax, expressiveness and the beauty of Tcl
- From: suchenwi
- Re: Syntax, expressiveness and the beauty of Tcl
- Prev by Date: Re: problem with tablelist
- Next by Date: Re: sqlite
- Previous by thread: unix review article on tcl
- Next by thread: Re: Syntax, expressiveness and the beauty of Tcl
- Index(es):
Relevant Pages
|
|