Hi,

My name is Goldin Evgeny,
my email is [EMAIL PROTECTED],
my homepage is http://geniek.net
my preferred user-ID on CPAN is "GENIE" or "GENIEK"


I'd like to contribute the new module called "Tie::LazyList" - it
allows programmer to generate infinite lists based on the start value
and generation function, implemented as tied array and, once created, may be
accessed for any value via $arr[ x ].
This may allow to easily create arrays of factorials, powers of 2, Fibonachi
numbers and access any value in it.


Example :

# creating array of factorials,
# params to tie are starting values ( either numeric scalar or list ref ) and
# the generation function, which will receive the ref to the list and
# the index to generate when called
tie @arr, "Tie::LazyList", [ 0, 1 ], sub { my ( $list_ref, $j ) = @_;
                                           $list_ref->[ $j - 1 ] * $j };
                                           
# now we can access factorial of any number, the underlying array will be
# dynamically expanded
for ( 1 .. 20 ){
        print $arr[ $_ ],"\n";
}

And here it's running :

E:\Temp>perl -w
use strict;
use Tie::LazyList;
my @arr;

tie @arr, "Tie::LazyList", [ 0, 1 ], sub { my ( $list_ref, $j ) = @_;
                                           $list_ref->[ $j - 1 ] * $j };
for ( 1 .. 20 ){
        print $arr[ $_],"\n";
}
^Z
1
2
6
24
120
720
5040
40320
362880
3628800
39916800
479001600
6227020800
87178291200
1307674368000
20922789888000
355687428096000
6.402373705728e+015
1.21645100408832e+017
2.43290200817664e+018

E:\Temp>



  Thank you !


Reply via email to