Greytree

TamWiki

For a mouse who is a packrat

Technology » Always Leave The Body Brace On The Same Line As The Proc
This was quite a problem for me until I figured out what was wrong

Summary:this is what goes at the top of the site

(redirected from Main.AlwaysLeaveTheBodyBraceOnTheSameLineAsTheProc)

Up: ^TckTk?^

Tcl is very finicky about where things are placed. Unlike other programming languages, location and white space seem to make a big difference to Tcl.

For example, compare the brace placement on this snippet:

  1. proc ::testegg::msg_test {nick userhost hand text}
  2. {
  3. set msg "nick=$nick. userhost=$userhost. hand=$hand. text=$text"
  4. putcmdlog [concat "testegg: " $msg]
  5. putserv [concat "PRIVMSG " $nick " :" $msg]
  6. return 1
  7. }

to the brace placement on this one:

  1. proc ::testegg::msg_test {nick userhost hand text} {
  2. set msg "nick=$nick. userhost=$userhost. hand=$hand. text=$text"
  3. putcmdlog [concat "testegg: " $msg]
  4. putserv [concat "PRIVMSG " $nick " :" $msg]
  5. return 1
  6. }

The first example will fail, because Tcl wants the body opening brace to be on the same line as the proc command.

I think it took me about 3 hours to figure that out...


Tags: Categories: Articles

Recent Changes | Printable View | Page History | Edit Page
Page last modified on April 09, 2012, at 09:03 AM by tamara