enumerable#to_set bug?

A

anon luker

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
 
N

nobu.nokada

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?
 
R

Robert Klemme

anon luker said:
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
 
A

anon luker

Robert Klemme said:
anon luker said:
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.
 
C

Christoph

Robert said:
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
http://sourceforge.net/projects/rubycollections. The latter
strikes me as barely useful maybe even counterproductive.
(Incidentally in Jason's in Set implementation we have
Set#eql? == Set#==).


/Christoph
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,145
Messages
2,570,825
Members
47,371
Latest member
Brkaa

Latest Threads

Top