Chaim Frenkel wrote:
> 
> Tony Olekshy wrote:
> >
> > If you write this:
> >
> >     try { my $p = P->new;
> >           my $q = Q->new;
> >         }
> >     finally { $p and $p->Done;
> >               $q and $q->Done;
> >             }
> >
> > what happens if both constructors succeed, but $p->Done dies?
> 
>         try { my $p = P->new; }
>         try { my $q = Q->new; }
>         finally { $p and $p->Done; }
> 
> If P barfs then there is no q. If q barfs, then there is only a p.

Please read more carefully.  I did not ask what happens when P->new
dies.  I asked what happens when $p->Done dies.  $q->Done is supposed
to get called anyway.

> And if you argue that there is more complicated stuff going on in
> the try block. Then you'll never get anything worked out.

Speak for yourself.  We regularly do stuff like this:

        try {
            my $p = P->New...
            .
            . handful of lines here
            .
            $foo and my $q = Q->New...  # might not happen
            .
            . handful of lines here
            .
            }
        finally { $p and $p->Done; }
        finally { $q and $q->Done; }

> Doing a whole series of finally's will not help you without thinking
> about the problem of restoring the invariants.

I'm well aware of that, and perfectly capable of doing so.  The problem
is, once I've done so and find I need to make sure each constructor is
paired with a Done, how do I do that in Perl.  RFC 88 just makes it
easier, no more than that.

Yours, &c, Tony Olekshy

Reply via email to