• Script completion status

    From Alan Grunwald@21:1/5 to All on Wed Aug 17 22:28:04 2022
    Summary:

    I've found the following:

    % puts stdout [catch {incr i}]
    0
    % puts stdout [catch {error foo}]
    1
    % puts stdout [catch {return foo}]
    2
    % puts stdout [catch {break}]
    3
    % puts stdout [catch {continue}]
    4

    Which is all as expected and documented.

    However

    % puts stdout [catch {return -code ok}]
    2
    % puts stdout [catch {return -code error}]
    2
    % puts stdout [catch {return -code return}]
    2
    % puts stdout [catch {return -code break}]
    2
    % puts stdout [catch {return -code continue}]
    2

    I'd expect these to return 0, 1, 2, 3 and 4 as in the previous case.

    What am I missing?

    Background:

    I'm doing some web scraping and I want to check if something has
    appeared on the page, if so, I'm done, otherwise I want to pause and
    retry a few times, and if it's not there at the end there's an error.
    So, I'm trying to develop a new control structure of the form

    proc wait {testScript} {backoff script} {timeoutScript} {
    .
    .
    .
    }

    I want to return some application-specific information from the
    timeoutScript, and I've been trying to do so via [return -code error],
    but the error isn't being propagated to the code that calls wait because timeoutScript is using return -code error -errorinfo {...} {other
    stuff}. I've changed this to error {other stuff} {...} and my code in
    [wait] works as I want it to, but the return manpage seems to suggest
    using [return] rather than [error].

    I'm using tcl 8.6.9 from ActiveTcl and testing with tkcon.

    Alan

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From apn@21:1/5 to Alan Grunwald on Thu Aug 18 07:01:47 2022
    The -code option value has to be interpreted in conjunction with the
    -level option which defaults to 1.

    % puts [catch {return -code error -level 0}]
    1
    % puts [catch {return -code break -level 0}]
    3
    % puts [catch {return -code continue -level 0}]
    4

    Without the -level 0, the codes are seen one level up the stack
    (defaulting to -level 1), not by the return invocation itself.

    % proc xx {} {return -code break} ; # Defaults to -level 1
    % catch {xx}
    3
    % proc yy {} {return -code break -level 2}
    % proc zz {} {yy}
    % catch yy
    2
    % catch zz
    3

    /Ashok

    On 8/18/2022 2:58 AM, Alan Grunwald wrote:
    Summary:

    I've found the following:

    % puts stdout [catch {incr i}]
    0
    % puts stdout [catch {error foo}]
    1
    % puts stdout [catch {return foo}]
    2
    % puts stdout [catch {break}]
    3
    % puts stdout [catch {continue}]
    4

    Which is all as expected and documented.

    However

    % puts stdout [catch {return -code ok}]
    2
    % puts stdout [catch {return -code error}]
    2
    % puts stdout [catch {return -code return}]
    2
    % puts stdout [catch {return -code break}]
    2
    % puts stdout [catch {return -code continue}]
    2

    I'd expect these to return 0, 1, 2, 3 and 4 as in the previous case.

    What am I missing?



    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Alan Grunwald@21:1/5 to apn on Thu Aug 18 12:54:41 2022
    Thanks Ashok,

    That has certainly fixed my problem.

    I guess the problem is that the code with the 'return' in it is executed
    via uplevel rather than some variety of call. I suppose the lesson is
    that this is pushing my understanding of Tcl to its limits.

    Thanks again,

    Alan

    On 18/08/2022 02:31, apn wrote:
    The -code option value has to be interpreted in conjunction with the
    -level option which defaults to 1.

    % puts [catch {return -code error -level 0}]
    1
    % puts [catch {return -code break -level 0}]
    3
    % puts [catch {return -code continue -level 0}]
    4

    Without the -level 0, the codes are seen one level up the stack
    (defaulting to -level 1), not by the return invocation itself.

    % proc xx {} {return -code break} ; # Defaults to -level 1
    % catch {xx}
    3
    % proc yy {} {return -code break -level 2}
    % proc zz {} {yy}
    % catch yy
    2
    % catch zz
    3

    /Ashok

    On 8/18/2022 2:58 AM, Alan Grunwald wrote:
    Summary:

    I've found the following:

    % puts stdout [catch {incr i}]
    0

    <snip>


    Which is all as expected and documented.

    However

    % puts stdout [catch {return -code ok}]
    2

    <snip>


    What am I missing?




    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Alex P@21:1/5 to All on Fri Aug 19 04:18:26 2022
    Just to not limiting yourself:
    https://www.magicsplat.com/ttpl/index.html

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)