------ 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 <<a href ailto:dblack / rubypal.com">dblack / rubypal.com</a>> wrote:<br><div class mail_quote"><blockquote class mail_quote" styleorder-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"> Hi --<div><div></div><div class j3C7c"><br> <br> On Tue, 3 Jun 2008, Yukihiro Matsumoto wrote:<br> <br> <blockquote class mail_quote" styleorder-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"> Hi,<br> <br> In message "Re: Set#map! vs. map"<br> on Tue, 3 Jun 2008 10:13:07 +0900, "David A. Black" <<a href ailto:dblack / rubypal.com" target blank">dblack / rubypal.com</a>> writes:<br> <br> |I'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'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? If so, what do you think collect<br> (currently map's alias) should return?<br> </blockquote> <br></div></div> I wasn't thinking of a general rule, just wondering about the case of<br> Set.</blockquote><div><br>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.<br> <br>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.<br> </div></div><br clear ll"><br>-- <br>Rick DeNatale<br><br>My blog on Ruby<br><a href ttp://talklikeaduck.denhaven2.com/">http://talklikeaduck.denhaven2.com/</a> ------ art_1791_24596073.1212495564171--