Assign using equals

What: Assign using equals
Where: From the contact
Description: Tcl code to define new unknown command which allows one
        to use = as a simple assignment command.
Contact: mailto:[email protected]  (Mike Taylor)

RS: This is one of the most frequent wishes for Tcl: to be able to write, in the Fortran/Algol/Pascal/C infix tradition,

 i = $j + 1

as opposed to Tcl's Polish notation (command name always comes first):

set i [expr {$j + 1}]

A compromise would be to have a let command whose arguments have the required structure (e.g. Let's assign with let) - a most simple implementation could be this:

proc let {varName "=" args} {
   upvar 1 $varName v
   set v [uplevel 1 [list expr] $args]
} 

But of course directly using expr is still a tad more efficient...


See also