in reply to Re: A mini-language for sequences (part 1)
in thread A mini-language for sequences (part 1)
Second, here's a patch that adds seq_concat, which is almost identical to seq_series. (In fact, the patch redefines the latter in terms of the former.)
diff -urN amlfsp1/ex17.pl amlfsp1.new/ex17.pl --- amlfsp1/ex17.pl 2005-03-09 15:22:08.000000000 -0500 +++ amlfsp1.new/ex17.pl 2005-03-10 20:53:15.660873854 -0500 @@ -11,5 +11,5 @@ seq(1..3)->seq_map(\&supto)->seq_concat->enumerate; -#seq(1..3)->seq_concatmap(\&supto)->enumerate; +seq(1..3)->seq_concatmap(\&supto)->enumerate; diff -urN amlfsp1/Sequences.pm amlfsp1.new/Sequences.pm --- amlfsp1/Sequences.pm 2005-03-10 13:38:12.000000000 -0500 +++ amlfsp1.new/Sequences.pm 2005-03-10 20:56:21.166003398 -0500 @@ -101,7 +101,11 @@ } sub seq_series { - my $seqs = seq( @_ ); + seq( @_ )->seq_concat; +} + +sub seq_concat { + my $seqs = shift; my $seq; seqsub { my @val; @@ -166,19 +170,6 @@ wantarray ? @accum : $accum[0]; } -sub seq_concat { # FIXME: there's probably a slicker way of doing th +is... - my $seq = shift; - my @cache; - while (my @seqs = $seq->()) { - foreach my $s (@seqs) { - while (my @vals = $s->()) { - push @cache, @vals; - } - } - } - seq(@cache); -} - sub seq_concatmap { my ($seq, $fn) = @_; $seq->seq_map($fn)->seq_concat;
To apply the patch (on a Unix-esque system), save it into a file, "cd" into the directory containing Sequences.pm, and then run this command: "patch -p1 < patchfile".
Cheers,
Tom
Tom Moertel : Blog / Talks / CPAN / LectroTest / PXSL / Coffee / Movie Rating Decoder
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: A mini-language for sequences (part 1)
by trammell (Priest) on Mar 11, 2005 at 03:51 UTC |