Error processing request
Parameters
CONTENT_LENGTH | 0 |
REQUEST_METHOD | GET |
REQUEST_URI | /revision/Let%27s+assign+with+let?V=18 |
QUERY_STRING | V=18 |
CONTENT_TYPE | |
DOCUMENT_URI | /revision/Let's+assign+with+let |
DOCUMENT_ROOT | /var/www/nikit/nikit/nginx/../docroot |
SCGI | 1 |
SERVER_PROTOCOL | HTTP/1.1 |
HTTPS | on |
REMOTE_ADDR | 172.71.255.7 |
REMOTE_PORT | 34878 |
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.219.95.244 |
HTTP_CF_RAY | 8828ca9c5f712316-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_REFERER | http://wiki.tcl.tk/revision/Let%27s+assign+with+let?V=18 |
HTTP_CF_CONNECTING_IP | 18.219.95.244 |
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 {Let's assign with let} {''Is it possible to assign to a $b ´s value and to b $a ´s value without using a third variable? Is there a function to do so?''
Why not just:
======
let a b @= $b $a
======
Which, by the way, also allows:
======
let a b c = 1 ;#this sets a b and c to 1
let a b c = 1 + 4 ;#"=" uses expr to process the value to assign
let a b c += 1 ;#computed assignments are allowed, +-*/&| supported
let a b c := info commands ;#uses eval to process right side
let a b c @= 1 2 3 ;#instead of assigning the list {1 2 3} to a b and c,
;#it instead assigns the elements in order, resulting
;#in a getting the value 1, b getting 2 and so on.
let a b c @:= info commands ;#uses eval to get result and uses @= for assignment
let a ++ ;#incr and
let a -- ;#decr are supported.
======
----
My suggestion will swap a-b and vice versa:
======
foreach {a b} [list $b $a] {}
======
Although proc let has many other features of course.
----
======
proc let { args } {
if { [llength $args ] == 2 } {
if [string equal [ lindex $args 1 ] "++" ] {
set result [ uplevel incr [ lindex $args 0 ] ]
} elseif [string equal [ lindex $args 1 ] "--" ] {
set result [ uplevel incr [ lindex $args 0 ] -1 ]
} else {
set result [ uplevel set "$args" ]
}
} else {
regexp {([^=:+\-*/&|@]*)([:+\-*/&|@]?)([@]*)=(.*)} $args -> vars op optional rest
if ![ info exists op ] {
return -code error -errorcode 1 "no valid assignment operator in $args"
}
switch -- $op {
: {
if [llength [info commands [lindex $rest 0]]] {
set result [uplevel $rest]
} else {
set result $rest ;# this should always work...
}
if { "$optional" == "@" } {
set max [ llength $result ]
foreach var $vars res $result {
uplevel 1 [ list set $var $res ]
}
} else {
foreach var $vars {
set result [ uplevel [list set $var $result] ]
}
}
}
@ {
if { "$optional" == ":" } {
set rest [uplevel $rest]
}
set max [ llength $rest ]
if { $max == 1 } {
eval set rest $rest
set max [ llength $rest ]
}
foreach var $vars res $rest {
set result [ uplevel 1 [ list set $var $res ]]
}
}
+ - - - * - / - & - | {
foreach var $vars {
set result [ uplevel set $var \[ expr \$$var $op ( $rest ) \] ]
}
}
= -
default {
if { [ catch { set result [ uplevel expr $rest ] } ] } {
set result $rest ;# this should always work...
}
foreach var $vars {
set result [ uplevel [list set $var $result] ]
}
}
}
}
return $result
}
======
----
[RS] The code fragment (appears twice above)
======
set i 0
foreach var $vars {
uplevel set $var [ lindex $result $i ]
incr i
}
======
seems like it can be replaced by
======
foreach var $vars res $result {
uplevel 1 [list set $var $res]
}
======
- if [foreach] can do a job once, it might as well do it twice ;-) A variable saved, and possibly safer with the [list] wrapper...
[Larry Smith] I'd clean forgotten that feature. Yes, it's
much more elegant that way. The above code has been
corrected.
======
[RFox] See Larry McVoy's L language? extension? to Tcl from Tcl 2006:
http://www.tcl.tk/community/tcl2006/papers/Larry_McVoy/l.pdf
<<categories>> Uncategorized} regexp2} CALL {my render {Let's assign with let} {''Is it possible to assign to a $b ´s value and to b $a ´s value without using a third variable? Is there a function to do so?''
Why not just:
======
let a b @= $b $a
======
Which, by the way, also allows:
======
let a b c = 1 ;#this sets a b and c to 1
let a b c = 1 + 4 ;#"=" uses expr to process the value to assign
let a b c += 1 ;#computed assignments are allowed, +-*/&| supported
let a b c := info commands ;#uses eval to process right side
let a b c @= 1 2 3 ;#instead of assigning the list {1 2 3} to a b and c,
;#it instead assigns the elements in order, resulting
;#in a getting the value 1, b getting 2 and so on.
let a b c @:= info commands ;#uses eval to get result and uses @= for assignment
let a ++ ;#incr and
let a -- ;#decr are supported.
======
----
My suggestion will swap a-b and vice versa:
======
foreach {a b} [list $b $a] {}
======
Although proc let has many other features of course.
----
======
proc let { args } {
if { [llength $args ] == 2 } {
if [string equal [ lindex $args 1 ] "++" ] {
set result [ uplevel incr [ lindex $args 0 ] ]
} elseif [string equal [ lindex $args 1 ] "--" ] {
set result [ uplevel incr [ lindex $args 0 ] -1 ]
} else {
set result [ uplevel set "$args" ]
}
} else {
regexp {([^=:+\-*/&|@]*)([:+\-*/&|@]?)([@]*)=(.*)} $args -> vars op optional rest
if ![ info exists op ] {
return -code error -errorcode 1 "no valid assignment operator in $args"
}
switch -- $op {
: {
if [llength [info commands [lindex $rest 0]]] {
set result [uplevel $rest]
} else {
set result $rest ;# this should always work...
}
if { "$optional" == "@" } {
set max [ llength $result ]
foreach var $vars res $result {
uplevel 1 [ list set $var $res ]
}
} else {
foreach var $vars {
set result [ uplevel [list set $var $result] ]
}
}
}
@ {
if { "$optional" == ":" } {
set rest [uplevel $rest]
}
set max [ llength $rest ]
if { $max == 1 } {
eval set rest $rest
set max [ llength $rest ]
}
foreach var $vars res $rest {
set result [ uplevel 1 [ list set $var $res ]]
}
}
+ - - - * - / - & - | {
foreach var $vars {
set result [ uplevel set $var \[ expr \$$var $op ( $rest ) \] ]
}
}
= -
default {
if { [ catch { set result [ uplevel expr $rest ] } ] } {
set result $rest ;# this should always work...
}
foreach var $vars {
set result [ uplevel [list set $var $result] ]
}
}
}
}
return $result
}
======
----
[RS] The code fragment (appears twice above)
======
set i 0
foreach var $vars {
uplevel set $var [ lindex $result $i ]
incr i
}
======
seems like it can be replaced by
======
foreach var $vars res $result {
uplevel 1 [list set $var $res]
}
======
- if [foreach] can do a job once, it might as well do it twice ;-) A variable saved, and possibly safer with the [list] wrapper...
[Larry Smith] I'd clean forgotten that feature. Yes, it's
much more elegant that way. The above code has been
corrected.
======
[RFox] See Larry McVoy's L language? extension? to Tcl from Tcl 2006:
http://www.tcl.tk/community/tcl2006/papers/Larry_McVoy/l.pdf
<<categories>> Uncategorized}} CALL {my revision {Let's assign with let}} CALL {::oo::Obj1452888 process revision/Let%27s+assign+with+let} CALL {::oo::Obj1452886 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