ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> perl6-language
perl6-language
Re: %hash1 >>...<< %hash2
by Mark A. Biggar other posts by this author
Jun 14 2005 7:19AM messages near this date
Re: %hash1 >>...<< %hash2 | Assigning Proxy objects
Luke Palmer wrote:
>  On 14 Jun 2005 06:07:10 -0000, David Formosa (aka ? the Platypus)
>  <dformosa@[...].au> 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.


-- 
mark@[...].org
mark.a.biggar@comcast.net
Thread:
Luke Palmer
Brent 'Dax' Royal-Gordon
Larry Wall
Mark A. Biggar

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved