[Challenge] implementing the ambiguous operator in D

Simen kjaeraas simen.kjaras at gmail.com
Sun Sep 5 03:00:50 PDT 2010


Philippe Sigaud <philippe.sigaud at gmail.com> wrote:

> I guess the D syntax would be
> auto x = amb([1,2,3]);
> auto y =amb([4,5,6]);
> x*y == 8; // forces desambiguation => the ambs explore the possibilities.
> assert(x == amb([2]));
> assert(y == amb([4]));
>
> There is only one value left, no more ambiguity.

But what happens in the case where there is more than one value left?
That's one of the reasons I feel that doing the combination, then
filtering it, is more correct. There is also the fact that the above
syntax does not let you call arbitrary functions in the requirements,
something filter does.


> Maybe in this case an
> 'alias possibilities[0] this' could do the trick:
>
> assert(x == 2);
> assert(y == 4);
>
> Can we do alias someArray[0] this; ?

Well, we can do this:

struct foo( R ) {
     R range;

     ref ElementType!R getFront( ) {
         return range.front;
     }

     alias getFront this;
}

-- 
Simen


More information about the Digitalmars-d mailing list