Today I have been learning about laziness in perl6. Most specifically, I have been playing with gather { take }. You can find an excellent explanation in this Blog. Anyway. The example in the blog applies the x * (x + 1) as the function to be applied to the input list. I have played around putting in different functions and plugging in values. Eventually I came up with a script to spit out tax based on user input.
use v6;
my @tax_table = gather {
for 1..1000 {
take $_ * .0825;
}
}
my $amount = prompt("How much are you paying? ");
say "Tax Due is @tax_table[$amount]";
Everyone remotely interested in Perl 6 should go to the Perl 5 to 6 blog. So far it is the most useful Perl 6 resource I've seen.
No comments:
Post a Comment