Lars Hellström | 29 Sep 15:58
Favicon

TIP#327 (tailcall) and custom control structures

I'm worried about the interaction between TIP#327's [tailcall] and 
custom control structures, e.g. the likes of TIP#329's [try]. It seems 
to me that there is a big bunch of unspecified behaviour in this area, 
which could shroud breaking some fundamental principles for Tcl, even 
if it can be argued that it doesn't break compatibility since the new 
behaviour is only triggered by a new command.

First, what works: If one defines

proc test-foreach {prefix list} {
    foreach x $list {
       tcl::unsupported::tailcall {*}$prefix $x
    }
}

then [test-foreach {format -%s-} {foo bar baz}] returns -foo-, as one 
should expect from the [return [uplevel ...]] analogy in the TIP.

Second, what's unclear: Suppose I want a try-finally style command with 
a body to be evaluated and which does some cleanup afterwards. 
Classically (well, post-TIP#90) that should be something like

proc once {body} {
    # Before-code
    catch {uplevel 1 $body} res opt
    # After-code
    return -options $opt $res
}

so for test purposes one might consider
(Continue reading)


Gmane