Any solutions to Ruby's inconsistencies?

Hmm, let me think about that method name... you are "mapping" a set of
things into another set (I'm using "set" for a simple group of
things); "collect" makes much less sense to me. What exactly are you
collecting? Probably just vernacular used in CS circles that I'm not
aware of, but silly nonetheless.

Todd

···

On Thu, Mar 5, 2009 at 10:52 AM, C. Dagnon <c-soc-rubyforum@dagnon.net> wrote:

Interesting... I hadn't learned about the *ect's. I have used collect
(never map, yuck),

Collect makes much more sense to me than map as I'm collecting a bunch of results and storing them in an array. But the great thing about Ruby is that whichever makes sense, you can use it - and if neither makes sense you can add your own alias :slight_smile:

Ellie

Eleanor McHugh
Games With Brains
http://slides.games-with-brains.net

···

On 5 Mar 2009, at 20:40, Todd Benson wrote:

On Thu, Mar 5, 2009 at 10:52 AM, C. Dagnon <c-soc- > rubyforum@dagnon.net> wrote:

Interesting... I hadn't learned about the *ect's. I have used collect
(never map, yuck),

Hmm, let me think about that method name... you are "mapping" a set of
things into another set (I'm using "set" for a simple group of
things); "collect" makes much less sense to me. What exactly are you
collecting? Probably just vernacular used in CS circles that I'm not
aware of, but silly nonetheless.

----
raise ArgumentError unless @reality.responds_to? :reason

Todd Benson wrote:

Interesting... I hadn't learned about the *ect's. I have used collect
(never map, yuck),

Hmm, let me think about that method name... you are "mapping" a set of
things into another set (I'm using "set" for a simple group of
things); "collect" makes much less sense to me. What exactly are you
collecting? Probably just vernacular used in CS circles that I'm not
aware of, but silly nonetheless.

I suspect it is from Common Lisp's loop:

  (loop for i from 1 to 3 collect (* i i))
  ==> (1 4 9)

You can do a bazillion different things inside a CL loop; collecting
results is just one of them. The loop terminology doesn't really fit
here.

I prefer 'map' since that is the name for the operation in other
languages (including Lisp).

···

On Thu, Mar 5, 2009 at 10:52 AM, C. Dagnon <c-soc-rubyforum@dagnon.net> > wrote:

--
Posted via http://www.ruby-forum.com/\.

Agreed. But you are collecting a collection, which seems inane and
illogical to me. You are, however, absolutely right about the
fascinating flexibility of Ruby (though sometimes that thought is
coupled with deplorable distain of an old codger for excessive use :slight_smile:
Actually, I'm not an old codger, but I do come from old-school DB
design, so I guess that counts. I also come from a math background,
so "map" and "transform" were common terms, never the verb "collect";
not even in engineering or physics. You don't "collect" a group of
things. They are already collected. That would be sort of like using
the verb "gather".

Todd

···

On Thu, Mar 5, 2009 at 3:24 PM, Eleanor McHugh <eleanor@games-with-brains.com> wrote:

On 5 Mar 2009, at 20:40, Todd Benson wrote:

On Thu, Mar 5, 2009 at 10:52 AM, C. Dagnon <c-soc-rubyforum@dagnon.net> >> wrote:

Interesting... I hadn't learned about the *ect's. I have used collect
(never map, yuck),

Hmm, let me think about that method name... you are "mapping" a set of
things into another set (I'm using "set" for a simple group of
things); "collect" makes much less sense to me. What exactly are you
collecting? Probably just vernacular used in CS circles that I'm not
aware of, but silly nonetheless.

Collect makes much more sense to me than map as I'm collecting a bunch of
results and storing them in an array. But the great thing about Ruby is that
whichever makes sense, you can use it - and if neither makes sense you can
add your own alias :slight_smile:

Eleanor McHugh wrote:

Collect makes much more sense to me than map as I'm collecting a bunch
of results and storing them in an array.

You're describing #select....

···

--
Posted via http://www.ruby-forum.com/\.

You are iterating the array visiting the elements one by one,
transforming each by the block, and stuffing the results into another
array. If that is not collecting the results of the transformation I
don't know what would be collecting things then.

Thanks

Michal

···

2009/3/5 Todd Benson <caduceass@gmail.com>:

Agreed. But you are collecting a collection, which seems inane and
illogical to me. You are, however, absolutely right about the
fascinating flexibility of Ruby (though sometimes that thought is
coupled with deplorable distain of an old codger for excessive use :slight_smile:
Actually, I'm not an old codger, but I do come from old-school DB
design, so I guess that counts. I also come from a math background,
so "map" and "transform" were common terms, never the verb "collect";
not even in engineering or physics. You don't "collect" a group of
things. They are already collected. That would be sort of like using
the verb "gather".

Actually the description is sufficiently generic to be valid for both select and collect. With select obviously the results will be a subset of the enumerator contents whereas with collect it will be a transformed copy of the enumerator contents, but in both cases I'll have a new array containing a set of results harvested from the original enumerator.

Ellie

Eleanor McHugh
Games With Brains
http://slides.games-with-brains.net

···

On 6 Mar 2009, at 12:28, Albert Schlef wrote:

Eleanor McHugh wrote:

Collect makes much more sense to me than map as I'm collecting a bunch
of results and storing them in an array.

You're describing #select....

----
raise ArgumentError unless @reality.responds_to? :reason

I knew that someone would pipe in that we are collecting objects and
not transforming them, but you still have a left-hand assignment
dependency unless you use "!"; either way, you are collecting _all_ of
them (well, that is if you don't do some block-internal trickery). To
me, "collect", "grab", "gather", "prune", are all lexically equivalent
to "select". In the current case, it's like saying I want to collect
a flock of sheep, when that action -- though makes sense when
physically grabbing them -- has nothing to do with the use in the
programming language.

Anyways, like Eleanor mentioned, Ruby gives you the power to say, for
example... flock_1.sheer... if you are going to sheer flock_1, and
renders the actual map vs. collect argument a little bit moot. I
suppose it really depends on your use of the language and what team
language standards you have set down.

I like #map because I see in my mind a->b, even though the a into b
doesn't have to be one to one. Like I said earlier; I think this is
an artifact of CS thinking. #map is easier to type too.

To each his or her own :slight_smile:

Todd

···

On Fri, Mar 6, 2009 at 5:10 AM, Michal Suchanek <hramrach@centrum.cz> wrote:

You are iterating the array visiting the elements one by one,
transforming each by the block, and stuffing the results into another
array. If that is not collecting the results of the transformation I
don't know what would be collecting things then.

Michal Suchanek wrote:

You are iterating the array visiting the elements one by one,
transforming each by the block, and stuffing the results into another
array. If that is not collecting the results of the transformation I
don't know what would be collecting things then.

Again I would submit that this is the Lisp way of thinking about it, as
I showed in the example I gave, which is I guess where the 'collect'
term comes from. In Lisp you loop over something (or several things)
and optionally collect results as a side-effect of the loop.

But often you apply a function which maps one set to another, that is,
Enumerable#map. The term 'map' is common in mathematics and in many
programming languages. Even Lisp uses 'map' when that the explicit
operation (and not a loop side-effect).

It is also helpful to recognize that if you were born in India you are
more likely to watch Cricket instead of Baseball. In other words,
cultural preferences are not absolute. If from the beginning ruby had
'map' but not the 'collect' synonym, there is no reason to believe that
you would find this situation unusual.

···

2009/3/5 Todd Benson <caduceass@gmail.com>:

--
Posted via http://www.ruby-forum.com/\.