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

End-of-scope actions, redux.

Thread Next
From:
Tony Olekshy
Date:
February 5, 2001 14:35
Subject:
End-of-scope actions, redux.
Message ID:
3A7F2AAE.F6A43337@avrasoft.com
Damian Conway wrote:
>
> Actually, I do agree that Perl 6 ought to provide a universal
> "destructor" mechanism on *any* block. For historical reasons, I
> suppose it should be C<continue>, though I would much prefer a
> more generic name, such as C<cleanup>.

Perl 6 ought to provide universal exit mechanisms for any delimited
scope, both for the case of normal sequential termination of scope,
and for the typically special cases of termination by non-local
flow control due to stack unwinding caused by the raising of an
exception.  Once you have both types of exit mechanisms, getting
the syntax and semantics relatively complete and consistent is
not necessarily trivial.

Many people put a lot of effort into this very problem in the
so-called errors mailing list during the Perl 6 RFC process.
One version of the results, with a fairly complete description
of the matters of dissent that were raised thereto, is contained
in RFC 88, "Omnibus Structured Exception/Error Handling Mechanism",
which I co-authored.

Using RFC 88's notation, the example being discussed in the parent
of this thread would be written something like this:

    sub read_it
    {
        try { my $fh = open @_; <$fh> }
        finally { $fh and close $fh }
        }

The existence of the "try" keyword, the choice of other names, and
actually important matters such as the lexical scope of $fh, are
discussed in RFC 88.  More complex constructs that are natural
extensions of the concept are also considered, such as the very
useful case of multiple finally blocks, along these lines:

    try { my $p = P->new; my $q = Q->new; ... }
    finally { $p and $p->Done; }
    finally { $q and $q->Done; }

which invokes $q->Done if $q was allocated, even if $p->Done raises
an exception!

Please do consider RFC 88 before re-executing the entire debate on
this matter again.  While many ideas sound good in isolation, gluing
the collection of ideas into a coherent whole can be more challenging.
And, Larry did mention the try catch catch catch finally construct in
his ALS talk.

For your reference, here are some RFC 88 links:

    RFC 88 as HTML   http://www.avrasoft.com/perl6/rfc88.htm
    RFC 88 as Text   http://www.avrasoft.com/perl6/rfc88.txt
    RFC 88 as POD    http://www.avrasoft.com/perl6/rfc88-pod.txt

    Perl 5 Try.pm    http://www.avrasoft.com/perl6/try6-ref5.txt
    Regression Test  http://www.avrasoft.com/perl6/try-tests.htm

Yours, &c, Tony Olekshy

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