Scott Meyers' DConf 2014 keynote "The Last Thing D Needs"

Walter Bright via Digitalmars-d-announce digitalmars-d-announce at puremagic.com
Sat May 31 16:27:08 PDT 2014


On 5/30/2014 5:37 AM, Steven Schveighoffer wrote:
> On Thu, 29 May 2014 21:15:21 -0400, deadalnix <deadalnix at gmail.com> wrote:
>
>> On Thursday, 29 May 2014 at 19:06:15 UTC, Steven Schveighoffer
>> wrote:
>>>> Static if is certainly NOT an attribute, it doesn't make any sense.
>>>
>>> Well... it sorta does. static if does not introduce a new scope, even with
>>> {}, and this only happens with attributes.
>>>
>>> -Steve
>>
>> in which case
>>
>> static if(cond) {
>> immutable:
>> }
>>
>> int x;
>>
>> should not create x as immutable if cond is true. The current
>> behavior is not consistent with attribute either.
>
> Ugh, that is really bad. It shouldn't do that. Is that intentional?

Yes. Semantic scope and lexical scope are different things. The ':' thing 
applies to the remaining statements in the lexical scope. 'static if' does not 
create a new semantic scope, even though the { } suggests it does.

There have been several suggestions to make 'static if' apply independently of 
the rest of the grammar, i.e. allow things like:

     int static if (cond) * else [ ] foo; // conditionally make foo a pointer or 
an array

I think we can agree that looks awful, but it is the same thing as suggesting 
that the 'immutable:' above extend outside of its lexical scope.


You might ask "why is semantic scope different from lexical scope" and the 
reason is simply that 'static if' would not be very useful if that were the case.



More information about the Digitalmars-d-announce mailing list