We are forking D

Andrej Mitrovic andrej.mitrovich at gmail.com
Mon Jan 8 14:50:45 UTC 2024


On Monday, 8 January 2024 at 14:34:26 UTC, Bruce Carneal wrote:
> On Monday, 8 January 2024 at 14:09:09 UTC, DrDread wrote:
>> On Sunday, 7 January 2024 at 18:51:40 UTC, Walter Bright wrote:
>>> ...
>>
>> and you _still_ misunderstand DIP 1036. which is the whole 
>> problem here. and we've told you repeatedly that you 
>> misunderstand it. please just go and look at the 
>> implementation.
>
> I read a draft 1036 spec from Atila on his publicly accessible 
> github here:
> https://github.com/atilaneves/DIPs/blob/string-interpolation/Interpolation.md
>
> It might not still be up but I found it approachable.  Again, 
> though, it's a draft and might not match the code (or the 
> actual intent for that matter).  Still, a useful possibility 
> for those who prefer not to look at code in the early going.

I really wish we didn't have to force parentheses in `$()` if the 
only thing inside the expression is an alphanumeric variable name.

There's the example of:

```D
enum result = text(
     i"@property bool $(name)() @safe pure nothrow @nogc const {
         return ($(store) & $(maskAllElse)) != 0;
     }
     @property void $(name)(bool v) @safe pure nothrow @nogc {
         if (v) $(store) |= $(maskAllElse);
         else $(store) &= 
cast(typeof($(store)))(-1-cast(typeof($(store)))$(maskAllElse));
     }\n"
);
```

But why not take it a step further and allow this:

```D
enum result = text(
     i"@property bool $name() @safe pure nothrow @nogc const {
         return ($store & $maskAllElse) != 0;
     }
     @property void $name(bool v) @safe pure nothrow @nogc {
         if (v) $store |= $maskAllElse;
         else $store &= 
cast(typeof($store))(-1-cast(typeof($store))$maskAllElse);
     }\n"
);
```

To me that's more readable then the first example where I have to 
count the closing parens to figure out where an expression starts 
and ends.

The `$()` should just be an escape hatch when you need more 
complex expressions. For example:

```D
int foo = 2;
int bar = 4;
writeln(i"$foo + $bar is $(foo + bar)");  // 2 + 4 is 6
```

I haven't read any rationale why parentheses are absolutely 
required in any of the DIPs I've skimmed through.


More information about the Digitalmars-d mailing list