<br><br><div class="gmail_quote">On Mon, May 27, 2013 at 9:53 PM, H. S. Teoh <span dir="ltr"><<a href="mailto:hsteoh@quickfur.ath.cx" target="_blank">hsteoh@quickfur.ath.cx</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="im">On Mon, May 27, 2013 at 09:24:28PM -0700, Timothee Cour wrote:<br>
> > Done, turns out the fix was trivial, just swapping two static ifs:<br>
> > <a href="https://github.com/D-Programming-Language/phobos/pull/1314" target="_blank">https://github.com/D-Programming-Language/phobos/pull/1314</a><br>
><br>
> This isn't what Andrei had in mind in his post above:<br>
><br>
> > I'm disappointed cartesianProduct works that way; I should have<br>
> > caught that during the code review. A better iteration order would<br>
> > have spanned the lower position in both ranges first, i.e. create<br>
> > squares of increasing side in the 2D space.<br>
><br>
> I would suggest an additional template parameter to specify the order<br>
> of iteration:<br>
</div>[...]<br>
<br>
The problem with allowing the user to specify order is that when one or<br>
more of the input ranges are infinite, the order of traversal is much<br>
less flexible, and it may not be possible to satisfy the requested<br>
order.<br></blockquote><div><br></div><div>Explicit is better than implicit. The user should request the order, and the compiler can statically disallow <span style="font-size:13px;color:rgb(34,34,34);font-family:arial,sans-serif;background-color:rgb(255,255,255)">lexicographic_</span><span style="font-size:13px;color:rgb(34,34,34);font-family:arial,sans-serif;background-color:rgb(255,255,255)">depth/anti</span><span style="font-size:13px;color:rgb(34,34,34);font-family:arial,sans-serif;background-color:rgb(255,255,255)">lexicographic_</span><span style="font-size:13px;color:rgb(34,34,34);font-family:arial,sans-serif;background-color:rgb(255,255,255)">depth when at least one of the ranges is infinite. </span></div>
<div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
The order that Andrei suggested is what's currently used for two<br>
infinite ranges, though when finite ranges are involved I chose a<br>
slightly simpler implementation. The order bearophile proposed in issue<br>
9878 is different from what Andrei describes, at any rate.<br>
<br>
What's the typical output order of cartesian products in other languages<br>
/ libraries? It seems nobody can agree on what the order should be. :-/<br>
<span class="HOEnZb"><font color="#888888"><br></font></span></blockquote><div><br></div><div>python uses itertools.product which is lexicographic_depth.</div><div>Like you say, no-one can agrees what the order should be, so let's leave it up to user through a template. Sounds like a no-brainer to me. There are use cases for each order I mentioned.</div>
<div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="HOEnZb"><font color="#888888">
<br>
T<br>
<br>
--<br>
People demand freedom of speech to make up for the freedom of thought<br>
which they avoid. -- Soren Aabye Kierkegaard (1813-1855)<br>
</font></span></blockquote></div><br>