POLL: Your favourite Tcl features

POLL: Your favourite Tcl features

Post by Neil Madde » Tue, 28 Mar 2006 22:15:26


A brief break from my unusually heavy Monday workload, I thought I'd
start a light-hearted thread to celebrate some of Tcl's more unique
features that make it such a useful language. So, what are your
favourite features of Tcl? What could you not live without? What feature
really makes Tcl stand out for you? As well as providing an amusing
diversion, hopefully the answers will be interesting for newcomers to
the language who are not yet aware of some of its more powerful facilities.

I'll set the ball rolling with my favourites:

[fileevent] (also available as the more accurate [chan event] in 8.5) is
a gem. Tcl's event loop was the first aspect of Tcl I ran across that
both confused and amazed me when I was learning. Seeing the ease with
which simple network servers could be knocked up in Tcl was a real
eye-opener. Learning that such simple code was automatically capable of
handling multiple simultaneous connections in an efficient way was
incredible. A real beauty.

From the C-API, I think my favourite function is
Tcl_GetIndexFromObjStruct, which has cleaned up a number of functions
I've had to write.

Cheers,

-- Neil
 
 
 

POLL: Your favourite Tcl features

Post by Volker Het » Tue, 28 Mar 2006 22:28:45

Neil Madden schrieb:
Traces. Lets me put some distance bnetween the user gui and the application code.
Otherwise, I'm in love with the syntax. I can use if as a variable or a command and
with $/[] stuff I can tell tcl which one I mean.

Lots of Greetings!
Volker

 
 
 

POLL: Your favourite Tcl features

Post by suchenw » Tue, 28 Mar 2006 22:34:34

[unknown] - very simple but very powerful mechanism to deeply extend
the syntax.
http://www.yqcomputer.com/ %20unknown%20know :

proc know what {
if ![info complete $what] {error "incomplete command(s) $what"}
proc unknown args $what\n[info body unknown]
} ;# RS
Usage example (let expr language be known):

% know {if {![catch {expr $args} res]} {return $res}}
% 3+4
7
 
 
 

POLL: Your favourite Tcl features

Post by Ralf Fasse » Tue, 28 Mar 2006 23:00:57

* Neil Madden < XXXX@XXXXX.COM >
| So, what are your favourite features of Tcl? What could you not live
| without? What feature really makes Tcl stand out for you?

- multi-platform, especially platform independent handling of serial
lines (RS232) and sockets
- clean syntax (not too verbose, not too obfuscated)
- extensibility (in TCL and C/C++)

R'
 
 
 

POLL: Your favourite Tcl features

Post by slebetma » Tue, 28 Mar 2006 23:01:23


Yeah [fileevent] is nice. I like the event loop in general which
fileevent is but one aspect of. The other aspect of the event loop
exposed to Tcl is of course [after] which is my favourite command in
Tcl. [after] makes Tcl one of the few programming languages out there
that is aware of the concept of time. Of course other languages have
their sleep and usleep functions but [after] is much more powerful.

My second favourite feature of Tcl is Everything Is A String. I was at
first amazed when I first realised this (previously I, like many
others, coded Tcl like C). Most other languages claiming to follow the
EIAS principle is only halfway there. In Tcl it's not just the values
that are strings. Variable names, proc names, proc bodies, channel/file
handles, everything in Tcl are nothing more than strings (the magic
object compilation is thankfully hidden from me).

My third favourite feature is my second favourite Tcl command, the
amazing foreach.
 
 
 

POLL: Your favourite Tcl features

Post by Michael Sc » Tue, 28 Mar 2006 23:05:50

The interp command with all its nice features.

- Command aliasing / simple currying... via interp alias
- (safe) slave interpreters to parse config files or handle security
boundaries

Followed by the "info" command for introspection.

Michael
 
 
 

POLL: Your favourite Tcl features

Post by Eckhard Le » Wed, 29 Mar 2006 00:22:42

I have some:

- the event loop as a whole ("after", "vwait", "tkwait"...)
- the "trace" and "info" commands (very helpful for debugging and
introspection)
- Tk, together with tile (nowhere it is sooo easy to write
sophisticated gui applications...)
- The "canvas" and "text" widgets in Tk
- the clean C interface
- the stubs mechanism for Tcl and extensions
- Starkits and starpacks.


Eckhard
 
 
 

POLL: Your favourite Tcl features

Post by clair » Wed, 29 Mar 2006 01:08:01

In article <OzRVf.10484$ XXXX@XXXXX.COM >,

.
.
.
Related reading: <URL: http://www.yqcomputer.com/ ;,
<URL: http://www.yqcomputer.com/ ;, <URL: http://www.yqcomputer.com/ ;,
<URL: http://www.yqcomputer.com/ ;, <URL: http://www.yqcomputer.com/ ;,
...

My personal answer: the people. And the Wiki.

I wouldn't want to develop without Tcl's introspection,
reliability, Unicode savvy, smart concurrency, Starkits,
stubs, Tk, ...
 
 
 

POLL: Your favourite Tcl features

Post by Andreas Le » Wed, 29 Mar 2006 01:16:42


One particular use I just came across recently was like this:

I had a program doing "heavy math" (actually bigint math in 8.5,
which is another one of my favourites), and worked in an
endless loop, usually only writing out sparse progress-type
information.

Now, if at some time I wanted the current status, I'd have to
"interrupt" it. Tcl, not being the best in interrupt-handling,
(at least unless using tclx,...) helped me with its fileevents:

###################################################################
proc show {{b 0}} {
# parameter b (with fall-through semantics :-)
# always: show some app-specific information.
# 2 ... consume&discard the line that triggered the fileevent, then
# 1 ... read more lines and handle them until empty, then
# 0 ... just continue

puts "app-specific status-display..."
# show a prompt, and read commands:
set line ""; for {set i 0} {$i<$b-1} {incr i} {gets stdin}
if {$b} { puts -nonewline "> "; flush stdout; gets stdin line}
while {$line ne ""} {
# "execute" line: parse app-specific commands, or just
# execute it as tcl-code through eval/uplevel/...
puts [catch {uplevel #0 $line} msg; set msg]
puts -nonewline "> "; flush stdout; gets stdin line
}
}
fileevent stdin readable [list show 2]

#... and then in the main body:
while {1} {
# do one step of the endless calculations ...
set interimsresult [do_one_iteration]

if {$interimsresult eq "very interesting"} {
show 1; # stop for prompt
} elseif {$interimsresult eq "interesting"} {
show 0; # output info, but continue
} else {
update; # this is where "show" gets called, once I press <Return>
}
}
#...
##################################################################

and if the script is then called with some readline-wrapper
tool, (e.g. rlwrap, by Hans Lub), you can even enjoy history
editing on those prompts :-)

PS: this example is for non-GUI scripts. with tkcon or a real
application-GUI it is usually even easier to achieve the effect.
 
 
 

POLL: Your favourite Tcl features

Post by me » Wed, 29 Mar 2006 02:01:48


^^^^^^^^^^^^^

My first, gut reaction is the event loop: it is very *** .

But, after spending several weeks beta testing software for
internationalization, and testing how encodings are handled
in a server written in perl.... I really, really, REALLY
like how simply tcl handles encodings.


--
WL
real mail: wliao at sdf loSnPesAtarM org
(remove the uppercase letters...)
 
 
 

POLL: Your favourite Tcl features

Post by David Grav » Wed, 29 Mar 2006 02:29:47


Ditto for me. Tcl's channel API is very nice and allows for custom
types to made quite easily.
 
 
 

POLL: Your favourite Tcl features

Post by Robert Hic » Wed, 29 Mar 2006 10:08:31

"My personal answer: the people. And the Wiki."

Ditto...that attracted me first to Tcl.

I also like:

- Starkits et al.
- Tclhttpd (very cool)

Robert
 
 
 

POLL: Your favourite Tcl features

Post by Matthias K » Wed, 29 Mar 2006 16:30:55

- The event stuff in general. When I came to Tcl it amazed me to be
able to have concurrency without the hassle of Thread coding.

- The second point I like is [interp create] together with
[toplevel -use] ... and run multiple applications in one window.

- A third point is just an example of various other cool features:
Came from Java and ever wanted to have try ... catch ... finally?
No problem with Tcl. Just write it yourself in about 30 lines of
code...

kind regards
(They that can give up essential liberty to obtain a little temporary)
(safety deserve neither liberty nor safety. -- Benjamin Franklin)
 
 
 

POLL: Your favourite Tcl features

Post by Donal K. F » Wed, 29 Mar 2006 23:05:10


The thing I like most about Tcl is one of the things that first
attracted me to it: there are *no* keywords in Tcl, and almost no
syntax. If I want to reimplement some core feature, or define my own
control structure, I can and easily. There's not many other languages
which let you do that; even in Lisp, reimplementing special forms
underneath a running program is tricky.

Aside from that, I really like Tk (especially [bind], [canvas] and
[text]) the event loop and interpreters.

Donal.
 
 
 

POLL: Your favourite Tcl features

Post by clair » Thu, 30 Mar 2006 00:08:02

In article <e0bft8$279n$ XXXX@XXXXX.COM >,

.
.
.

Tags and traces. I'm not sure what I'm saying, but canvas and
text are amazing (inside non-joke: someone ought to write book
chapters on them), and tags are a big nexus of underappreciated
capabality.