DMD 1.035 and 2.019 releases

Tomas Lindquist Olsen tomas at famolsen.dk
Thu Sep 4 09:28:42 PDT 2008


Jarrett Billingsley wrote:
> On Thu, Sep 4, 2008 at 7:58 AM, Denis Koroskin <2korden at gmail.com> wrote:
>> On Thu, 04 Sep 2008 15:44:30 +0400, Tomas Lindquist Olsen
>> <tomas at famolsen.dk> wrote:
>>
>>> Walter Bright wrote:
>>>> bearophile wrote:
>>>>> Walter Bright:
>>>>>> If there's any constructor defined for S, then S(args) is a
>>>>>> constructor call. If there's any opCall defined for S, then S(args)
>>>>>> is an opCall call. Otherwise, it's a struct literal.
>>>>> I haven't tried that in real code, so I can't be sure, but while it
>>>>> may work for the compiler, it sounds a bit too much complex for the
>>>>> person that later reads the code. Too many alternative possibilities
>>>>> may make the code more complex to follow.
>>>>>
>>>>> To reduce such ambiguity (ambiguity for the person, not for the
>>>>> compiler) may be to change the syntax of struct literals...
>>>>  I disagree, I think just the reverse. The S(args) syntax means that it's
>>>> entirely up to the struct designer to say how it should work. The user
>>>> needn't know or care, and the struct designer can change the design without
>>>> affecting user code.
>>>>
>>> This is one of those things I really dislike about D :(
>>> It's really nice that we can override struct initialization, but the fact
>>> that it eliminates the possibility to override it (with a nice syntax) makes
>>> it much less appealing IMHO.
>>>
>>> The most important point to me, is that old thing about static struct
>>> initializer and struct literals have different syntaxes, and that the static
>>> variant is much more flexible.
>>>
>>> I would have loved to see the static struct initializer syntax become an
>>> expression. If the problem is ambiguity, why not just prefix the {} braces
>>> with the struct name?
>>>
>>> struct S
>>> {
>>>  int a;
>>>  float b;
>>> }
>>>
>>> const s = S{1, 2.0};
>>> const t = S{b:3.14};
>>>
>>> void foo()
>>> {
>>>  auto st = S{4,5.5};
>>> }
>>>
>> It may have problems with the q{}:
>>
>> struct q
>> {
>>    float t;
>> }
>>
>> auto foo = q{ t = 3.1415f };    // what's the type of foo?
>>
>> But then, does anybody using it?
>>
>> Other than that I agree, current solution is not very good.
>>
> 
> auto foo = q { t: 3.1415f}; // typeof(foo) == q
> 
> q{ is treated more or less as an atomic character.  Put a space
> between them and bam, you have a struct literal.
> 
> And please don't get rid of token strings; those of us who love mixins
> wouldn't want to see them go ;)

I kinda like

""{foobar etc}

as an alternative


More information about the Digitalmars-d-announce mailing list