Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: 7c299afdb1799b3ef057aebe7e87c852d328dfa4
Ticket: 550789ffffffffffffffffffffffffffffffffff
[break] should take an 'after'-script
User & Date: nobody on 2002-05-26 01:28:12
Changes

  1. icomment:
    Logged In: NO 
    
    At 2002-05-10 14:56,  dgp wrote:
    > The particular applications outlined in the proposal are
    > worthwhile and interesting, but Tcl already provides the
    > ability to define new looping commands and new completion
    > codes that can implement those ideas.
    
    Whereas this is quite true, it is also the case that the
    elegant way of defining these commands is far from obvious,
    and the reply would have been much more enlightning if it
    had contained an example. As it were, I stumbled upon *the*
    (? -- there could be others ...) elegant solution and could
    share it with the world on the Wiki (see
    http://mini.net/tcl/return), but there was a fair amount of
    luck in that.
    
    > Such commands could
    > be added to the control package of tcllib, if it is 
    > believed necessary to provide such commands broadly.  I
    > don't think there's any need to change the core to give
    > the proposer the power he seeks.
    
    I hope you will, and I agree the programming convenience I
    requested can be found without changing the core. The only
    reason I now see for incorporating this into the core is
    that there are much more efficient ways of bytecoding
    break-with-eval than that which the byte-compiler produces
    from the script-level solutions. I suspect incorporation in
    the core is the only way to make the compiler produce these
    optimal codings (but maybe Tcl9 will have interfaces that
    allow extensions to specify optimal bytecode even for
    control structures such as break-with-eval?). 
    
    > I do not think this request is a good idea.  It proposes a
    > change to [break], but really this is a proposed change to a
    > number of commands that respond to the TCL_BREAK 
    > completion code.
    
    I hope you are aware that a similar critique could be
    directed against TIP#90. There "a number of commands" (more
    precisely every command defined by [proc]) are already
    exhibiting a special behaviour, but that is not completely
    satisfactory and so it needs to be changed. *Note* that I'm
    not saying that I want to direct such critique against
    TIP#90, I'm merely pointing out that what difference there
    is between the proposals is a difference in degree rather
    than something specifically distinict.
    
    Indeed, there is a script level workaround to the return
    -code versus control::do problem that is quite similar to
    the script level implementation of break-with-eval. Consider
    
    proc eproc {name arglist body} {
        interp alias {} $name {} eproc_call "$name "
        proc "$name " $arglist $body
    }
    proc returneval {script} {return -code -1 $script}
    proc eproc_call {args} {
        set code [catch [list uplevel 1 $args] res]
        if {$code == -1} then {
            set code [catch [list uplevel 1 $res] res]
            return -code $code $res
        } elseif {$code == 1} then {
            global errorInfo errorCode
            return -code error -errorinfo $errorInfo -errorcode
    $errorCode $res
        } else {
            return -code $code $res
        }
    }
    
    With these commands, one can instead of the definition
    
    proc b {} {control::do {return -code error} while 1}
    
    which stumbles on the fact that control::do is a proc, use
    the definition
    
    eproc c {} {control::do {returneval {error}} while 1}
    
    which does not. Indeed, even the $errorInfo one gets after
    [catch c] is (with the exception of the proc name) identical
    to that one gets from [catch a], where [a] is defined by
    
    proc a {} {while 1 {return -code error}}
    
    Is it reasonable to request the use of [eproc] rather than
    [proc]? Perhaps not, but it probably isn't substantially
    more reasonable to request the use of [breakeval-aware
    foreach] and [breakeval {script}] instead of [foreach] and
    [break {script}].
    
    /Lars Hellström
    
    
    
  2. login: "nobody"
  3. mimetype: "text/plain"
  4. username: "nobody"