[ruby-talk:02391] Re: Iterator into array

From: "Conrad Schneiker" <schneiker@...>
Date: 2000-04-08 05:45:03 UTC
List: ruby-talk #2391
From: Dave Thomas
> Clemens Hintze <c.hintze@gmx.net> writes:
>
> > But I could not imagine how it should work! Look onto your 'fibUpTo'
> > method. It returns nothing. From where should the values you want to
> > have come from?
>
> My suggestion (actually, it's less than a suggestion, it's really just a
> wild idea) is that the values passed to 'yield' could be collected in
> to an array in the cases where an iterator was called without a
> block. In this case, the values passed to yield (the Fibonacci numbers
> in this case) would be collected, so the method would return an array
> of them. In another post, I suggested a disambiguation in the calling
> syntax to make this possible without breaking other code.
>
> Anyway, ny initial post was the question: is there a neat, functional
> way to collect the values yielded by an iterator, and it seems like
> the answer is (sadly) no.

Well, something like this [seems, sounds] like a [generically good, good
generic] idea to me.

Certainly the application that you have in mind is the sort of thing that
ought to be encouraged, and it would certainly be nice if it were
well-supported by some sort of suitable Ruby extension.

I'm not [very, recently] familiar with functional languages, so I would be
curious to know [if, how] other languages (perhaps one or more of Haskell,
CLOS/MOP, Godel, or even Mathematica) support this this capability.

Conrad




In This Thread