Useful Basic TCL Formulas

Robert Abitbol There are a lot of basic TCL formulas which are needed and useful in a lot of programs. This is some of them. Since I am a beginner, please don't be shy and don't hesitate to contradict me if what I am saying is wrong! Thanks!

AM (16 february 2005) Just a matter of idiom: the common word for this seems to be idiom - formula makes me think of magic incantations or pseudo-scientific inventions in old movies :)

MG See also Bag of Algorithms, Example Scripts Everybody Should Have, and all the other pages mentioned on those two.

1) Calling a box with some text

- Calling a box with a text: easy! Ex:

 tk_messageBox -message "Sorry, this function isn't ready yet."

The full function would be:

 proc preferences {} {
    tk_messageBox -message "Sorry, this function isn't ready yet. Come back later :-)"

phk How about this:

 proc preferences {text} {
    tk_messageBox -message $text

then you can call it from different places, using appropriate texts.

The proc name could be possibly changed to messageBox (makes it more universal).

Have a look at the tutorials.

MAK Or, hey, to make it really universal, how about tk_messageBox and make it take optional switches and... oh wait. (I too am puzzled by the purpose of a proc called "preferences" that displays a dialog box saying the function isn't ready yet, as a "full" function.) Why not "notImplemented"? But, really, why would "messageBox $text" be better than "tk_messageBox -message $text"? A "proc puts_error { text } { puts stderr $text }" would be about as useful.

phk Sure, but I think Robert Abitbol just started to learn tcl. My part is supposed to help him to the next level.

RS As this is just a case of currying, one could also use

 interp alias {} messageBox {} tk_messageBox -message
 interp alias {} puts_error {} puts stderr

- More to come