Subject: Re: commenting in switch statements From: Bryan Oakley Date: 1997/04/06 Message-ID: <3348295D.41C67EA6@healthcare.com> Newsgroups: comp.lang.tcl lvirden@cas.org wrote: > > According to Bryan Oakley : > :lvirden@cas.org wrote: > :> > :> Okay, I am sorry for being dense here. But if someone would have > :> the patience to explain (feel free to use email if necessary) the > > And many of you have - some politely, and some quite rudely. Sorry > that you felt so incensed that instead of ignoring my posting and moving > on with your life some folk felt it necessary to flame me. > > :Short answer: because the # pattern has one argument; after that are > > And here was the catch that I was missing. That in some cases, the > tcl interpreter treats everything after a # as 'a part of the # command' > and in at least one case - switch - the interpreter associates only > the first word (sometimes!) with the # and treats the remainder of > the line as being another command. Not exactly. You are still missing something. In the case of the switch statement the interpreter isn't associating anything with the # character. It's just an element in a list that is an argument to the switch command. Based on where that character sits in the list it's either treated as a pattern or body. No magic associations going on here. The same is true whether we're talking about '#' or expr or if or while or ..... Nowhere in the tcl language does the interpreter associate one word with the # and the remainder of the line as being another comand (well, unless you count "# comment! ; set foo bar". The only time # is treated as the comment character is if it appears where a command could appear (from the man page: "at a point where tcl is expecting the first character of the first word of a command"). The same can be said of 'expr' or 'if' or ... these are only treated as commands if they appear where a command is expected. Otherwise they are just another word in a list (or string, or whatever). > :Perhaps we should treat all this as a bug in the man page. If the man > :page was more explicit about how the list of elements is processed, > :would that help? > > I don't know whether it would help in general or not. The behavior of > tcl to treat plain text as data or commands , depending on the vagarity > of the command in process, is pretty tough to explain in a mere > man page. But it *is* explained in a mere man page, and fairly suscinctly. Half a man page, really. The main tcl man page spells out a mere eleven rules which covers this quite nicely. Really only the first three rules and rule 9 (the comment rule...) are all that's required to explain how tcl distinguishes between commands and data. The rest is quoting. My remark about the man page was specifically in reference to the switch statement. Perhaps that man page needs to spell out that the list of patterns and actions *must* have an even number of elements. -- Bryan Oakley mailto:oakley@healthcare.com Software Engineer http://www1.clearlight.com/~oakley/ Healthcare Communications, Inc. http://www.healthcare.com/