DMD 0.177 release

Marcin Kuszczak aarti at interia.pl
Sat Dec 9 14:22:04 PST 2006


Walter Bright wrote:

>> I'm also a little wary about opAssign.  Not that I don't find it useful,
>> just that you've been vehemently opposed to overloading it in D for how
>> many years, and three weeks before 1.0 you reverse your opinion.  What
>> does that mean?
> 
> The problem I have, and still have, is the identity assignment. This is
> specifically disallowed with opAssign. I can go into the reasons why if
> you like.
> 

I wonder if it is not possible to make D, working as a base with values not
with references. 

In such a case references would be hidden from programmers and only values
would be visible at first. Assigning would always mean assign value, and
when there should be passed reference the special syntax would be
necessary, so references would be special case.

To disambiguate you can make something like this:

auto v := new Any; // special assignment operator ':=' for references
auto z := new Any;

v = 5; // Standard opAssign
z = v; // No problem here, opAssign can be used as usually
z :=v; // Reference copy - opAssign is not used here

Additionally when passing arguments to function, which demands references,
there could be used implicit conversion from values to references (so that
for user it would be visible as sending values). Below example almost works
now (almost because constructors can not be templatized):

void varFunc(Any[] arr ...) {
        foreach(v; arr) writefln(v.type);
}

void main() {
#       varFunc(new Any(5), new Any("tekst"[]), new Any(&variadicFunction));
}

In language in which everything is consider as an object you could just
write:

void main() {
        bool test;
#       varFunc(Any(5), Any("tekst"[]), Any(&variadicFunction));
#       varFunc(Any(5.6), Any(&test));
}

If there should be send reference(pointer) it should be done explicitly.
E.g.

void varFunc(Any*[] arr ...) {
....
}
void main() {
#       varFunc(new Any(5), new Any("tekst"[]), new Any(&variadicFunction));
}

Does it make any sense? Please comment...


> Having opAssign for foreign types turns out to be needed for things
> like, say I want to build a ranged integer. This is an integer that can
> only have values between m and n. Without opAssign, I'd have to use a
> property:
> RangedInt!(m,n) r;
> r.value = 6;
> It's just not right.

the same in case of boost::Any port to D.

-- 
Regards
Marcin Kuszczak
(Aarti_pl)



More information about the Digitalmars-d-announce mailing list