Thread overview
New thing I learned for the day
Nov 26, 2019
Adam D. Ruppe
Nov 26, 2019
Timon Gehr
Nov 28, 2019
H. S. Teoh
November 26, 2019
Did you know this was valid syntax? I didn't.

static if(cond)
   ...
else: // wat...


seen here:
https://github.com/dlang/phobos/blob/3bfccf4f160a07165682549407eaeec5c8907c82/std/utf.d#L4213-L4215

Only seems to work outside of functions, and naturally then not for normal if statements.

-Steve
November 26, 2019
On Tuesday, 26 November 2019 at 15:28:38 UTC, Steven Schveighoffer wrote:
> Did you know this was valid syntax? I didn't.

I did not know already, but it is no surprise to me either because the colon works on almost every other attribute like that too... static if and version are similar according to teh grammar.
November 26, 2019
On 11/26/19 10:35 AM, Adam D. Ruppe wrote:
> On Tuesday, 26 November 2019 at 15:28:38 UTC, Steven Schveighoffer wrote:
>> Did you know this was valid syntax? I didn't.
> 
> I did not know already, but it is no surprise to me either because the colon works on almost every other attribute like that too... static if and version are similar according to teh grammar.

static if and version are not attributes. But actually, I didn't know that it works with version as well. Seems to also work with a debug condition according to grammar.

What's weird is that it doesn't work in a function, but I guess those are considered a different part of the grammar.  In any case, I probably will not be using it. But I did a double take when I saw it...

-Steve
November 26, 2019
On 26.11.19 16:50, Steven Schveighoffer wrote:
> On 11/26/19 10:35 AM, Adam D. Ruppe wrote:
>> On Tuesday, 26 November 2019 at 15:28:38 UTC, Steven Schveighoffer wrote:
>>> Did you know this was valid syntax? I didn't.
>>
>> I did not know already, but it is no surprise to me either because the colon works on almost every other attribute like that too... static if and version are similar according to teh grammar.
> 
> static if and version are not attributes. But actually, I didn't know that it works with version as well. Seems to also work with a debug condition according to grammar.
> 
> What's weird is that it doesn't work in a function, but I guess those are considered a different part of the grammar.  In any case, I probably will not be using it. But I did a double take when I saw it...
> 
> -Steve

static foreach(i;0..10):

pragma(msg, ":P");
pragma(msg, "!");
November 28, 2019
On Tue, Nov 26, 2019 at 05:02:26PM +0100, Timon Gehr via Digitalmars-d wrote: [...]
> static foreach(i;0..10):
> 
> pragma(msg, ":P");
> pragma(msg, "!");

Ouch. That's ... ouch.

Chalking this down to one of the darker corners of D. :-/


T

-- 
Being forced to write comments actually improves code, because it is easier to fix a crock than to explain it. -- G. Steele