On Monday, 8. November 2010 17:20:43 Jon Lang wrote: > Solomon Foster wrote: > > Well, hyperoperators work fine on Hashes, they operate on the values, > > paired up by key if needed. (That is, %hash>>++ doesn't care about > > the keys, %hash1 >>+<< %hash2 sums based on keys.) I would assume > > that Bag should work in the exact same way. Dunno how Set should work > > in this context, though. > > I would hope that Bags would not work the same way. If they do, then > you get things like: > > Bag(1, 3, 2, 1) >>+<< Bag(2, 3, 1, 2) # same as Bag(1, 1, 1, 2, 2, 2, > 3, 3)
Hyper-plus is not Bag-union. If there is a result at all I would expect Bag(2, 6, 4, 2) because for every element in order on the left there exists the same element on the right and vice versa. The four results of addition are collected into a new Bag. But this fails in other cases: Bag(1,2,3) >>+<< (Bag(4,5,6) has at least the same number of elemnts on both sides but an undefined pairing. The proper set operators are either some Unicode characters or IIRC an operator with parens: Bag(1, 3, 2, 1) (+) Bag(2, 3, 1, 2) or better (&). I'm generally very happy with the choice of sigil for Sets and Bags because this is what they are: scalars as far as storage is concerned. More important is to have the right set of operators that automatically imply Bags: (1,2,3,4) (&) (2,3) === Bag(1,2,2,3,3,4). Arrays and Hashes are about storage. In the abstract the memory of a computer is one big array! Sets and Bags are about operations on them like the numeric operations are on numbers or the string operators on strings. So it is very important to keep the domains nicely separated by means of disjoint operators. This is why we have ~ for concatenation and not overloaded +. It makes of course sense to iterate a Bag. But indexing it doesn't. We are also not indexing into strings: "blah"[2] is not 'a'. Regards, TSa. -- "The unavoidable price of reliability is simplicity" -- C.A.R. Hoare "Simplicity does not precede complexity, but follows it." -- A.J. Perlis 1 + 2 + 3 + 4 + ... = -1/12 -- Srinivasa Ramanujan