Cartesian products? [Especially wrt iterations]
I apologize in advance for posting yet another suggestion without having full knowledge of all apocalypses, and I fear (for a very positive meaning of fear) that the answer will be: but that is already available. Well, the point is that I wonder wether Perl6 will support cartesian products between lists, i.e. an infix operator that will return a list of arrayrefs containing ordered pairs from the originating lists. Now, one possible difficulty with such an operator would be wrt what to do with applying it twice or even more times. One would reasonably want it to be associative in the obvious sense, but this won't happen (because mathematically speaking (AxA)xA and Ax(AxA) are associative only up to a *natural* isomorphism, which doesn't make much difference, mathematically speaking, but indeed it does in a computer programming context). However I already know that I'll be told that I can cook up something like that myself. But to be fair I think that the context in which such a beast would be most useful would be that of iterating over multiple variables, so one (well, I for one!) could be content with a special syntax for that, instead. Put more clearly, it is now common to see things like: for my $x (1..10) { for my $y (5..20) { for my $text (qw/foo bar baz/) { do_stgh_with $x, $y, $text; } } } and it would be very much in the phylosophy of Perl to allow for a very concise syntax to obtain the same effect. I am aware of the zip operator, but AFAICT it solves an equally common but completely different problem... Michele -- The amount of repetition repetition isn't that great. - Ignacy Sawicki in comp.text.tex thread Bug in FeynMF's Queues?
Re: Cartesian products? [Especially wrt iterations]
On Tue, 13 Jul 2004, Austin Hastings wrote: Using google(+perl6 +cartesian product) would have led you to the conclusion that this is already included. I hope this is horribly wrong, since the syntax is a little bewildering. [...] See Luke Palmer's Outer product considered useful post: http://www.mail-archive.com/[EMAIL PROTECTED]/msg15513.html That's exactly the point! I wish too there were a more intuitive syntax, possibly even employing a predefined array variable if none is explicitly specified... On Tue, 13 Jul 2004, Jonathan Scott Duff wrote: and it would be very much in the phylosophy of Perl to allow for a very concise syntax to obtain the same effect. I am aware of the zip operator, but AFAICT it solves an equally common but completely different problem... Are you sure? for zip(1..10, 5..20, foo bar baz) - $x, $y, $text { do_something_with $x,$y,$text; } Not sure at all: admittedly I may well be one of the less informed ones about Perl6 here. Though as far as I can understand zip() is for iterating *in parallel*, and both other replies here and discussion previously held here seem to indicate that it is so. Michele -- Una gran americanata quello della cottura dell'Hot-dog con i gas di scarico della turbina Una strunzata in piu' tanto gia' mangiano delle schifezze in piu' condite con kerosene... - Natale Novello su it.hobby.modellismo, Re: Video spettacolare in volo
Re: Cartesian products? [Especially wrt iterations]
Jonathan Scott Duff writes: On Tue, Jul 13, 2004 at 03:31:57PM +0200, Michele Dondi wrote: Put more clearly, it is now common to see things like: for my $x (1..10) { for my $y (5..20) { for my $text (qw/foo bar baz/) { do_stgh_with $x, $y, $text; } } } and it would be very much in the phylosophy of Perl to allow for a very concise syntax to obtain the same effect. I am aware of the zip operator, but AFAICT it solves an equally common but completely different problem... Are you sure? for zip(1..10, 5..20, foo bar baz) - $x, $y, $text { do_something_with $x,$y,$text; } That does a different thing entirely. Allow me to demonstrate, using Couter that I proposed: for zip(1..3, 4..6) - $x, $y { say $x,$y; } 1,4 2,5 3,6 for outer(1..3, 4..6) - $x, $y { say $x,$y; } 1,4 1,5 1,6 2,4 2,5 2,6 3,4 3,5 3,6 The essential difference between the lists that zip and outer generate is the essential difference between the outer and inner products. outer expands an index while zip collapses an index. Note also that all arguments to zip ought to be the same length (and if not, they are finessed into bein g so), where this restriction desn't apply to outer. Luke
Re: Cartesian products? [Especially wrt iterations]
--- Michele Dondi [EMAIL PROTECTED] wrote: On Tue, 13 Jul 2004, Austin Hastings wrote: Using google(+perl6 +cartesian product) would have led you to the conclusion that this is already included. I hope this is horribly wrong, since the syntax is a little bewildering. [...] See Luke Palmer's Outer product considered useful post: http://www.mail-archive.com/[EMAIL PROTECTED]/msg15513.html That's exactly the point! I wish too there were a more intuitive syntax, possibly even employing a predefined array variable if none is explicitly specified... Boggle! While Couter may not be totally intuitive, it's not far off. Likewise, the latin-1 version is pretty good: for @x × @y × @z - $x, $y, $z { ... } Is there some even more intuitive way than this? On Tue, 13 Jul 2004, Jonathan Scott Duff wrote: Are you sure? for zip(1..10, 5..20, foo bar baz) - $x, $y, $text { do_something_with $x,$y,$text; } Not sure at all: admittedly I may well be one of the less informed ones about Perl6 here. Though as far as I can understand zip() is for iterating *in parallel*, and both other replies here and discussion previously held here seem to indicate that it is so. No, ¥ (Czip) is wrong for this. (It's the inner product, so it really ought to be '·' (Cinner) except for the wierd origin.) =Austin
Re: Cartesian products? [Especially wrt iterations]
Luke Palmer skribis 2004-07-13 10:28 (-0600): for outer(1..3, 4..6) - $x, $y { say $x,$y; } 1,4 1,5 1,6 2,4 2,5 2,6 3,4 3,5 3,6 So outer is somewhat like {} in shell globs? perl -le'print for glob {1,2,3},{4,5,6}' Juerd