Short list with things to finish for D2

Stewart Gordon smjg_1998 at yahoo.com
Fri Nov 20 11:54:19 PST 2009


Andrei Alexandrescu wrote:
> We're entering the finale of D2 and I want to keep a short list of 
> things that must be done and integrated in the release. It is clearly 
> understood by all of us that there are many things that could and 
> probably should be done.

What do you mean by finale, exactly?

<snip>
> * Encode operators by compile-time strings. For example, instead of the 
> plethora of opAdd, opMul, ..., we'd have this:
> 
> T opBinary(string op)(T rhs) { ... }
> 
> The string is "+", "*", etc. We need to design what happens with 
> read-modify-write operators like "+=" (should they be dispatch to a 
> different function? etc.)
<snip>

Perhaps something like

     T opModify(string op)(T rhs)

so that
     a += b
would be equivalent to the first of these to be valid:
     a = a.opModify!("+")(b)
     a = (a.opModify!("+")(b), a)  (if opModify returns void)
     a = a.opBinary!("+")(b)
     a = b.opBinary!("+")(a)

The idea is that an opModify method would likely modify the object 
in-place and return the modified object, but may return a new object to 
be assigned to a.

That said, I'm not sure if there's any real use case for it being a new 
object distinct from simple a + b.  But maybe there are cases where it 
may variously modify in-place or reallocate.  (Is this still how ~= 
works in current D2?)

But whatever we do, we shouldn't allow opModify to return something if 
that something isn't going to be assigned to a.

Stewart.



More information about the Digitalmars-d mailing list