Version 6 of The way tcl works

Updated 2005-01-09 04:34:49

The way tcl works

from "Bryan's Practical Guide to Tcl Programming", vol 0, page 0.

    The way tcl works: a line of code is parsed once. Only 
    once. Only ever once. Once, once, once. No exceptions at
    all. None. Zero. Zip. Nada. After substitutions are performed
    the first word becomes the command and all the other words 
    become the arguments. Always. Always, always. Always. 

    Always.

    To avoid substitutions, place a \ before special characters, 
    or place a whole string of special characters inside curly 
    braces. Things in curly braces will never, ever, ever, ever 
    be parsed before being passed to the command. Never, ever,
    ever. No exceptions. 

    The only tricky part (the _only_ tricky part) is knowing 
    that some commands will do their own parsing of arguments.
    But only *after* the line of code is parsed in the usual
    manner. Examples of these commands are "if", "expr", 
    "while" and a few others. 

    Unless you know for certain what you are doing, and know 
    for a fact that you want something to potentially be 
    evaluated twice, always, always, always provide such 
    arguments in curly braces. Always. Unless you know what 
    precisely what you are doing.

    When you truly understand the above, you are a tcl expert.

Reference: [L1 ]


LV While it may look like the paragraph 'the only tricky part' contradicts the first paragraph, it doesn't. The line of code is only parsed once. However, the resulting of that parse is a command name and zero or more arguments. IF there are arguments, when the command is invoked, it may be written to perform an eval on one or more of those arguments. Most commands don't. However, a few do.

[Replace this line with the name of a wiki page which discusses the commands which perform one or more additional evals]


FW: Hum. My understanding was that things in the global scope are re-parsed every time they're run (for instance, loop bodies, bindings etc.) on the theory that in the majority of cases things in the global scope are gonna be executed once anyway. I've heard you're supposed to keep loops in procs for that reason, for instance. Am I wrong?

WHD: I think you're confusing parsing with byte-compiling.


Category Tutorial