"benny" <linux / marcrenearns.de> schrieb im Newsbeitrag
news:20040127180844.0b670068 / bava.ho...
> Am Wed, 28 Jan 2004 01:39:01 +0900
> schrieb ts <decoux / moulon.inra.fr>:
>
> > >>>>> "H" == Hal Fulton <hal9000 / hypermetrics.com> writes:
> >
> > H> In other words, I expect + to be commutative always. But probably
> > H> someone will now show me a case where it is not in Ruby.  :)
> >
> >   ruby -e 'p [1]+[2]==[2]+[1]'
> >
> >
> > Guy Decoux
> >
> >
> >
> >
> >
>
> conclusion: no argument against "<<" / "+" for hashs?

No.  Arguments are:

"+" is inefficient. (same for "-")

"<<" has usually the semantics that the left side is a collection while
the right side is an element.  And since each entry in a Hash needs a key
value pair this could not be done with <<, because "<<" can only have a
single argument.  You could only implement << in a way that "h << [key,
value]" would add the pair (key, value), but this is by no means clearer
than "h[key] = value" IMHO.

see Array: [1]<<[2] yields [1,[2]] and not [1,2]

> and "delete" is even more obscure when we have "-" : e.g.
>
> testhash = {"key" => "value", "other key" => "other entry"}
> otherhash = {"other key" => "other entry"}
>

Again, this is not symmetric with other occurences of "-": left and right
side should be of the same type, at least both should be containers, i.e.
hashes in this case.

> testhash - "key" #->  {"other key" => "other entry"}
>
> # should delete the entry with the key "key"
>
> testhash - otherhash #-> {}
>
> # should delete the corresponding entry as well

What should it do if the Hash contains Hashes as keys?  This is highly
ambiguous and not intuitive.

> I think this is far more intuitive and flexible

Regards

    robert