Tie::LazyList

Perl extension for lazy lists growing on demand
Download

Tie::LazyList Ranking & Summary

Advertisement

  • Rating:
  • License:
  • Perl Artistic License
  • Price:
  • FREE
  • Publisher Name:
  • Goldin Evgeny
  • Publisher web site:
  • http://search.cpan.org/~genie/

Tie::LazyList Tags


Tie::LazyList Description

Perl extension for lazy lists growing on demand Tie::LazyList is a Perl module that allows you to create lazy lists ( "infinite lists, whose tail remain unevaluated", Watt ) growing on demand with user-defined generation function.What you have is a usual Perl array whose elements are generated by some function and which may be accessed by $arr as any other, but actually grows under the hood if the element you're accessing isn't generated yet. This way, the amount of memory wasted for the array is no more ( and no less, unfortunately ) then you need. Think about it as dynamically growing factorials ( Fibonacci numbers, arithmetic progression .. ) table which you can access for any element without need to explicitly build and maintain it.All you need to specify is the initial list elements, generation function and .. that's it, actually - go and work with it ! See the example above - I think, they demonstrate the simplicity.SYNOPSIS use Tie::LazyList; # lazy list of factorials tie @arr, 'Tie::LazyList', , 'FACT'; tie @arr2, 'Tie::LazyList', 1, sub { my ( $array_ref, $n ) = @_; $array_ref-> * $n }; tie @arr3, 'Tie::LazyList', \@arr; print "$_\n" for @arr; # prints ( eternally ) values of 1!, 2!, 3! .. print "$_\n" for @arr2; # the same print "$_\n" for @arr3; # the same # lazy list of powers of 2 tie @arr, 'Tie::LazyList', 2, 'POW'; tie @arr2, 'Tie::LazyList', 1, sub { my ( $array_ref, $n ) = @_; $array_ref-> * 2 }; tie @arr3, 'Tie::LazyList', \@arr2; print $arr , "\n", # prints 1024 = 2^10 $arr2, "\n", # the same $arr3, "\n"; # the same # lasy lists of Fibonacci numbers, arithmetical/geometrical progressions and their sums, etc .. Requirements: · Perl


Tie::LazyList Related Software