Luke Palmer wrote:
On 14 Jun 2005 06:07:10 -0000, David Formosa (aka ? the Platypus)
<[EMAIL PROTECTED]> wrote:

multi sub infix_circumfix_meta_operator:{'>>','<<'} (Hash %a,Hash %b,Code $op) {
       my Hash %return;
       for intersection(keys %a,keys %b) -> $key {
         %return{$key} = $op($a{$key},$b{$key});
       }
       return %return;
}

       Would this be sensible, usefull behavour?


I think so.

In fact, I've implemented "hash vector" and "hash matrix" classes
which are useful for doing various linearesque things, when you don't
know how many elements your vectors will have.  The difference between
the hyper hash ops and vector-vector ops in my class is the fact that
you did intersection instead of union (I assumed unset elements were
0).  Unfortunately, such an assumption doesn't make sense on a general
scale, so I wonder whether I would end up using the hash hyper ops or
whether I'd just go and implement them again.

So, I'd really like to see a couple examples where this behavior could
be useful.  I don't doubt that it can, but I can't think of anything
at the moment.

This is effectively the Database inner vs outer join issue. There are times you need one and times you need the other. Example for the outer join case: combining two invoices where you want to add together the subtotals for each type of item and missing items on either invoice should be assumed to be 0 quantity at 0 dollars. Note that just like in the reduce op you need to know the identity value associated with the op. come to think of it just like in the DB world you really need 4 different versions: inner join (intersection of keys), full outer join (union of keys) and the left and right outer joins where you on consider the missing keys on the left or right sides. This means that the current hyper-op should be define to be one of inner or full and we need some syntax to specify the other three op types. >>-:left<< Ugh!

As a sidenote this would make writing a simple in Perl 6 DB module trivial.


--
[EMAIL PROTECTED]
[EMAIL PROTECTED]

Reply via email to