On 12/5/14 3:55 PM, Walter Bright wrote:
On 12/5/2014 7:27 AM, Steven Schveighoffer wrote:
Can someone who knows what this new feature is supposed to do give
some Ali
Çehreli-like description on the feature? Basically, let's strip out
the *proof*
in the DIP (the how it works and why we have it), and focus on how it
is to be
used.

I still am having a hard time wrapping my head around the benefits and
when to
use scope, scope ref, why I would use it. I'm worried that we are
adding all
this complication and it will confuse the shit out of users, to the
point where
they won't use it.

The tl;dr version is when a declaration is tagged with 'scope', the
contents of that variable will not escape the lifetime of that declaration.

It means that this code will be safe:

    void foo(scope int* p);

    p = malloc(n);
    foo(p);
    free(p);

The rest is all the nuts and bolts of making that work.


This is not what I was asking for. What I wanted to know was, when I see scope ref, why is it there? When should I use it? When should I use scope? What nasty things are prevented if I use it? Examples would be preferable.

Note, in your example above, marking foo pure solves the problem already.

The rules and statements give an inferred benefit. I'd like that benefit to be more fully explained.

-Steve

Reply via email to