Re: [Challenge] implementing the ambiguous operator in D

2010-09-07 Thread Peter Alexander
I agree with Andrei here, building hypercubes makes more sense, and feels like it has more structure. It also has the nice property that, once you've seen a (n+1)th element of any range then you have already explored the entire product of the first n elements of every range, kind of like how

Re: [Challenge] implementing the ambiguous operator in D

2010-09-07 Thread Andrei Alexandrescu
On 09/07/2010 02:43 AM, Peter Alexander wrote: I agree with Andrei here, building hypercubes makes more sense, and feels like it has more structure. It also has the nice property that, once you've seen a (n+1)th element of any range then you have already explored the entire product of the

Re: [Challenge] implementing the ambiguous operator in D

2010-09-06 Thread Peter Alexander
== Quote from Andrei Alexandrescu Yah, per your follow-up post, it's a different problem. It's also a much more difficult one. I convinced myself crossProduct is impossible to implement if one input range and one infinite forward range are simultaneously present. It works with any number of

Re: [Challenge] implementing the ambiguous operator in D

2010-09-06 Thread Simen kjaeraas
Peter Alexander peter.alexander...@gmail.com wrote: I must be missing something, because I don't understand how you could possibly take the cross product of any number of infinite ranges (other than to just return the range of (a[0], b[i]) for all (infinitely many) i in b). Note that I'm

Re: [Challenge] implementing the ambiguous operator in D

2010-09-06 Thread Simen kjaeraas
Andrei Alexandrescu seewebsiteforem...@erdani.org wrote: I convinced myself crossProduct is impossible to implement if one input range and one infinite forward range are simultaneously present. It works with any number of infinite forward ranges, and also with other combinations. I couldn't

Re: [Challenge] implementing the ambiguous operator in D

2010-09-06 Thread Simen kjaeraas
Simen kjaeraas simen.kja...@gmail.com wrote: Special cases come for input ranges - I will not consider those. All forward ranges can be treated the same, regardless of infiniteness. Actually, input ranges make everything a lot easier - the best solution is the brute-force stupid solution. --

Re: [Challenge] implementing the ambiguous operator in D

2010-09-06 Thread Andrei Alexandrescu
On 09/06/2010 06:51 AM, Peter Alexander wrote: == Quote from Andrei Alexandrescu Yah, per your follow-up post, it's a different problem. It's also a much more difficult one. I convinced myself crossProduct is impossible to implement if one input range and one infinite forward range are

Re: [Challenge] implementing the ambiguous operator in D

2010-09-06 Thread Simen kjaeraas
Attached latest version. It bugs out with an infinite loop, and I'm too tired to look more at it now. -- Simen autoRefTuple.d Description: Binary data combine.d Description: Binary data

Re: [Challenge] implementing the ambiguous operator in D

2010-09-06 Thread Peter Alexander
== Quote from Andrei Alexandrescu (seewebsiteforem...@erdani.org)'s article We've discussed this before. Crosscartesian product of multiple infinite ranges can be easily done by applying Cantor's trick for proving that rational numbers are just as numerous than natural numbers. Google for

Re: [Challenge] implementing the ambiguous operator in D

2010-09-06 Thread Andrei Alexandrescu
On 09/06/2010 04:34 PM, Philippe Sigaud wrote: Which gives us: (0,0),(0,1),(1,0),(0,2),(1,1),(2,0),(0,3), .. See the indices: sum of 0, then sum of 1, then sum of 2, ... You never get stuck in an infinite line since these diagonal slices are finite. I don't think iteration for constant index

Re: [Challenge] implementing the ambiguous operator in D

2010-09-05 Thread Simen kjaeraas
Philippe Sigaud philippe.sig...@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.

Re: [Challenge] implementing the ambiguous operator in D

2010-09-05 Thread Philippe Sigaud
On Sun, Sep 5, 2010 at 12:00, Simen kjaeraas simen.kja...@gmail.com wrote: Philippe Sigaud philippe.sig...@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 ==

Re: [Challenge] implementing the ambiguous operator in D

2010-09-05 Thread Denis Koroskin
On Sun, 05 Sep 2010 16:59:31 +0400, Philippe Sigaud philippe.sig...@gmail.com wrote: But the real challenge in the SO question is the 'going back in time' part, which I have trouble to understand : how can you modify x and y through a multiplication and a comparison? It can be done using

Re: [Challenge] implementing the ambiguous operator in D

2010-09-05 Thread Andrei Alexandrescu
On 09/05/2010 07:59 AM, Philippe Sigaud wrote: On Sun, Sep 5, 2010 at 12:00, Simen kjaeraas simen.kja...@gmail.com mailto:simen.kja...@gmail.com wrote: Philippe Sigaud philippe.sig...@gmail.com mailto:philippe.sig...@gmail.com wrote: I guess the D syntax would be auto

Re: [Challenge] implementing the ambiguous operator in D

2010-09-05 Thread Philippe Sigaud
2010/9/5 Denis Koroskin 2kor...@gmail.com On Sun, 05 Sep 2010 16:59:31 +0400, Philippe Sigaud philippe.sig...@gmail.com wrote: But the real challenge in the SO question is the 'going back in time' part, which I have trouble to understand : how can you modify x and y through a

Re: [Challenge] implementing the ambiguous operator in D

2010-09-05 Thread Philippe Sigaud
On Sun, Sep 5, 2010 at 15:56, Andrei Alexandrescu seewebsiteforem...@erdani.org wrote: equivalent to the problem: auto solution = comp!([a,b], a*b == 8)([1,2,3], [4,5,6]); solution is a range, in this case a one element range, containing only [2,4]. I did a range comprehension maybe one

Re: [Challenge] implementing the ambiguous operator in D

2010-09-05 Thread Philippe Sigaud
On Sun, Sep 5, 2010 at 16:30, Philippe Sigaud philippe.sig...@gmail.comwrote: What you call crossProduct can be seen as zipWith!tuple(range, range2), which Scratch that. zipWith *is* mapping on n ranges in parallel.

Re: [Challenge] implementing the ambiguous operator in D

2010-09-05 Thread Denis Koroskin
On Sun, 05 Sep 2010 18:24:43 +0400, Philippe Sigaud philippe.sig...@gmail.com wrote: 2010/9/5 Denis Koroskin 2kor...@gmail.com On Sun, 05 Sep 2010 16:59:31 +0400, Philippe Sigaud philippe.sig...@gmail.com wrote: But the real challenge in the SO question is the 'going back in time' part,

Re: [Challenge] implementing the ambiguous operator in D

2010-09-05 Thread bearophile
Denis Koroskin: The code above should print: state saved state restored (not tested) On Windows, dmd 2.048, this code: import std.c.stdio: puts; version (Windows) { alias int[16] jmp_buf; extern (C) extern { int setjmp(ref jmp_buf env); void longjmp(ref jmp_buf

Re: [Challenge] implementing the ambiguous operator in D

2010-09-05 Thread Denis Koroskin
On Sun, 05 Sep 2010 19:17:55 +0400, bearophile bearophileh...@lycos.com wrote: Denis Koroskin: The code above should print: state saved state restored (not tested) On Windows, dmd 2.048, this code: import std.c.stdio: puts; version (Windows) { alias int[16] jmp_buf; extern (C)

Re: [Challenge] implementing the ambiguous operator in D

2010-09-05 Thread bearophile
Denis Koroskin: Turn main into an extern(C) int main() and it works. This version: import std.c.stdio: puts; version (Windows) { alias int[16] jmp_buf; extern (C) extern { int setjmp(ref jmp_buf env); void longjmp(ref jmp_buf env, int value); } } struct State {

Re: [Challenge] implementing the ambiguous operator in D

2010-09-05 Thread Denis Koroskin
On Sun, 05 Sep 2010 20:18:13 +0400, bearophile bearophileh...@lycos.com wrote: Denis Koroskin: Turn main into an extern(C) int main() and it works. This version: import std.c.stdio: puts; version (Windows) { alias int[16] jmp_buf; extern (C) extern { int setjmp(ref

Re: [Challenge] implementing the ambiguous operator in D

2010-09-05 Thread Andrei Alexandrescu
On 09/05/2010 09:30 AM, Philippe Sigaud wrote: On Sun, Sep 5, 2010 at 15:56, Andrei Alexandrescu seewebsiteforem...@erdani.org mailto:seewebsiteforem...@erdani.org wrote: equivalent to the problem: auto solution = comp!([a,b], a*b == 8)([1,2,3], [4,5,6]); solution is

Re: [Challenge] implementing the ambiguous operator in D

2010-09-05 Thread Simen kjaeraas
Philippe Sigaud philippe.sig...@gmail.com wrote: But the real challenge in the SO question is the 'going back in time' part, which I have trouble to understand : how can you modify x and y through a multiplication and a comparison? I believe this to be possible, though horrible and

Re: [Challenge] implementing the ambiguous operator in D

2010-09-04 Thread Philippe Sigaud
On Sat, Sep 4, 2010 at 01:40, Simen kjaeraas simen.kja...@gmail.com wrote: Simen kjaeraas simen.kja...@gmail.com wrote: I believe this will only work with arrays as input. Either that, or I need a way to make this work: struct Foo( R ) if ( isForwardRange!R ) { bool delegate(

Re: [Challenge] implementing the ambiguous operator in D

2010-09-03 Thread Peter Alexander
== Quote from Nick Sabalausky (a...@a.a)'s article Interesting thing, but devil's advocate: What would be the uses/benefits of that versus just having for each element versions of the operators? Well the obvious benefit is that you don't have to create all those extra version -- you get them

Re: [Challenge] implementing the ambiguous operator in D

2010-09-03 Thread Simen kjaeraas
Philippe Sigaud philippe.sig...@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])

Re: [Challenge] implementing the ambiguous operator in D

2010-09-03 Thread Justin Johansson
On 02/09/10 05:38, Philippe Sigaud 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 It's great to see someone doing the first D discussion topic with the [challenge] annotation.

Re: [Challenge] implementing the ambiguous operator in D

2010-09-03 Thread Peter Alexander
== Quote from Simen kjaeraas (simen.kja...@gmail.com)'s article Yes, very much so. However, Peter Alexander has misunderstood the ambiguous operator. Hey, I was just going by what the guy posted :) He mentioned nothing of tuples, and his examples certainly didn't show any tuples.

Re: [Challenge] implementing the ambiguous operator in D

2010-09-03 Thread Philippe Sigaud
On Fri, Sep 3, 2010 at 19:51, Peter Alexander peter.alexander...@gmail.comwrote: == Quote from Simen kjaeraas (simen.kja...@gmail.com)'s article Yes, very much so. However, Peter Alexander has misunderstood the ambiguous operator. Hey, I was just going by what the guy posted :) He

Re: [Challenge] implementing the ambiguous operator in D

2010-09-03 Thread Philippe Sigaud
On Fri, Sep 3, 2010 at 16:30, Justin Johansson n...@spam.com wrote: On 02/09/10 05:38, Philippe Sigaud 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 It's great to see

Re: [Challenge] implementing the ambiguous operator in D

2010-09-03 Thread Simen kjaeraas
Peter Alexander peter.alexander...@gmail.com wrote: == Quote from Simen kjaeraas (simen.kja...@gmail.com)'s article Yes, very much so. However, Peter Alexander has misunderstood the ambiguous operator. Hey, I was just going by what the guy posted :) He mentioned nothing of tuples, and his

Re: [Challenge] implementing the ambiguous operator in D

2010-09-03 Thread Simen kjaeraas
Philippe Sigaud philippe.sig...@gmail.com wrote: Now, the 'real'/intriguing/mind-bending amb operator (from the 60's) does like the Haskell implementation linked in SO does: backtracking on the results to avoid some condition. If someone is up to the challenge of implementing it in D, great!

Re: [Challenge] implementing the ambiguous operator in D

2010-09-03 Thread Simen kjaeraas
Simen kjaeraas simen.kja...@gmail.com wrote: I believe this will only work with arrays as input. Either that, or I need a way to make this work: struct Foo( R ) if ( isForwardRange!R ) { bool delegate( ElementType!R ) bar; Filter!( bar, R ) range; } Or, well, something like it. I

Re: [Challenge] implementing the ambiguous operator in D

2010-09-02 Thread Pelle
On 09/01/2010 11:49 PM, Peter Alexander wrote: On 1/09/10 9:08 PM, Philippe Sigaud wrote: Peter, can we discuss your solution here? Sure, I'd be interested to hear any improvements. Like I said in my answer, I'm still learning D so I'm sure there's many issues. For example, I made no attempt

Re: [Challenge] implementing the ambiguous operator in D

2010-09-02 Thread Peter Alexander
On 2/09/10 7:34 AM, Pelle wrote: It needs opEquals :-) Yeah, it needs a lot of things :) You could easily add unary operators as well (e.g. so that -amb([1, 2]) == [-1, -2]. I didn't bother adding more than I did because it would make the post too large, and wouldn't really add anything (I

Re: [Challenge] implementing the ambiguous operator in D

2010-09-02 Thread Philippe Sigaud
On Thu, Sep 2, 2010 at 09:06, Peter Alexander peter.alexander...@gmail.comwrote: On 2/09/10 7:34 AM, Pelle wrote: It needs opEquals :-) Yeah, it needs a lot of things :) You could easily add unary operators as well (e.g. so that -amb([1, 2]) == [-1, -2]. I didn't bother adding more than

Re: [Challenge] implementing the ambiguous operator in D

2010-09-02 Thread Nick Sabalausky
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

Re: [Challenge] implementing the ambiguous operator in D

2010-09-02 Thread Nick Sabalausky
Nick Sabalausky a...@a.a wrote in message news:i5p68t$2pt...@digitalmars.com... 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:

[Challenge] implementing the ambiguous operator in D

2010-09-01 Thread Philippe Sigaud
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]) ==

Re: [Challenge] implementing the ambiguous operator in D

2010-09-01 Thread Peter Alexander
On 1/09/10 9:08 PM, Philippe Sigaud wrote: Peter, can we discuss your solution here? Sure, I'd be interested to hear any improvements. Like I said in my answer, I'm still learning D so I'm sure there's many issues. For example, I made no attempt for const-correctness or anything like that