On 10/28/05, Darren Duncan <[EMAIL PROTECTED]> wrote:
> One thing I would like to be able to do is this:
>
>    @baz = cross([1,2],[3,4]); # yields ([1,3],[1,4],[2,3],[2,4])
>
> And alternately, this:
>
>    for cross([1,2],[3,4]) -> $foo,$bar { ... } # loop has 4 iterations

I already proposed this in this thread:

http://groups.google.com/group/perl.perl6.language/browse_thread/thread/13f6317f6ca9229d/8046eddc50097a52?lnk=st&q=outer+product+luke+palmer&rnum=1#8046eddc50097a52

Where I called it "outer".  Nowadays, instead of returning arrays, it
probably returns tuples:

    for outer(1,2 ; 3,4) -> :($foo, $bar) {...}

So that it can be well-typed[1].

> On the other hand, perhaps something I actually want is something
> like the hyper-operation but with appropriately different syntax:
>
>    ['a','b'] >>~<< ['c','d']

This was also discussed.  The hot syntax at the time was:

    ('a','b') <<~>> ('c','d')

But we decided against it for a reason I can't recall at the moment.

For this, do:

    map -> :($a, $b) { $a ~ $b } outer(<a b> ; <c d>)

Perhaps this could be written:

    map &infix:<~>, *<<outer(<a b> ; <c d>)

But perhaps not.

Luke

[1] That is, if you had:

    for outer(1,2 ; "foo", "bar") -> :($foo, $bar) {...}

The compiler could be sure that $foo is a Num and $bar is a Str.

Reply via email to