September 03, 2008
Jarrett Billingsley wrote:
> Speaking of syntactical ambiguity, the expression
> 
> S(1, 2, 3)
> 
> can, right now, have one of three meanings:
> 
> 1. A struct literal for struct S
> 2. A call to S's static opCall
> 3. An instantiation of S and a call to its ctor
> 
> Even if opCall goes away, we'll still be left with the ambiguity of struct literal vs. ctor.  I'd really, really like to hear Walter's view on this but he has responded neither to the thread I posted on digitalmars.D nor the bugzilla ticket (http://d.puremagic.com/issues/show_bug.cgi?id=2170).

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.
September 03, 2008
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...

Bye,
bearophile
September 04, 2008
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.

September 04, 2008
On Wed, Sep 3, 2008 at 7:29 PM, Walter Bright <newshound1@digitalmars.com>wrote:

> Jarrett Billingsley wrote:
>
>> Speaking of syntactical ambiguity, the expression
>>
>> S(1, 2, 3)
>>
>> can, right now, have one of three meanings:
>>
>> 1. A struct literal for struct S
>> 2. A call to S's static opCall
>> 3. An instantiation of S and a call to its ctor
>>
>> Even if opCall goes away, we'll still be left with the ambiguity of struct literal vs. ctor.  I'd really, really like to hear Walter's view on this but he has responded neither to the thread I posted on digitalmars.D nor the bugzilla ticket (http://d.puremagic.com/issues/show_bug.cgi?id=2170).
>>
>
> 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.
>

So uh,

why don't you want to change struct literals?


September 04, 2008
On Wed, 03 Sep 2008 20:04:49 -0400, Jarrett Billingsley wrote:

> On Wed, Sep 3, 2008 at 7:29 PM, Walter Bright <newshound1@digitalmars.com>wrote:
> 
>> Jarrett Billingsley wrote:
>>
> Otherwise, it&#39;s a struct literal.<br> </blockquote></div><br>So uh,<br><br>why don&#39;t you want to change struct literals?<br><br></div>

Hi Jarrett,
do you mind not to use html markup?
My news reader has no html renderer, nor my eye to brain connection.
Thanks. :)
September 04, 2008
Walter Bright a écrit :
> Chris R. Miller wrote:
>> Walter Bright wrote:
>>> Sean Kelly wrote:
>>>> Walter Bright wrote:
>>>>> Struct constructors!
>>>> Must... have... D2.  :-)
>>> I figured you'd be seduced sooner or later!
>>
>> So this would make structs (in effect) classes that don't exist on the heap?
>>
> 
> No, structs do not inherit and do not have virtual functions.

So both syntax are possible?

S(...)
new S(...)

for a struct with a constructor? Is that documented anywhere?
September 04, 2008
On Thu, Sep 4, 2008 at 9:50 AM, Ary Borenszweig <ary@esperanto.org.ar> wrote:
> Walter Bright a écrit :
>>
>> Chris R. Miller wrote:
>>>
>>> Walter Bright wrote:
>>>>
>>>> Sean Kelly wrote:
>>>>>
>>>>> Walter Bright wrote:
>>>>>>
>>>>>> Struct constructors!
>>>>>
>>>>> Must... have... D2.  :-)
>>>>
>>>> I figured you'd be seduced sooner or later!
>>>
>>> So this would make structs (in effect) classes that don't exist on the
>>> heap?
>>>
>>
>> No, structs do not inherit and do not have virtual functions.
>
> So both syntax are possible?
>
> S(...)
> new S(...)
>
> for a struct with a constructor? Is that documented anywhere?
>

I'm pretty sure that's:

S thing = S(...);
S* ptr = new S(...);

So yes both syntaxes are possible, but they are not synonyms.

--bb
September 04, 2008
Walter Bright wrote:
> Struct constructors!

Thanks for the nice release!

I have a question. The "dynamic initialization of struct" syntax seems
still using opCall. Is it going to replaced by constructors?

    struct S {
        this(int x) {
            writeln("ctor");
        }
        static S opCall(int x) {
            writeln("opCall");
            return S.init;
        }
    }

    void main(){
        S s = 1; // prints "opCall"
    }
September 04, 2008
On Wed, Sep 3, 2008 at 8:22 PM, Moritz Warning <moritzwarning@web.de> wrote:
>
> On Wed, 03 Sep 2008 20:04:49 -0400, Jarrett Billingsley wrote:
>
> > On Wed, Sep 3, 2008 at 7:29 PM, Walter Bright <newshound1@digitalmars.com>wrote:
> >
> >> Jarrett Billingsley wrote:
> >>
> > Otherwise, it&#39;s a struct literal.<br> </blockquote></div><br>So uh,<br><br>why don&#39;t you want to change struct literals?<br><br></div>
>
> Hi Jarrett,
> do you mind not to use html markup?
> My news reader has no html renderer, nor my eye to brain connection.
> Thanks. :)

Ack, I've started using the mailing lists and gmail to interact with the newsgroups and forgot that it uses HTML by default, thanks for the heads up.
September 04, 2008
On Thu, Sep 4, 2008 at 10:38 AM, Jarrett Billingsley <jarrett.billingsley@gmail.com> wrote:
> On Wed, Sep 3, 2008 at 8:22 PM, Moritz Warning <moritzwarning@web.de> wrote:
>>
>> On Wed, 03 Sep 2008 20:04:49 -0400, Jarrett Billingsley wrote:
>>
>> > On Wed, Sep 3, 2008 at 7:29 PM, Walter Bright <newshound1@digitalmars.com>wrote:
>> >
>> >> Jarrett Billingsley wrote:
>> >>
>> > Otherwise, it&#39;s a struct literal.<br> </blockquote></div><br>So uh,<br><br>why don&#39;t you want to change struct literals?<br><br></div>
>>
>> Hi Jarrett,
>> do you mind not to use html markup?
>> My news reader has no html renderer, nor my eye to brain connection.
>> Thanks. :)
>
> Ack, I've started using the mailing lists and gmail to interact with the newsgroups and forgot that it uses HTML by default, thanks for the heads up.
>

That happened to me too.

I posted a suggestion to Google after that that Gmail should be smart
enough not to reply to a plain text message with an HTML formatted
one.  Or that there should be a way to specify certain recipients
don't get HTML.
Maybe if you suggest it too it will push it up on their radar a bit.

--bb