Forum OpenACS Q&A: Tcl "gotcha" reminder ...

Collapse
Posted by Don Baccus on
When you put code in comments like this:

# set foo [dom:: ...]

The code inside the brackets is executed.

Way back in the dim dark past, when someone converted apm-xml-procs to use ns_xml rather than the Tcl XML library, they commented out the old code as in my example above.

This means that the APM was parsing every .info file twice!  Once in Tcl, once again in ns_xml!

So much for switching to ns_xml to speed things up ...

(I found out about this in a bizarre way I won't bother relating other than I was surprised to see my install dying inside dom::!)

Also ... don't call that code anymore, it's no longer loaded.  I noticed that Peter cut-'n-pasted some error code from apm-xml-procs that hadn't been converted to ns_xml, I've fixed it.

Also postcard still uses dom:: ... if someone wants to convert it to ns_xml it will probably start working again.

Of course ... we'll soon be switching to tDOM but there's very little ns_xml stuff in the toolkit and the conversion's easy so don't let that stand in your way!

Collapse
Posted by David Walker on
For convenience in my personal code I has switched to using a comment proc.  I can't tell you if it has a performance cost but it is very convenient for commenting out long blocks, providing all your "{" have matching "}" within the commented block.

proc comment {args} {}

comment {
lots of commented out stuff
in here {[someproc]}

}

It doesn't look to me like the code in brackets in comments is executed in tclsh.  Is there something different going on here?

Collapse
Posted by Alex Sokoloff on
I remember being appalled when unbalanced brackets in comments would blow up in tcl. I can't believe they made it work that way by accident. What was the rationale for evaluating quoted code, anyway?
Collapse
Posted by Jeff Davis on
I think it was done that way to horrify CS people :)
see http://mini.net/tcl/462 for more about it than anyone should
know.
Collapse
Posted by Jonathan Ellis on
I don't think the code in a comment gets executed:

# puts foo
# set a [puts foo]

Collapse
Posted by Jeff Davis on
Yeah, it's probably a case like this where the comment is such that what looks like a comment is actually just broken bracing. An example being:
foreach x { 
   set y 1
# } [puts foo] 
which will in fact evaluate the puts for obvious reasons. of course seperate the open brace from the close by a hundred lines and it is less obvious why code in a "comment" is being evaluated :)
Collapse
Posted by Don Baccus on
Only the code within the square brackets get executed.

In this case the call to dom:: was causing an error, which is how I caught it.

And, no, there was no bracketing error.  The latest version of nsxml wasn't working with our ns_xml calls which caused an invalid node to be returned and then passed to the dom:: proc INSIDE THE COMMENT triggering an error!

Collapse
Posted by Jonathan Ellis on
well, as I posted,

# set a [puts foo]

does not execute the bracketted puts.  So I'd be interested what your code boils down to when you strip out everything nonessential to reproducing this behavior.