Re: hyp-op examples of a Bag type in S03
At 4:11 PM +1200 5/23/06, Sam Vilain wrote: Darren Duncan wrote: $bag1 >>-<< 1; # Bag(2,7,[1,Seq(8,2)],7) $bag2 >>-<< (1,1,1,1); # probably the same > $bag3 >>-<< (1,1,2,1); # ? Bag's won't .does(Array) or .does(Coll[Seq,...]), so that hyperoperator won't work - if anything it would try to add the (1,1,1,1) list to all of the elements of the bag. You'd need to put the bag in something that does imply ordering first. This applies to any unordered collection, bags or sets. Sam. Yes, I already assumed that only the first line would absolutely work, and that the third absolutely wouldn't. The second line example I considered borderline, because all of the elements were the same, and the count of elements matched the count in $bag2, so the result is the same no matter which set element each is matched up with. But of course it would be unreasonable for a generic Perl 6 implementation to be expected to intuit such things, so I shouldn't have said "probably the same", if that's specifically what you were replying to. See list post "[svn:perl6-synopsis] r9304 - doc/trunk/design/syn", where Larry corrected S03 in response to my post. Case closed. -- Darren Duncan
Re: hyp-op examples of a Bag type in S03
Darren Duncan wrote: > $bag1 >>-<< 1; # Bag(2,7,[1,Seq(8,2)],7) > $bag2 >>-<< (1,1,1,1); # probably the same > $bag3 >>-<< (1,1,2,1); # ? > > Bag's won't .does(Array) or .does(Coll[Seq,...]), so that hyperoperator won't work - if anything it would try to add the (1,1,1,1) list to all of the elements of the bag. You'd need to put the bag in something that does imply ordering first. This applies to any unordered collection, bags or sets. Sam.
Re: hyp-op examples of a Bag type in S03
Er, I meant to say "subtracted" where I said "added". -- Darren Duncan
hyp-op examples of a Bag type in S03
I know they were just introduced, but I have a question about the conceptual validity of the following statements in S03, which appear in the newly edited hyper-operators section: Bag(3,8,[2,Seq(9,3]],8) >>-<< 1; # Bag(2,7,[1,Seq(8,2)],7) Bag(3,8,[2,Seq(9,3)],8) >>-<< (1,1,1,1); # Bag(2,7,[1,Seq(8,2)],7) Bag(3,8,[2,Seq(9,3)],8) >>-<< (1,1,2,1); # Bag(2,7,[0,Seq(7,1)],7) First of all, my concept of a Bag is that it is like a Set, in that it is an *un-ordered* collection of things, but unlike a Set, each distinct element can appear more than once in a Bag (eg, the '8'). Correct me if you think differently about that. Now, say you phrased the lines above slightly differently, like this: $bag1 = Bag(3,8,[2,Seq(9,3]],8); $bag2 = Bag(3,8,[2,Seq(9,3)],8); $bag3 = Bag(3,8,[2,Seq(9,3)],8); $bag1 >>-<< 1; # Bag(2,7,[1,Seq(8,2)],7) $bag2 >>-<< (1,1,1,1); # probably the same $bag3 >>-<< (1,1,2,1); # ? Now, the $bag1 example is unambiguous; all Bag members are having 1 added to them. But $bag3 does not seem predictable to me. Since a Bag is unordered, how do we know, with the $bag3 example, which elements are having a 2 added to them and which elements are having a 1? The only way that $bag3 could be predictable is if a Bag is ordered. But in that case, how is a Bag different than a Seq? Now, I realize that technically the source code in the actual S03 does display the members of each Bag in a sequence (the sequence they appear in the code itself), but what would that example compile to (would that seq info be lost), and what information would the compiled code carry to associate the values on the left and right hand sides of the hyper-operator? So I would appreciate if the S03 examples could be explained as to why they would work, or alternately please replace 'Bag' with 'Seq'. Thank you. -- Darren Duncan