Web Images Videos Maps News Shopping Gmail more »
Recently Visited Groups | Help | Sign in
Google Groups Home
why doesn't Array include Comparable
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  8 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
ara.t.how...@noaa.gov  
View profile  
 More options Aug 9 2006, 12:14 am
From: ara.t.how...@noaa.gov
Date: Wed, 9 Aug 2006 13:14:25 +0900
Local: Wed, Aug 9 2006 12:14 am
Subject: why doesn't Array include Comparable

why __wouldn't__ one want this?

   harp:~ > cat a.rb
   a = 0,1,2
   b = 2,3,4

   p a < b rescue puts "can't do that!"

   class Array; include Comparable; end

   p a < b

   harp:~ > ruby a.rb
   can't do that!
   true

??

-a
--
to foster inner awareness, introspection, and reasoning is more efficient than
meditation and prayer.
- h.h. the 14th dali lama


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Hal Fulton  
View profile  
 More options Aug 9 2006, 12:56 am
From: Hal Fulton <hal9...@hypermetrics.com>
Date: Wed, 9 Aug 2006 13:56:39 +0900
Local: Wed, Aug 9 2006 12:56 am
Subject: Re: why doesn't Array include Comparable

Offhand I would guess it's because arrays can
hold arbitrary objects.

If one array held four different classes of
objects, and another held yet another four
classes of objects, that's potentially sixteen
spaceship operators that would need to be
defined for this to make sense. And most of
those would not make sense anyway.

Hal


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Logan Capaldo  
View profile  
 More options Aug 9 2006, 8:22 am
From: Logan Capaldo <logancapa...@gmail.com>
Date: Wed, 9 Aug 2006 21:22:39 +0900
Local: Wed, Aug 9 2006 8:22 am
Subject: Re: why doesn't Array include Comparable

On Aug 9, 2006, at 12:56 AM, Hal Fulton wrote:

But spaceship is already defined for array (and it does the right  
thing (tm)). If Array is going to make spaceship available, why _not_  
include Comparable?


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
James Edward Gray II  
View profile  
 More options Aug 9 2006, 8:51 am
From: James Edward Gray II <ja...@grayproductions.net>
Date: Wed, 9 Aug 2006 21:51:53 +0900
Local: Wed, Aug 9 2006 8:51 am
Subject: Re: why doesn't Array include Comparable
On Aug 9, 2006, at 7:22 AM, Logan Capaldo wrote:

> But spaceship is already defined for array (and it does the right  
> thing (tm)). If Array is going to make spaceship available, why  
> _not_ include Comparable?

I have to agree.  I know I've wanted it a couple of times now.

James Edward Gray II


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Trans  
View profile  
 More options Aug 9 2006, 9:05 am
Newsgroups: comp.lang.ruby
From: "Trans" <transf...@gmail.com>
Date: Wed, 9 Aug 2006 22:05:15 +0900
Local: Wed, Aug 9 2006 9:05 am
Subject: Re: why doesn't Array include Comparable
Indeed I have found it useful to

  class Tuple < Array
    include Comparable
  end

But I also make it immutable.

T.


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
ara.t.how...@noaa.gov  
View profile  
 More options Aug 9 2006, 10:13 am
From: ara.t.how...@noaa.gov
Date: Wed, 9 Aug 2006 23:13:19 +0900
Local: Wed, Aug 9 2006 10:13 am
Subject: Re: why doesn't Array include Comparable

On Wed, 9 Aug 2006, Hal Fulton wrote:
> Offhand I would guess it's because arrays can
> hold arbitrary objects.

> If one array held four different classes of
> objects, and another held yet another four
> classes of objects, that's potentially sixteen
> spaceship operators that would need to be
> defined for this to make sense. And most of
> those would not make sense anyway.

i don't understand - it's up to to the objects inside the container to
impliment the right methods and array already knows how to handle it:

   harp:~ > cat a.rb
   a = 0, 'foo', 42
   b = 1, 'bar', 42.0

   p a < b rescue puts "can't do that"

   class Array; include Comparable; end

   p a < b

   p a.sort_by{ rand } < b.sort_by{ rand }

   harp:~ > ruby a.rb
   can't do that
   true
   a.rb:9:in `<': comparison of Array with Array failed (ArgumentError)
           from a.rb:9

if you're collections impliment <=> correctly then Array does the right thing -
looping over each of them.

-a
--
to foster inner awareness, introspection, and reasoning is more efficient than
meditation and prayer.
- h.h. the 14th dali lama


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
ara.t.how...@noaa.gov  
View profile  
 More options Aug 9 2006, 10:18 am
From: ara.t.how...@noaa.gov
Date: Wed, 9 Aug 2006 23:18:20 +0900
Local: Wed, Aug 9 2006 10:18 am
Subject: Re: why doesn't Array include Comparable

On Wed, 9 Aug 2006, Logan Capaldo wrote:
> But spaceship is already defined for array (and it does the right thing
> (tm)). If Array is going to make spaceship available, why _not_ include
> Comparable?

yeah - exactly.  by implimenting <=> it __is__ comparable in that one can
indeed to

   a = 0,1,2
   b = 2,3,4

   lt = (a <=> b) == -1
   eq = (a <=> b) == 0
   gt = (a <=> b) == 1

so it's just anoying that i can't acutally say

   lt = a < b

2 cts.

-a
--
to foster inner awareness, introspection, and reasoning is more efficient than
meditation and prayer.
- h.h. the 14th dali lama


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Daniel Berger  
View profile  
 More options Aug 9 2006, 10:48 am
From: "Daniel Berger" <Daniel.Ber...@qwest.com>
Date: Wed, 9 Aug 2006 23:48:59 +0900
Local: Wed, Aug 9 2006 10:48 am
Subject: Re: why doesn't Array include Comparable

FWIW, I modified the Array class to include Comparable and then ran both the
test_array.rb file that's distributed with the Ruby distro and my own tests in
the ruby_test project and all tests still passed.

Regards,

Dan

This communication is the property of Qwest and may contain confidential or
privileged information. Unauthorized use of this communication is strictly
prohibited and may be unlawful.  If you have received this communication
in error, please immediately notify the sender by reply e-mail and destroy
all copies of the communication and any attachments.


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2009 Google