How do I end a proc? I'm calling proc 'do:pwd:check' and if something goes wrong in that proc I'd like to end the script. But as it is now it goes back to the proc 'msg:get:memos' and goes on.
Sure, I can solve it in msg:get:memos-proc, but I'm gonna call do:pwd:check from 10 different procs with msgdel and ****.
So, how do I end do:pwd:check? I did try 'exit', and sure, it ends, but a little bit too much. =)
yes, thats exactly how its done. that is the fundamental logic behind conditional function programming languages. your syntax could be inproved slightly though, ie
if {![do:pwd:check $lowercasenick $text]} {
return 0
}
(this works because if is really tests against integers, evaluating false for 0 and true for everything else, so if do:pwd:check returns 0, the above if evaluates to if {!0} which is if {1} ).
returning 0 on faliure is often seen as bad form, as tradionally a return code of 0 is for ok, but this has no real operational implications.
there are other ways of breaking out of the controlling function that calls a proc without conditional calls, but its bad programming form to do so (look up the syntax on the return command in the tcl docs if you wanna find out how). The only time I can think of that it would ever be needed to throw an exception break would be in highly optimized code, where you cant afford the cpu time an if{} would take (and such code is notoriously difficult for maintanance work).