On 10/20/06, Yukihiro Matsumoto <matz / ruby-lang.org> wrote:
> Hi,
>
> In message "Re: String not enumerable, what about IO? (was Re: Symbol < String in Ruby > 1.8)"
>     on Fri, 20 Oct 2006 20:49:47 +0900, Jim Weirich <jim / weirichhouse.org> writes:
>
> |I don't see how an enumerator is any less a "thing" than anything else.
>
> I think he assumes a "thins" should be more array-like than an
> enumerator.  Understandable.  I have a vague plan to create something
> more array-like (but lazy like generators) and make Enumerable#map
> etc. to return "that something".  It would have (almost) all the
> methods in Array.  If String#line would give us that something, David
> would not complain, I guess.
>
> The points left:
>
>   * the current behavior of Enumerable methods to give enumerators if
>     they don't have blocks given.  it was introduced when enumerators
>     were made built-in.  I need to check the discussion of the time.
>
>   * the name of that something.

  Maybe IndexedEnumerator?

  It might be tricky to make this completely Array like. While [] is
probably not too much of a problem, I'm not sure about the wisdom of
[]=().  Some though needs to be given as to whether an Enumerator or
IndexedEnumerator is appropriate in various circumstances.

    [1, 2, 3].each
    (1..3).each
    {:un => 1, :deux =2}.each
    {:un => 1, :deux =2}.each_key
    {:un => 1, :deux =2}.each_value
     File.open('/a/b').each
     File.open('/dev/random').each_byte

Now an observation, since Enumerator mixes in Enumeration, I think
that without changing the current 1.9, someone who want's an array of
lines can do:

   str.lines.to_a[0]
or
    IO.read(file).lines.to_a[3256]

Now some unvarnished opinion coming from someone steeped in Smalltalk,
and one of the X3J20 Smalltalk "language lawyers".   I'm presenting my
background and credentials, not to lend credence to my beliefs, but to
put my opinions in perspective.  Ruby is not Smalltalk, although
Smalltalk can (and already does seem to) provide useful background to
the evolution of Ruby.

One of the things which has bothered me slightly about Ruby is that
there seem to be quite a few cases where methods jump too quickly to
returning an Array.  Some of this is because it seems to make an early
decision to trade space for potential speed, although this might in
some use cases (like iterating over a large file) not be the best
optimization.

In Ruby, Array seems to be the basic conception of a collection, and
Ruby has relatively few classes representing collections.  Array in
Ruby feels like me to be a kind of "Swiss-Army Collection." This is a
bit different from Smalltalk which has quite a collection of
Collections.

One of the things I like about the new feature of the each like
methods is that it shows, what seems to me, to be a more mature view
that Collection-ness is not the same as Array-ness.

-- 
Rick DeNatale

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