develooper Front page | perl.perl6.language | Postings from February 2001

Re: End-of-scope actions: POST blocks.

Thread Previous | Thread Next
From:
Tony Olekshy
Date:
February 12, 2001 20:25
Subject:
Re: End-of-scope actions: POST blocks.
Message ID:
3A88B70F.1B773483@avrasoft.com
"David L. Nicol" wrote:
> 
> POST{stuff} is a macro for
> 
> push (my) @Deferred_stuff, sub {stuff}; # my on first use in a space

Since the reference implementation requires try, @Deferred_stuff is
actually try's argument list (a bunch of tagged catch and finally
blocks).  The "my" is provided by try.  But in general, yes, if
post/always/except is part of Perl 6 then every block will have to
keep track of whether or not any such action has been seen during
the excecution of the block.  Fortunately, it need do nothing
special if no such actions have been seen (such as, oh, GC for
example).

> and return(arg) becomes, including implied EndOfBlock return:
> 
> &{shift @Deferred_stuff} while @Deferred_stuff; return(arg)

Yes, but you have to keep track of exceptions raised while
executing &{shift @Deferred_stuff}, so you can propagate them
if they occur, and you have to keep track of catch clauses that
don't raise exceptions, because they can terminate propagation.
For example:

    my $r = do { except { h() }; f() };
    g();
or
    my $r = try { f() } catch { h() };
    g();

should set $r to f() unless f() raises an exception, in which
case it should use h() for $r, and whether or not f() raises an
exception it should *not* propagate such an exception, it should
execute g().  Unless, of course, h() throws, in which case it
should propagate that exception, not set $r, and not call g().

On the other hand:

    my $r = do { always { h() }; f() };
    g();
or
    my $r = try { f() } finally { h() };
    g();

should call h() whether or not f() throws; and if f() or h()
throw the exception should be propagated, otherwise $r should
be set, and g() should be called.

Yours, &c, Tony Olekshy

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About