Domain Specific Languages in D; was: C++, D: Dinosaurs?

Aarti_pl aarti at interia.pl
Wed Nov 5 03:17:21 PST 2008


Nick Sabalausky pisze:
> But I agree, a way to return a non-standard 
> type from an operator overload would be even better.

Unfortunately it would not be that easy in D.

With current operator overloading method you can not distinguish between 
equals and not equals, as method equals makes comparison itself - it's 
not just notification for user program that some specific operator 
should be called.

As I said before - current behavior makes sense, but it's also problem 
when you want to use &&, ||, == operators in SQL expressions (it 
definitely makes sense in such context and doesn't make user code look 
bad, but is not possible with schema choosen in D).

It would be solved with below:
1. Allow additional operators in D, such as:

T opSymbolEquals(U v1, V v2); //alt. T op==(U v1, V v2);
T opSymbolNotEquals(U v1, V v2); //alt. T op!=(U v1, V v2);
...

for cases where raw operators should be used.

Then it will be possible to use only one standard opEquals() or 
opSymbolEquals in one class.


2. Allow defining user infix operators.

Then it would be possible to define e.g.

opAND()

which is quite good for SQL queries.

BR
Marcin Kuszczak
(aarti_pl)



More information about the Digitalmars-d mailing list