|
|
|
|
Tmac is a macro facility for Tcl. It lets developers customize their use of Tcl so that they can write more concise code depending on specific needs in the application. Since Tmac processing takes place before the Tcl code is parsed, there is generally no runtime penalty for macros. In fact, macros could easily speed up code by reducing the number of evals, by ensuring that all expr arguments are braced, and generally making it easier to streamline or follow best practices because they can be embedded in macros and reused.
A brief example illustrates some mechanics. # Making a customized string range - define macro "srange"
set s "abc_0555_YXZ" # Invoke the macro:
# The equivalent Tcl Code set fieldx [string range $s $fstart [expr {$fstart+$flength-1}]]
There are many more powerful ways to use macros which depend on the programmers needs and preferences. Like procedures, macros can embed as much or as little information as desired: # A more encompassing macro can be built using the previous macro MAC-BLOCK midfield s {<:sfield @s $fstart $flength:>} set field2 <:midfield $s:>
The example merely hints at the possibilities, macros can also "rewrite" Tcl code to implement new commands. For more example usage, benefits, and overview see the Introduction .
See the man page for usage details.
Download Tmac version 1.0 - 1 December 2003 - RT
|
|
Tmac - copyright Roy E. Terry, 2003 royterry@earthlink.net |
| TMac Home Introduction Usage Download Q&A + Examples |