DMD 0.148 - scope guard
Bruno Medeiros
daiphoenixNO at SPAMlycos.com
Tue Feb 28 05:05:43 PST 2006
Chris Miller wrote:
> On Sat, 25 Feb 2006 21:06:36 -0500, Walter Bright
> <newshound at digitalmars.com> wrote:
>
>> Scope guards are a novel feature no other language has. They're based on
>> Andrei Alexandrescu's scope guard macros, which have led to considerable
>> interest in the idea. Check out the article
>> www.digitalmars.com/d/exception-safe.html
>>
>
> This format looks good to me:
>
> scope(exit) foo();
> scope(success) bar();
> scope(failure) baz();
>
> similar to extern(name), pragma(name), etc, requires one `scope`
> keyword, name in () doesn't need to be a keyword but is still treated
> special, and doesn't look bad.
Here's some more experimental ideas:
scope.onExit fooexpr;
scope.onSuccess barexpr;
scope.onFailure bazexpr;
Now a more clean/pure version, but that doesn't allow block statements:
scope.onExit(fooexpr);
scope.onSuccess(barexpr);
scope.onFailure(bazexpr);
Don't really 100% like them, but I'll present them anyway, maybe it will
inspire someone for a better idea. (The problem with this one is that is
makes scope seem like a workable proper object, while it's not)
--
Bruno Medeiros - CS/E student
"Certain aspects of D are a pathway to many abilities some consider to
be... unnatural."
More information about the Digitalmars-d
mailing list