Forum OpenACS Development: Re: General Comment editing issue Solved, and the true source is in core.

Heya Brian...

Thing is, it's inconsistant. If you don't supply a code block, it doesn't overwrite the vars. If you do supply the code block, the vars "should" (IMO) only be visible within it. I didn't know about the unclobber thing tho. Looking at db_foreach, there's no such issue, or at least no "-unclobber" option. For consistancy's sake, it should be the opposite: if, on the small chance, someone wants the vars visible beyond the block, there should be a -clobber option, and it should also be in loops like db_foreach.

If you like, you can apply the concept from "Apple User Interface Guidelines": don't make (the programmer) remember any more than he has to, certainly not: "so there's a foreach, a db_foreach, a db_multirow, and in only one of those, vars are clobbered outside a supplied block, and then only when it's supplied"... nightmarish... That's exactly the kind of thing that's going to chase devs away.

-Jim

Jim

This code block

foreach value [list a b c] {
#do something
}

the varaible "value" is still set after the foreach code block. db_foreach and db_multirow behave exactly the same way.

So for a Tcl programmer it is expected behavior. The only thing you need to remember is that the variables matching the columns in the query are created within the loop so they can overwrite variables in the caller since that is the level the code block runs at, and they exist in the caller's level after the code block completes.