"Philippe Sigaud" <philippe.sig...@gmail.com> wrote in message news:mailman.42.1283371696.858.digitalmar...@puremagic.com... > 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]) >
Interesting thing, but devil's advocate: What would be the uses/benefits of that versus just having "for each element" versions of the operators? Also, "ambiguous" seems like a rather odd name for what it does. I don't see how ambiguity has anything to do with it. That disconnect made it difficult at first for me to understand what it was. It's more like an "elementwise" or something. Certainly useful, I had reason to make a similar function once: /// ctfe_subMapJoin("Hi WHO. ", "WHO", ["Joey", "Q", "Sue"]) /// --> "Hi Joey. Hi Q. Hi Sue. " T ctfe_subMapJoin(T)(T str, T match, T[] replacements) if(isSomeString!T) { T value = ""; foreach(T replace; replacements) value ~= ctfe_substitute(str, match, replace); return value; } Though I'll grant that's a questionable name for it. I wasn't sure what else to call it though.