Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

hyp-op examples of a Bag type in S03

0 views
Skip to first unread message

Darren Duncan

unread,
May 19, 2006, 4:22:32 PM5/19/06
to perl6-l...@perl.org
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

Darren Duncan

unread,
May 19, 2006, 4:25:19 PM5/19/06
to perl6-l...@perl.org
Er, I meant to say "subtracted" where I said "added". -- Darren Duncan

Sam Vilain

unread,
May 23, 2006, 12:11:43 AM5/23/06
to Darren Duncan, perl6-l...@perl.org
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.

Darren Duncan

unread,
May 23, 2006, 1:25:21 AM5/23/06
to perl6-l...@perl.org

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

0 new messages