Re: [code-review] Algorithm::GenerateSequence

Andrew Savige <ajsavige-/[email protected]> Mon, 8 Sep 2003 18:54:21 +1000 (EST)
Newsgroups gmane.comp.lang.perl.code-review-ladder
Message-ID <[email protected]>
Richard Cramp wrote:
> I needed this to write Games::Set (possibly a forthcoming post) and
> couldn't for the life of me find anything that looked like it by
> searching on such terms as Counter, Iterator, Generator, Sequence.
> 
> Now what wheel is it I've reinvented, and how round is this one?

It looks excellent to me, but I'm very new to all this iterator/
generator business in Perl. I heard MJD is fanatical on this stuff,
but I couldn't find any useful free stuff at at http://www.plover.com/.
Can anyone point me to some good white papers on iterators/generators
in Perl? Other languages, such as Python and Haskell, have built-in
support for lazy evaluation in generators/iterators, so you can create
iterators that return unbounded output (e.g. Fibonacci Sequence).
Can Perl do that? What about Perl 6?

Anyway, your solution seems quite memory efficient in that the ctor
takes references, so there should not be a big memory overhead, even
with huge lists.

I noticed in sub new:
   _counters => [ map { 0 } @_ ],
can be made a little shorter and faster like this:
   _counters => [ (0) x @_ ],

/-\ (waiting for wiser heads on this list to comment...)



http://search.yahoo.com.au - Yahoo! Search
- Looking for more? Try the new Yahoo! Search