Version 0 of Noise word

Updated 2010-06-04 18:20:18 by AMG

AMG: Noise words are a kind of syntax sugar.

Noise words don't affect the behavior of a program: Like comments, they're there to enhance readability. Unlike comments, noise words are not entirely ignored: Usually, when a command takes a noise word, it checks the spelling and throws an error if it's not the word it was expecting. Noise words are typically optional, depending on the command.

To test if something's a noise word or not, delete it from the definition of the command and see if any ambiguity is created. If not, it was a noise word.

I don't think it's useful to have a hard-and-fast definition for noise words, since every command is free to be different. So the above definition is more of a guideline.

In the following examples, noise words are highlighted in bold.


[if] has two optional noise words: "then" and "else" [L1 ]. They can be omitted but they cannot be misspelled. However, "elseif" is required, and I question its status as a noise word. Popular usage of [if] uses "else" but not "then", to match the C programming language and its descendants. (I frequently misspell "elseif" as "else if", which is an error.)

if test1 then code1 elseif test2 then code2 else code3

I'm not aware of any other examples of noise words in the Tcl core. But there are other commands implemented on this Wiki which use noise words.


My [lcomp] command (presently on the hat0 page, but I will move it) has one required noise word ("and"), and I am debating adding another ("in").

lcomp {"$w $x $y $z"} for w {A B} and {x y} {C D E F} for z {G H I J} if {$z in "G I J"}
lcomp {"$w $x $y $z"} for w in {A B} and {x y} in {C D E F} for z in {G H I J} if {$z in "G I J"}

Let's delete the noise words and see if this creates ambiguity:

lcomp {"$w $x $y $z"} for w {A B} {x y} {C D E F} for z {G H I J} if {$z in "G I J"}

Looks good to me, except for one very special case. Maybe for is iterating over two lists in parallel and the variable name for the second list is "for" or "if". This does create an ambiguity, but in an admittedly pathological case, so "and" is almost a noise word.

lcomp {$x ** $if} for x {2} and if {2} ;# returns 4
lcomp {$x ** $if} for x {2} if {2}     ;# can't read "if": no such variable???

The first line clearly has two variables, x and if, but the second line appears to have one variable and one conditional. The problem goes away when the second variable is renamed, and now [lcomp] for works just like the [foreach] core command.

lcomp {$x ** $y} for x {2} and y {2}   ;# returns 4
lcomp {$x ** $y} for x {2} y {2}       ;# returns 4

Noise words are different than dummy words. Noise words can be only specific values, whereas dummy words can be anything. Also, dummy words affect the program by their presence or absence, whereas noise words do not. Optional noise words are truly optional. For a mandatory noise word to be a noise word, there can only be one possible value, dictated by context. If there's a choice, it's a keyword (correct term?) if the choice makes a difference, or it's a dummy word if the choice doesn't matter.