Enumerable#to_set bug?

Hi, folks. Is this a bug?

irb(main):001:0> require ‘set’
=> true
irb(main):002:0> a = [1,2,3].to_set
=> #<Set: {1, 2, 3}>
irb(main):003:0> b = a.dup
=> #<Set: {1, 2, 3}>
irb(main):004:0> a == b
=> true
irb(main):005:0> [a,b].to_set
=> #<Set: {#<Set: {1, 2, 3}>, #<Set: {1, 2, 3}>}>

Thanks,
prs

Hi,

At Sat, 24 Apr 2004 11:19:05 +0900,
anon luker wrote in [ruby-talk:98188]:

Hi, folks. Is this a bug?

I don’t think so, since Set is a container class.

irb(main):001:0> require ‘set’
=> true
irb(main):002:0> a = [1,2,3].to_set
=> #<Set: {1, 2, 3}>
irb(main):003:0> b = a.dup
=> #<Set: {1, 2, 3}>
irb(main):004:0> a == b
=> true
irb(main):005:0> [a,b].to_set
=> #<Set: {#<Set: {1, 2, 3}>, #<Set: {1, 2, 3}>}>

What happens when you add 4 to a, if it were reduced?

···


Nobu Nakada

“anon luker” hatespyware@yahoo.com schrieb im Newsbeitrag
news:534d31a2.0404231815.69fd8659@posting.google.com

Hi, folks. Is this a bug?

irb(main):001:0> require ‘set’
=> true
irb(main):002:0> a = [1,2,3].to_set
=> #<Set: {1, 2, 3}>
irb(main):003:0> b = a.dup
=> #<Set: {1, 2, 3}>
irb(main):004:0> a == b
=> true
irb(main):005:0> [a,b].to_set
=> #<Set: {#<Set: {1, 2, 3}>, #<Set: {1, 2, 3}>}>

irb(main):008:0> a.eql? b
=> false

although

irb(main):009:0> a.to_a.eql?( b.to_a )
=> true

So maybe Set#eql? should be changed.

robert

“Robert Klemme” bob.news@gmx.net wrote in message news:c6dbnj$atac0$1@ID-52924.news.uni-berlin.de

“anon luker” hatespyware@yahoo.com schrieb im Newsbeitrag
news:534d31a2.0404231815.69fd8659@posting.google.com

Is this a bug?

require ‘set’
a = [1,2,3].to_set
b = a.dup
a == b => true
[a,b].to_set
=> #<Set: {#<Set: {1, 2, 3}>, #<Set: {1, 2, 3}>}>

a.eql? b
=> false
although
a.to_a.eql?( b.to_a )
=> true
So maybe Set#eql? should be changed.
robert

Thanks for a good observation, Robert. As it is, set seems utterly worthless to me.

Robert Klemme wrote:

irb(main):009:0> a.to_a.eql?( b.to_a )
=> true

So maybe Set#eql? should be changed.

robert

Check out the thread after the set classed was checked
was included as a standard library [ruby-core:423] -
in particular [ruby-core:423]. I tend to think that is
a toss up up between the current efficient Set#eql?
implementation (actually I wondering why Set#eql? and
Set#hash are overridden at all) and the mathematically
correct

class Set
alias :eql? :==
end

implementation (in tandem with appropriated Set#hash).
I have more definite opinion on current Set#<=> semantic,
which was adopted from an earlier Set class in
RubyCollections download | SourceForge.net. The latter
strikes me as barely useful maybe even counterproductive.
(Incidentally in Jason’s in Set implementation we have
Set#eql? == Set#==).

/Christoph