TCL: Return to a higher level?

How can I return from proc to a higher context?
For example: if proc X is called another proc Y, which calls the third proc Z - is there a way to get back from Z right back to X?

+3
source share
2 answers

From 8.5 years or more, yes. The command returnhas a parameter -levelthat is used only for this:

return -level 2 $someValue

Thus, for example:

proc X {} {
    puts "X - in"
    Y
    puts "X - out"
}
proc Y {} {
    puts "Y - in"
    Z
    puts "Y - out"
}
proc Z {} {
    puts "Z - in"
    return -level 2 "some value"
    puts "Z - out"
}
X

produces this conclusion:

X - in
Y - in
Z - in
X - out

Please note that this reduces the possibility of reuse Z, but this is your business.

+9
source

If you call "x process" from "z proc", then the loop will create a process in your thread.

0
source

Source: https://habr.com/ru/post/1759847/


All Articles