NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.
All the Perl that's Practical to Extract and Report
Stories, comments, journals, and other submissions on use Perl; are Copyright 1998-2006, their respective owners.
The real way to write factorial in Perl 6: (Score:1)
It isn’t even worth pulling out into a function.
Re: (Score:1)
Perl Golf still lives, I see. I had started playing around with subsets and had intended to update it with stuff like that but I will just say wow...that is really neat.
Re: (Score:1)
It’s not golf! That’s just bog-standard Perl 6. Hyper- and reduce operators are normal part of the repertoire and in fact one of the reasons I am looking forward to v6. They get rid of huge swathes of monkey code… as you just saw. Lots of things that would require loops, which really constitute nothing but accidental complexity, can be expressed by a single operator.
Re:The real way to write factorial in Perl 6: (Score:1)
However, how will the simple
[*] 1..$nwork or fail when $n is large like 100 or 8.424000e+08 ? Does it magically transform to a generator and tail recursion under the covers, or does it do what it appears to say and fill memory with a low entropy sequence? Fills your swap disk and dies horribly is much worse than throwing floating overflow exception after 200 iterations.See http://www.perladvent.org/2008/3/ [perladvent.org] for benchmarks where it doesn't fail for absurd inputs so we can discuss them.
Bill
# I had a sig when sigs were cool
use Sig;
Reply to This
Parent
Re: (Score:1)
Perl 6 lets you write :-)
1..*(or alternatively1..Inf). That should answer your question.