What is 'scope' in function parameter?
Mike Franklin
slavo5150 at yahoo.com
Mon Dec 25 12:11:58 UTC 2017
On Monday, 25 December 2017 at 11:09:25 UTC, Jonathan M Davis
wrote:
>> ```
>> import std.stdio;
>>
>> int[] x;
>>
>> void func(scope int[] a) {
>> x = a;
>> }
>>
>> void main() {
>> func([0,1,2]);
>> writeln(x);
>> }
>> ```
>>
>> This code was successfully compiled and printed '[0, 1, 2]'.
>>
>> But according to https://dlang.org/spec/function.html, above
>> code must cause a compile error.
>>
>> Could you give me any advice?
>
> Walter has been working on DIP 1000, which broadens scope so
> that it affects a lot more types, and that can be triggered
> with the -dip1000 compiler flag, but it's very much a work in
> progress, and I wouldn't advise using it at this point. Without
> it, scope has zero effect on something like a dynamic array.
>
> https://github.com/dlang/DIPs/blob/master/DIPs/DIP1000.md
But we need people to use -dip25 and -dip1000 and provide
feedback, submit bug reports, etc.. so we can move the
implementation forward.
Based on your assessment, is Sobaya's test case an indication of
a bug in -dip1000's implementation?
Mike
More information about the Digitalmars-d-learn
mailing list