[Challenge] implementing the ambiguous operator in D

Simen kjaeraas simen.kjaras at gmail.com
Fri Sep 3 06:08:04 PDT 2010


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

> Hey, this question on SO makes for a good challenge:
>
> http://stackoverflow.com/questions/3608834/is-it-possible-to-generically-implement-the-amb-operator-in-d
>
> The amb operator does this:
>
> amb([1, 2]) * amb([3, 4, 5]) == amb([3, 4, 5, 6, 8, 10])
> amb(["hello", "world"]) ~ amb(["qwerty"]) == amb(["helloqwerty",  
> "worldqwerty"])
> amb(["hello", "world"]) ~ "qwerty" == amb(["helloqwerty", "worldqwerty"])
> amb(["hello", "very long string"]).length = amb([5, 16])
>
>
> (I find the guy examples much more comprehensible that the articles he  
> links
> to)
>
> Are people interested in trying this?


Yes, very much so. However, Peter Alexander has misunderstood the
ambiguous operator. The idea of amb is to return the combinatorial
product of N ranges. if this sounds familiar, it is because it has been
discussed at length here earlier, with me and Andrei being the prime
contributors (see Combining infinite ranges and Huffman coding
comparison). The solution has eluded me for a while, and I have shelved
my efforts while doing other things. Perhaps now is the time to revisit
it.

Peter Alexander seems to have conflated the two concepts of the
ambiguous operator and its require()-function. Basically, Amb should be
a range of tuples, and you then filter it to retrieve the interesting
parts.

-- 
Simen


More information about the Digitalmars-d mailing list