{"id":6240,"date":"2022-12-20T18:58:03","date_gmt":"2022-12-20T21:58:03","guid":{"rendered":"http:\/\/lode.uno\/linux-man\/index.php\/2022\/12\/20\/uplevel-mann\/"},"modified":"2022-12-20T18:58:03","modified_gmt":"2022-12-20T21:58:03","slug":"uplevel-mann","status":"publish","type":"post","link":"https:\/\/lode.uno\/linux-man\/2022\/12\/20\/uplevel-mann\/","title":{"rendered":"uplevel (mann)"},"content":{"rendered":"<h1 align=\"center\">uplevel<\/h1>\n<p> <a href=\"#NAME\">NAME<\/a><br \/> <a href=\"#SYNOPSIS\">SYNOPSIS<\/a><br \/> <a href=\"#DESCRIPTION\">DESCRIPTION<\/a><br \/> <a href=\"#EXAMPLE\">EXAMPLE<\/a><br \/> <a href=\"#SEE ALSO\">SEE ALSO<\/a><br \/> <a href=\"#KEYWORDS\">KEYWORDS<\/a> <\/p>\n<hr>\n<p>______________________________________________________________________________<\/p>\n<h2>NAME <a name=\"NAME\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">uplevel \u2212 Execute a script in a different stack frame<\/p>\n<h2>SYNOPSIS <a name=\"SYNOPSIS\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\"><b>uplevel<\/b> ?<i>level<\/i>? <i>arg<\/i> ?<i>arg &#8230;<\/i>? ______________________________________________________________________________<\/p>\n<h2>DESCRIPTION <a name=\"DESCRIPTION\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">All of the <i>arg<\/i> arguments are concatenated as if they had been passed to <b>concat<\/b>; the result is then evaluated in the variable context indicated by <i>level<\/i>. <b>Uplevel<\/b> returns the result of that evaluation.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">If <i>level<\/i> is an integer then it gives a distance (up the procedure calling stack) to move before executing the command. If <i>level<\/i> consists of <b>#<\/b> followed by a number then the number gives an absolute level number. If <i>level<\/i> is omitted then it defaults to <b>1<\/b>. <i>Level<\/i> cannot be defaulted if the first <i>command<\/i> argument starts with a digit or <b>#<\/b>.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">For example, suppose that procedure <b>a<\/b> was invoked from top-level, and that it called <b>b<\/b>, and that <b>b<\/b> called <b>c<\/b>. Suppose that <b>c<\/b> invokes the <b>uplevel<\/b> command. If <i>level<\/i> is <b>1<\/b> or <b>#2<\/b> or omitted, then the command will be executed in the variable context of <b>b<\/b>. If <i>level<\/i> is <b>2<\/b> or <b>#1<\/b> then the command will be executed in the variable context of <b>a<\/b>. If <i>level<\/i> is <b>3<\/b> or <b>#0<\/b> then the command will be executed at top-level (only global variables will be visible).<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">The <b>uplevel<\/b> command causes the invoking procedure to disappear from the procedure calling stack while the command is being executed. In the above example, suppose <b>c<\/b> invokes the command<\/p>\n<p style=\"margin-left:22%; margin-top: 1em\"><b>uplevel<\/b> 1 {set x 43; d}<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">where <b>d<\/b> is another Tcl procedure. The <b>set<\/b> command will modify the variable <b>x<\/b> in <b>b<\/b>\u2019s context, and <b>d<\/b> will execute at level 3, as if called from <b>b<\/b>. If it in turn executes the command<\/p>\n<p style=\"margin-left:22%; margin-top: 1em\"><b>uplevel<\/b> {set x 42}<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">then the <b>set<\/b> command will modify the same variable <b>x<\/b> in <b>b<\/b>\u2019s context: the procedure <b>c<\/b> does not appear to be on the call stack when <b>d<\/b> is executing. The <b>info level<\/b> command may be used to obtain the level of the current procedure.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><b>Uplevel<\/b> makes it possible to implement new control constructs as Tcl procedures (for example, <b>uplevel<\/b> could be used to implement the <b>while<\/b> construct as a Tcl procedure).<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">The <b>namespace eval<\/b> and <b>apply<\/b> commands offer other ways (besides procedure calls) that the Tcl naming context can change. They add a call frame to the stack to represent the namespace context. This means each <b>namespace eval<\/b> command counts as another call level for <b>uplevel<\/b> and <b>upvar<\/b> commands. For example, <b>info level 1<\/b> will return a list describing a command that is either the outermost procedure call or the outermost <b>namespace eval<\/b> command. Also, <b>uplevel #0<\/b> evaluates a script at top-level in the outermost namespace (the global namespace).<\/p>\n<h2>EXAMPLE <a name=\"EXAMPLE\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">As stated above, the <b>uplevel<\/b> command is useful for creating new control constructs. This example shows how (without error handling) it can be used to create a <b>do<\/b> command that is the counterpart of <b>while<\/b> except for always performing the test after running the loop body:<\/p>\n<p style=\"margin-left:22%; margin-top: 1em\">proc do {body while condition} { <br \/> if {$while ne &#8220;while&#8221;} { <br \/> error &#8220;required word missing&#8221; <br \/> } <br \/> set conditionCmd [list expr $condition] <br \/> while {1} { <b><br \/> uplevel<\/b> 1 $body <br \/> if {![<b>uplevel<\/b> 1 $conditionCmd]} { <br \/> break <br \/> } <br \/> } <br \/> }<\/p>\n<h2>SEE ALSO <a name=\"SEE ALSO\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">apply(n), namespace(n), upvar(n)<\/p>\n<h2>KEYWORDS <a name=\"KEYWORDS\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">context, level, namespace, stack frame, variable<\/p>\n<hr>\n","protected":false},"excerpt":{"rendered":"<p>  uplevel \u2212 Execute a script in a different stack frame <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3783,1],"tags":[2635,2860],"class_list":["post-6240","post","type-post","status-publish","format-standard","hentry","category-n-comandos-tcl-tk","category-sin-categoria","tag-mann","tag-uplevel"],"gutentor_comment":0,"_links":{"self":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/posts\/6240","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/comments?post=6240"}],"version-history":[{"count":0,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/posts\/6240\/revisions"}],"wp:attachment":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/media?parent=6240"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/categories?post=6240"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/tags?post=6240"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}