From: Robert Dober Date: 2006-07-21T21:27:24+09:00 Subject: Re: opacity of magic enumerator (was: Re: Using .each with constructors) ------=_Part_114954_4281422.1153484840785 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: quoted-printable Content-Disposition: inline On 7/21/06, dblack@wobblini.net wrote: > > Hi -- > > On Fri, 21 Jul 2006, Martin DeMello wrote: > > > On 7/21/06, dblack@wobblini.net wrote: > > > >> On Fri, 21 Jul 2006, Logan Capaldo wrote: > >> > > >> > irb(main):001:0> RUBY_VERSION > >> > =3D> "1.9.0" > >> > irb(main):002:0> a, b, c =3D 3.times.map { Object.new } > >> > =3D> [#, #, #] > >> > >> Interesting.... That reveals that one of the problems with this magic > >> enumerator thing is that the method names weren't necessarily chosen > >> with this in mind, and don't work very well. 3.times.map very > >> strongly does *not* communicate a 0...3 mapping to me. My first > > > > If you think about it, though, the underlying problem is that 3.times > > passes a parameter into the block, which is what makes 3.times.map > > {|i| } nonintuitive. The plain 3.times.map {} doesn't suggest a 0...3 > > mapping, but rather an enumerator consisting of three "passes" which > > map naturally turns into a 3-object array. > > I'm not getting the "naturally" part :-) I mean, of course it's all > non-natural in a sense, but I just can't seem to get my brain to > perceive 3.times as returning something that responds to map this way. > > Maybe part of the problem is that it suggests an equivalence between: > > [0,1,2].map {} > > and > > 3.times.map {} I completely agree, we could easily monkeypatch Fixnum to deliver 3.numbers =3D> [0, 1, 2] or 3.numbers( :starting =3D> 2 ) [2, 3, 4 ] or 3.numbers( :interval =3D> 42 ) =3D> [0, 42, 2*42 ] I do not like the name, but maybe someone has a better idea? Cheers Robert which makes it seem like 3.times is return an array. Or something. I > don't even know exactly; it just reads very badly to me. > > > I predict that this *will* seem intuitive once magic enumerators > > have been around a while - note that it already reads perfectly as > > 3.times.collect > > I think that if something has to be around for a while to be > comprehensible, it loses the "intuitive" badge :-) I'm sure that > eventually the process of mentally translating it will get faster.... > I guess I'm just used to Ruby semantics not having big gaps, and for > me, there's a big gap between "3.times.map" and mapping across 0,1,2. > (I'm not sure about your .collect point; to me that suffers from > exactly the same problem.) > > I'm also still troubled by the rather wide net cast by magic > enumerators. I don't think anyone came up with an answer to my > earlier question: When would you ever need this: > > some_enumerable.map.other_method > > ? If the answer is "never", then I don't think map should return an > enumerator. > > > David > > -- > http://www.rubypowerandlight.com =3D> Ruby/Rails training & consultancy > http://www.manning.com/black =3D> RUBY FOR RAILS (reviewed on > Slashdot, 7/12/2006!) > http://dablog.rubypal.com =3D> D[avid ]A[. ]B[lack's][ Web]log > dblack@wobblini.net =3D> me > > --=20 Deux choses sont infinies : l'univers et la b=EAtise humaine ; en ce qui concerne l'univers, je n'en ai pas acquis la certitude absolue. - Albert Einstein ------=_Part_114954_4281422.1153484840785--