Error processing request
Parameters
CONTENT_LENGTH | 0 |
REQUEST_METHOD | GET |
REQUEST_URI | /revision/Namespace+variables?V=11 |
QUERY_STRING | V=11 |
CONTENT_TYPE | |
DOCUMENT_URI | /revision/Namespace+variables |
DOCUMENT_ROOT | /var/www/nikit/nikit/nginx/../docroot |
SCGI | 1 |
SERVER_PROTOCOL | HTTP/1.1 |
HTTPS | on |
REMOTE_ADDR | 172.70.127.33 |
REMOTE_PORT | 12264 |
SERVER_PORT | 4443 |
SERVER_NAME | wiki.tcl-lang.org |
HTTP_HOST | wiki.tcl-lang.org |
HTTP_CONNECTION | Keep-Alive |
HTTP_ACCEPT_ENCODING | gzip, br |
HTTP_X_FORWARDED_FOR | 18.226.150.175 |
HTTP_CF_RAY | 879b5ffd7ec3e0fc-ORD |
HTTP_X_FORWARDED_PROTO | https |
HTTP_CF_VISITOR | {"scheme":"https"} |
HTTP_ACCEPT | */* |
HTTP_USER_AGENT | Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; [email protected]) |
HTTP_CF_CONNECTING_IP | 18.226.150.175 |
HTTP_CDN_LOOP | cloudflare |
HTTP_CF_IPCOUNTRY | US |
Body
Error
Unknow state transition: LINE -> END
-code
1
-level
0
-errorstack
INNER {returnImm {Unknow state transition: LINE -> END} {}} CALL {my render_wikit {Namespace variables} {[Martin Lemburg]: here some procedures ...
* ... to get the full qualified name of ...
* ... to check the existence of ...
* ... to connect (with upvar) to ...
... a variable in the current or any parent namespace
======
proc getFullNspcVarName {args} {
switch -exact -- [llength $args] {
1 {
set nspc [uplevel namespace current];
set varname [lindex $args 0];
}
2 {
foreach {nspc varname} $args {break;}
if {[catch {namespace parent $nspc}]} {
error "no such namespace \"$nspc\"";
}
}
default {
error "wrong # args: should be \"getFullNspcVarName ?namespace? varname\"";
}
}
while {![info exists ${nspc}::$varname]} {
if {$nspc == "::"} {
return "";
}
set nspc [namespace parent $nspc];
}
return ${nspc}::$varname;
}
======
(See also [[[namespace] which]].)
[Martin Lemburg]:
no, "namespace which" is not comparable.
It doesn't do an recursive search over all parent namespace of the current or the given namespace.
There was a wikit-page [Dynamic variable scoping] with a procedure '''dynascope'''. This procedure provided access to variables in upper scope levels, with searching for the given variable in upper scope levels and [upvar]ing it, if found.
The '''getFullNspcVarName''' procedure provides a similar support, for searching the given variable, but not in upper scope, but namespace "levels".
======
proc varExistsInNspc {args} {
if {[catch {set result [uplevel getFullNspcVarName $args]} reason]} {
error $reason;
}
if {$result == ""} {
return 0;
}
return 1;
}
proc nspcVar2LocalVar {args} {
if {[catch {set result [uplevel getFullNspcVarName $args]} reason]} {
error $reason;
}
if {$result == ""} {
return 0;
}
set varname [namespace tail $result];
if {[uplevel info exists $varname]} {
error "namespace var \"$result\" already exists";
}
uplevel upvar $result $varname;
return 1;
}
# demo and test:
if {[file tail [info script]] == [file tail $argv0]} {
namespace eval a {
variable a1;
variable a2;
variable a3;
set a1 "a1 is a var of ::a";
set a2 "a2 is a var of ::a";
set a3 "a3 is a var of ::a";
namespace eval b {
variable b1;
variable a2;
set b1 "b1 is a var of ::a::b";
set a2 "a2 is a var of ::a::b";
puts "varExistsInNspc b1 = [varExistsInNspc b1]";
puts "getFullNspcVarName b1 = [getFullNspcVarName b1]";
puts "varExistsInNspc a1 = [varExistsInNspc a1]";
puts "getFullNspcVarName a1 = [set var [getFullNspcVarName a1]]";
if {[nspcVar2LocalVar a1]} {
puts "connected \"$var\" to \"a1\"";
puts "a1 = $a1";
} else {
puts stderr "couldn't connect to \"a1\"";
}
nspcVar2LocalVar a2;
}
}
}
<<categories>> Uncategorized} regexp2} CALL {my render {Namespace variables} {[Martin Lemburg]: here some procedures ...
* ... to get the full qualified name of ...
* ... to check the existence of ...
* ... to connect (with upvar) to ...
... a variable in the current or any parent namespace
======
proc getFullNspcVarName {args} {
switch -exact -- [llength $args] {
1 {
set nspc [uplevel namespace current];
set varname [lindex $args 0];
}
2 {
foreach {nspc varname} $args {break;}
if {[catch {namespace parent $nspc}]} {
error "no such namespace \"$nspc\"";
}
}
default {
error "wrong # args: should be \"getFullNspcVarName ?namespace? varname\"";
}
}
while {![info exists ${nspc}::$varname]} {
if {$nspc == "::"} {
return "";
}
set nspc [namespace parent $nspc];
}
return ${nspc}::$varname;
}
======
(See also [[[namespace] which]].)
[Martin Lemburg]:
no, "namespace which" is not comparable.
It doesn't do an recursive search over all parent namespace of the current or the given namespace.
There was a wikit-page [Dynamic variable scoping] with a procedure '''dynascope'''. This procedure provided access to variables in upper scope levels, with searching for the given variable in upper scope levels and [upvar]ing it, if found.
The '''getFullNspcVarName''' procedure provides a similar support, for searching the given variable, but not in upper scope, but namespace "levels".
======
proc varExistsInNspc {args} {
if {[catch {set result [uplevel getFullNspcVarName $args]} reason]} {
error $reason;
}
if {$result == ""} {
return 0;
}
return 1;
}
proc nspcVar2LocalVar {args} {
if {[catch {set result [uplevel getFullNspcVarName $args]} reason]} {
error $reason;
}
if {$result == ""} {
return 0;
}
set varname [namespace tail $result];
if {[uplevel info exists $varname]} {
error "namespace var \"$result\" already exists";
}
uplevel upvar $result $varname;
return 1;
}
# demo and test:
if {[file tail [info script]] == [file tail $argv0]} {
namespace eval a {
variable a1;
variable a2;
variable a3;
set a1 "a1 is a var of ::a";
set a2 "a2 is a var of ::a";
set a3 "a3 is a var of ::a";
namespace eval b {
variable b1;
variable a2;
set b1 "b1 is a var of ::a::b";
set a2 "a2 is a var of ::a::b";
puts "varExistsInNspc b1 = [varExistsInNspc b1]";
puts "getFullNspcVarName b1 = [getFullNspcVarName b1]";
puts "varExistsInNspc a1 = [varExistsInNspc a1]";
puts "getFullNspcVarName a1 = [set var [getFullNspcVarName a1]]";
if {[nspcVar2LocalVar a1]} {
puts "connected \"$var\" to \"a1\"";
puts "a1 = $a1";
} else {
puts stderr "couldn't connect to \"a1\"";
}
nspcVar2LocalVar a2;
}
}
}
<<categories>> Uncategorized}} CALL {my revision {Namespace variables}} CALL {::oo::Obj630721 process revision/Namespace+variables} CALL {::oo::Obj630719 process}
-errorcode
NONE
-errorinfo
Unknow state transition: LINE -> END
while executing
"error $msg"
(class "::Wiki" method "render_wikit" line 6)
invoked from within
"my render_$default_markup $N $C $mkup_rendering_engine"
(class "::Wiki" method "render" line 8)
invoked from within
"my render $name $C"
(class "::Wiki" method "revision" line 31)
invoked from within
"my revision $page"
(class "::Wiki" method "process" line 56)
invoked from within
"$server process [string trim $uri /]"
-errorline
4