(unknown)

#!/usr/bin/ruby

···

#
# try003.rb
#
# Here is my bug. It turns out it's not as whacky as I though. It just
# was failing because Ruby cannot sort booleans; presumably an omission:

b = [false,true,false,true]

# Sorry about this omission the first time: Version was ruby 1.8.1 on CentOS
# Linux.
b.sort.each do |bool|
  p bool
end

What is bigger, a true or a false? One might argue that the truth is
the biggest thing, on the other hand its nearly always the case that a
lie needs much more effort than the truth. So what to do? false < true
or true < false or true == false?

Now to help you

irb(main):002:0> def false.<=>(o) o ? -1 : 0 end
=> nil
irb(main):003:0> def true.<=>(o) !o ? 1 : 0 end
=> nil
irb(main):004:0> [true, false, true, false, false].sort
=> [false, false, false, true, true]

regards,

Brian

···

On 19/10/05, Xeno Campanoli <xeno@eskimo.com> wrote:

#!/usr/bin/ruby
#
# try003.rb
#
# Here is my bug. It turns out it's not as whacky as I though. It just
# was failing because Ruby cannot sort booleans; presumably an omission:

b = [false,true,false,true]

# Sorry about this omission the first time: Version was ruby 1.8.1 on CentOS
# Linux.
b.sort.each do |bool|
        p bool
end

--
http://ruby.brian-schroeder.de/

Stringed instrument chords: http://chordlist.brian-schroeder.de/

Hi,

···

In message "Re: " on Thu, 20 Oct 2005 02:50:03 +0900, Xeno Campanoli <xeno@eskimo.com> writes:

# Here is my bug. It turns out it's not as whacky as I though. It just
# was failing because Ruby cannot sort booleans; presumably an omission:

Sorting is to reorder items according to their value order. How can
booleans can be sorted? Is there any order between true and false?
Which is bigger, in that case?

              matz.

Hi!

Besides, why would you want to sort on only two values ?

Is that you want to output all females before males or something similar.

Regards
JC

···

--- Yukihiro Matsumoto <matz@ruby-lang.org> wrote:

Hi,

In message "Re: " > on Thu, 20 Oct 2005 02:50:03 +0900, Xeno Campanoli <xeno@eskimo.com> writes:

># Here is my bug. It turns out it's not as whacky as I though. It just
># was failing because Ruby cannot sort booleans; presumably an omission:

Sorting is to reorder items according to their value order. How can
booleans can be sorted? Is there any order between true and false?
Which is bigger, in that case?

              matz.

__________________________________
Yahoo! Music Unlimited
Access over 1 million songs. Try it free.
http://music.yahoo.com/unlimited/

Another perspective is sorting is to bunch things into realms of like value.

That being said, it wasn't hard once I realized the problem to just use 1 and 0.

As far as which is bigger, I'd go with the concept that truth is like existence, and falsehood is like non-existence, and then to assume whole numbers as is done elsewhere in things like this and say that something is bigger than nothing.

Thank you, by the way, for answering me in person.

Best wishes.

Sincerely, Xeno

Yukihiro Matsumoto wrote:

···

Hi,

In message "Re: " > on Thu, 20 Oct 2005 02:50:03 +0900, Xeno Campanoli <xeno@eskimo.com> writes:

# Here is my bug. It turns out it's not as whacky as I though. It just
# was failing because Ruby cannot sort booleans; presumably an omission:

Sorting is to reorder items according to their value order. How can
booleans can be sorted? Is there any order between true and false?
Which is bigger, in that case?

            matz.

--
Xeno Campanoli: http://www.eskimo.com/~xeno
The real disaster is ANY TIME WE GET A BUSH FOR PRESIDENT!

Oh, one other excuse for wanting this:

I'm a firm believer in things working in parallel. If you can define an array of things indexed as truth or false, it should work, and if it works, you should be able to sort it.

That being said, I wouldn't mind that much a functionality that didn't let you define such a thing either.

xc

Xeno Campanoli wrote:

···

Another perspective is sorting is to bunch things into realms of like value.
That being said, it wasn't hard once I realized the problem to just use 1 and 0.
As far as which is bigger, I'd go with the concept that truth is like existence, and falsehood is like non-existence, and then to assume whole numbers as is done elsewhere in things like this and say that something is bigger than nothing.

Thank you, by the way, for answering me in person.

Best wishes.

Sincerely, Xeno

Yukihiro Matsumoto wrote:

Hi,

In message "Re: " >> on Thu, 20 Oct 2005 02:50:03 +0900, Xeno Campanoli >> <xeno@eskimo.com> writes:

># Here is my bug. It turns out it's not as whacky as I though. It just
># was failing because Ruby cannot sort booleans; presumably an omission:

Sorting is to reorder items according to their value order. How can
booleans can be sorted? Is there any order between true and false?
Which is bigger, in that case?

                            matz.

--
Xeno Campanoli: http://www.eskimo.com/~xeno
The real disaster is ANY TIME WE GET A BUSH FOR PRESIDENT!