|
|
| Pathologically Eclectic Rubbish Lister | |
| PerlMonks |
Re: Functional perl pleaseby ariels (Curate) |
| on Jan 06, 2002 at 12:56 UTC ( #136663=note: print w/ replies, xml ) | Need Help?? |
|
Here's one example. The Hamming sequence is the sequence of numbers whose prime factors are only 2, 3 and 5, in ascending order. Writing a program to print out the sequence is non-trivial (we exclude "solutions" which must store the entire sequence in a large array and the like). It used to be the poster example of co-routines, but current style more likely favours a functional program using streams and (somewhat) lazy evaluation. Read about streams in this chapter of Structure and Interpretation of Computer Programs. The program below is a translation to Perl of a streams-based program to print out the Hamming sequence.
EDIT (20020506): fix indentation (Perlmonks does horrible things to tabs; glad it's not Pythonmonks).
In Section
Seekers of Perl Wisdom
|
|
||||||||||||||||||||