------art_1791_24596073.1212495564171
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

On Tue, Jun 3, 2008 at 4:33 AM, David A. Black <dblack / rubypal.com> wrote:

> Hi --
>
>
> On Tue, 3 Jun 2008, Yukihiro Matsumoto wrote:
>
>  Hi,
>>
>> In message "Re: Set#map! vs. map"
>>   on Tue, 3 Jun 2008 10:13:07 +0900, "David A. Black" <dblack / rubypal.com>
>> writes:
>>
>> |I'm just wondering whether it would make more sense for Set to have a
>> |#map method that returned a set, rather than an array, as long as that
>> |behavior is considered meaningful (as it appears to be since that's
>> |how Set#map! is working). Otherwise that aspect of the map/map!
>> |distinction seems kind of arbitrary.
>>
>> Do you want to make a new rule that map should return the object of
>> the same class as the receiver?  If so, what do you think collect
>> (currently map's alias) should return?
>>
>
> I wasn't thinking of a general rule, just wondering about the case of
> Set.


It's probably completely irrelevant to Ruby, but in Smalltalk the collect
method in general returns an instance of the same class as the receiver.
Most collection class implementations of collect use 'self species new' to
instantiate the result, where the species method returns the class to be
used. The general species method is implemented as '^self class', which
means that classes which don't override it will return an instance of their
own class.

However, in contrast to Ruby which uses Array as a kind of
"swiss-army-knife" collection class, with a few specialized collection
classes, Smalltalk has a fairly rich collection of collection classes so it
probably makes more sense for Smalltalk to do what it does.


-- 
Rick DeNatale

My blog on Ruby
http://talklikeaduck.denhaven2.com/

------art_1791_24596073.1212495564171
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

On Tue, Jun 3, 2008 at 4:33 AM, David A. Black &lt;<a hrefailto:dblack / rubypal.com">dblack / rubypal.com</a>&gt; wrote:<br><div classmail_quote"><blockquote classmail_quote" styleorder-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Hi --<div><div></div><div classj3C7c"><br>
<br>
On Tue, 3 Jun 2008, Yukihiro Matsumoto wrote:<br>
<br>
<blockquote classmail_quote" styleorder-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Hi,<br>
<br>
In message &quot;Re: Set#map! vs. map&quot;<br>
 &nbsp; on Tue, 3 Jun 2008 10:13:07 +0900, &quot;David A. Black&quot; &lt;<a hrefailto:dblack / rubypal.com" targetblank">dblack / rubypal.com</a>&gt; writes:<br>
<br>
|I&#39;m just wondering whether it would make more sense for Set to have a<br>
|#map method that returned a set, rather than an array, as long as that<br>
|behavior is considered meaningful (as it appears to be since that&#39;s<br>
|how Set#map! is working). Otherwise that aspect of the map/map!<br>
|distinction seems kind of arbitrary.<br>
<br>
Do you want to make a new rule that map should return the object of<br>
the same class as the receiver? &nbsp;If so, what do you think collect<br>
(currently map&#39;s alias) should return?<br>
</blockquote>
<br></div></div>
I wasn&#39;t thinking of a general rule, just wondering about the case of<br>
Set.</blockquote><div><br>It&#39;s probably completely irrelevant to Ruby, but in Smalltalk the collect method in general returns an instance of the same class as the receiver.&nbsp; Most collection class implementations of collect use &#39;self species new&#39; to instantiate the result, where the species method returns the class to be used. The general species method is implemented as &#39;^self class&#39;, which means that classes which don&#39;t override it will return an instance of their own class.<br>
<br>However, in contrast to Ruby which uses Array as a kind of &quot;swiss-army-knife&quot; collection class, with a few specialized collection classes, Smalltalk has a fairly rich collection of collection classes so it probably makes more sense for Smalltalk to do what it does.<br>
</div></div><br clear
ll"><br>-- <br>Rick DeNatale<br><br>My blog on Ruby<br><a hrefttp://talklikeaduck.denhaven2.com/">http://talklikeaduck.denhaven2.com/</a>

------art_1791_24596073.1212495564171--