why scope(success)?
Chris Nicholson-Sauls
ibisbasenji at gmail.com
Wed May 10 12:02:59 PDT 2006
Regan Heath wrote:
> On Tue, 9 May 2006 22:36:03 -0400, Ben Hinkle <ben.hinkle at gmail.com> wrote:
>
>>> Maybe... self documenting functions, listing all return values at
>>> the top?
>>>
>>> int foobar( ..etc.. )
>>> {
>>> scope(success) return 1;
>>> scope(failure) return 0;
>>>
>>> }
>>
>>
>> Does scope(failure) continue unwinding the stack? I wonder what the
>> behavior
>> is of returning from a scope(failure).
>
>
> Good question. No idea. :(
>
>> I believe writing "scope(success) foo;" followed by the end of the
>> current scope is equivalent to just writing "foo;". Maybe I'm
>> misunderstanding the example.
>
>
> You're right. For some reason I got it in my head that scope(success)
> happened when the function itself returned, as opposed to the current
> scope closing.
>
> So, what about in this case:
>
> int foobar( ..etc ..)
> {
> if (a) scope(success) a.foo();
> //A: immediately after if
> }
> //B: at function return
>
> when does a.foo() get executed? at A or B? I get the impression it's A.
>
> Regan
Evidence from testing is that a.foo() is executed at point A. Which I think is a shame,
really. It limits the usefulness of the scope() statement, which I feel is otherwise full
of potential. Maybe its a little silly to say aloud, but certain statements just
shouldn't "be a scope" for the sake of the scope() statement. Maybe different scopes
should have "weights" or something... I don't know how it should be done, just that it
should, or else a way created to say which scope you are anchoring on, but what on earth
would the syntax be?
-- Chris Nicholson-Sauls
More information about the Digitalmars-d
mailing list