Forum OpenACS Q&A: return and uplevel

Collapse
Posted by Jonathan Ellis on
probably old news to many of you but I just noticed this today: "return" in uplevel returns out of the context uplevel was called from, not the context uplevel is "reparented" into. example:
tcl>proc foo {} { uplevel { puts 1;  return;  puts 2 } }
tcl>proc bar {} { foo;  puts 3 }
tcl>bar
1
3
note bar calls foo, which contains a return statement in uplevel, but that return does not make bar terminate.
Collapse
Posted by Titi Ala'ilima on
This is important to remember when you're using db_foreach, because it looks as if you're code is executing in the calling context, but it is using the "re-parenting" trick, so any return in your loop will only terminate the loop.  If you want to terminate the calling context, you need to use "return -code return", and I think there are some places where even that won't work (inside the -if_no_rows clause, IIRC).