Re: Is this a legitimate use of "reutrn -level"?



Adrian Davis wrote:
Consider the following:-

# Example
proc proc0 {} {
puts "This is proc0"
proc1
puts "Back in proc0"
}

proc proc1 {} {
puts "This is proc1"
proc2
puts "Back in proc1"
}

proc proc2 {} {
puts "This is proc2"
return -level 2
}
# End of example

...which displays the following when run...

This is proc0
This is proc1
This is proc2
Back in proc0

...Which is exactly what I want. Under certain conditions in "proc2" I
want to continue processing from the point after the call to "proc1"
in "proc0". The above use of "return -level 2" seems to work Ok, but
I'm not sure if this a legitimate/supported use of this option. The
man page doesn't seem to be clear on this point. Is this usage
correct?

This is valid, but fragile. These routines are using the commands
in an acceptable way, but the danger is in whether other callers of
the [proc2] command will get surprised in bad ways. You'll want the
docs for [proc2] to be very very clear that it returns the TCL_RETURN
return code, and callers need to use it in situations where that makes
sense, or be prepared to [catch] it.

--
| Don Porter Mathematical and Computational Sciences Division |
| donald.porter@xxxxxxxx Information Technology Laboratory |
| http://math.nist.gov/~DPorter/ NIST |
|______________________________________________________________________|
.



Relevant Pages

  • lambda block doesnt work with upto iterator
    ... work with the .upto iterator. ... puts "#" ... puts "Call proc2!" ...
    (comp.lang.ruby)
  • Is this a legitimate use of "reutrn -level"?
    ... puts "This is proc0" ... proc proc1 { ... proc proc2 { ...
    (comp.lang.tcl)
  • finding process and waiting for it to end
    ... I am working on a jscript that launches a process (proc1). ... Proc1 launches a secondary process (proc2) and then exits. ... I want my script to launch proc1 and then find the process associated ...
    (microsoft.public.scripting.jscript)
  • waiting for input of widget and return input value
    ... run proc1, then proc1 will invoke proc2 and popup some checkbutton for ... to invoke proc3, proc3 will check which button was checked and return a ... checked variable list, then proc2 return the list to proc1, and proc1 ... proc proc1 { ...
    (comp.lang.tcl)
  • Re: About Lists of Pointers
    ... > In Proc1, the address of a local variable is pushed. ... is NOT the same as Addr, although both return pointers. ... When Proc2 gets called ...
    (borland.public.delphi.language.objectpascal)