* bogus codegen with static opAssign() usage *

Bill Baxter dnewsgroup at billbaxter.com
Mon Feb 19 12:55:26 PST 2007


Bill Baxter wrote:
> Walter Bright wrote:
>> kris wrote:
>>> The syntax, however, is very clean. Importantly, it supports the 
>>> unification or /centralization/ of all those 'new' invocations. I'd 
>>> go so far as to say such a syntax could represent a bridge between OO 
>>> and scripting:
>>>
>>> ----
>>> String s = "mystring";
>>> ----
>>>
>>> ----
>>> File f = "/foo/bar.d";
>>> ----
>>>
>>> ----
>>> Regex r = "^(.*)$";
>>> ----
>>>
>>> There's a fairly wide range of simple applicability for this kinda' 
>>> thing. Would be great if static opAssign() could support this, or 
>>> some other operator were enabled?
>>>
>>> How about it?
>>
>> I don't get it. Exactly what transformation are you looking for?
> 
> He wants
>    String s = "mystring";
> 
> To call something like:
>    static String opConstruct(char[] str) {
>           return new String(str);
>    }
> 
> So that 's' get's initialized with a freshly allocated String.
> With the current opAssign stuff you have to do:
> 
>      String s = new String;
>      s = "mystring";
> 
> I've felt this too.  After you add an opCast, 

Correction: I meant opAssign.

>things like s="mystring" 
> become valid, and soon after that you start to expect String s = 
> "mystring" to work too.

I agree with kris that such a thing would be nice to have.  If a=b works 
it seems like "Type a = b" should work too.

--bb



More information about the Digitalmars-d mailing list