Other than for the except and always clauses, RFC 199 is very
similar to RFC 88.  I like the idea behind except and always,
but I think the proposed implementation could be dramatically
simplified.

The first thing to realize is that just because 119 doesn't say
"try" the doesn't mean it isn't there, it's just implied.  To my
understanding, in order to be able to try, catch, or finally at all,
one must pre-arrange to have changed the exit-sequence code for a
block that has try, catch, or finally semantics, whether implicit
or not, because one has to do the stack unwinding thingy for such
blocks.  That's why some references mention that it may be difficult
to do a local goto across a non-local unwinding boundry.  On the
other hand, Perl is not so tied to hardware, so this may not be
difficult to arrange at all.

Whether or not local gotos out of unwind flow-control blocks can
be implemented does not impact the usefulness of the concepts of
except and always.  If those gotos can be done they will be,
otherwise they won't; it will have the same impact on 88 and 119.

So, lets say we had a syntax like this:

    {
    my $foo = $bar always <expr>;
    my $foo = $bar always <block>;
    my $foo = $bar always <code_ref>;
    ...
    }

The given <expr>, <block>, or <code_ref> would be evaluated just
before its associated lexical variable goes out of lexical scope,
including due to unwinding.

If some action is to be taken on end-of-scope, but only if an
exception is being caught (like RFC 119s "except") it can simply
be coded like this:

    my $foo = $bar always { $@ and catch_it($foo); };

because in an always (like in a finally in RFC 88), defined $@
indicates whether an exception is being handled, or normal local
processing is taking place.

This RFC would need some notes about where exactly "always" hooks
into the rules described in a generic mechanism like RFC 88, and
perhaps an RFC-88 style mechanism hook for invoking a callback
whenever an "always" is entered, like this:

    try on_always_enter => sub { ... }, { ... }

Note that since RFC 88 uses a "try" keyword to establish the
context in which a "finally" keyword is expected, and since
the my $foo examples above don't have such context, "always"
can probably be renamed "finally" without the parser getting
confused about RFC 88's finally.

And that would pretty much be my version of the "always" RFC.

Yours, &c, Tony Olekshy

Reply via email to