Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: A mini-language for sequences (part 1)

by trammell (Priest)
on Mar 10, 2005 at 18:52 UTC ( #438380=note: print w/replies, xml ) Need Help??


in reply to A mini-language for sequences (part 1)

My to-do list has included going through the examples in this meditation for some time; the attached code is a uuencoded .tgz file containing a more streamlined version of Sequences.pm, plus files containing the various bits of example code.

Is there an easier way to post multi-file code than this? I'm not in the mood to cut-n-paste 20-odd files...

begin-base64 644 amlfsp1.tgz H4sIAPKVMEIAA+1cbW/bRhL2Z/2KiaIk5IWWRIqSetbZVYHmiqJX3OEuBxSQ DYKS1jZrilT4Usdn6L939oXkkpQUX22LabIPYIvizs7uzu4z+y535V/Ga7N3 9IzoI8bDIf00x0NT/sxwZPYt0zZNazyyjvrmYGSOj2D4nJnKkMaJGwEcrcLA S8Jop9ynwrOCZJ9/Erii/v9DPqQkWJC4u149dRrUHiPb3lX/o7E1yuu/b6Gc OcKnIziIEb/y+n/5opfGUW/uBb01ifxWa+0ubtwrAnmDmLRaaUwgTiJvkUzY 860bBV5wFfNvcxf/vXn3cR1GCYneoHyYRjB998u//vnv93AKH257EJMPQIJ0 RSI3IfSbs47CpZU/0YeYfbuMwpUTr8miBQj2JoyIu7iWnwsp/tbzMWX2uHLX 7DMmkUe4xv9561wXPju3XsKV/eb6qZDhj068cH03Ein5LFfOIgwWbgI9LFec ziEgt3DP9K3uQOtg5pPQgA5K6ljWqTNhYXOfxDF7i2FMZtLatFovYYH5Rwtc psEi8cIgBs0NwuBuFaaYkXQehWniBSTWIbnGRCOyjkhMgoTmhFcHzwU1VzrX XusiL3ltHZ9hBrWpo7P0hKicYQ8zRHyyiml2tb4B50xYGIhG4MIUHQ/+BlMu nr+k+BY0oeX4bIZib9/CBeglkRNYhnBPVZxCfwKaDhueyoZmjLab793EPTn5 Pl1hwxPGLZoIz4QfYoVAR5Y8OXlPIox9CuZkt8yPwZJajSZdLrqoJ1rwjjPr X4ii3157PgENx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937n376GVw3ublZ0Uv0 mYAlBH5ggCsGdsseJV6xi22x4G/tniufWs/gnCdliAcL59Z8YaB08U/efizd 0cmHFdlV4GyOzu4Dg26UpfniIc/ZfXvqtDdv30r3fHRxz4cOWPj2prgYDuei OJ/jcqHE/+bO/9n5+Z/R2LYU/w+Ip+b/7t9q2PMLDRW+zIr+nS/IiQuXF5Bf +vmEaHZF9OJzpNxnBYn/jZ3/s8dZ/2/bpmWp8f8B8cT8/2P0ZzsJLqb40Uki N4jXYX4lnq4RROFtXN5MnEk3rIur5OK3OZg8vSuvA7+UzPckqXrUMoNZ3zAv DJhZxoB+2MYQPy5qXqiaIS1T8iVs++WQ+N/Y+T97MMz5Pxrx8/9Ddf73IHg0 /w+xBIBiyzBxctGWNHrfOrMXv9CTHT30l2LlQOz3c6JLKnEgYRomdwumQR3D l8TxfZD439j5P7uf3f8fDgdi/0/1/4fBo/jPmJmu6VEccbSHHa3ZCPrzADpA p4+UkrpY0ZNH7HRr/vw1ldBrS3d1uVgIFj96UY70shIr/2UNKe6XvaKnoKCg oKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKDwNeF3lkgKxQB4AAA= ====

Replies are listed 'Best First'.
Re^2: A mini-language for sequences (part 1)
by tmoertel (Chaplain) on Mar 11, 2005 at 02:10 UTC
    First, thanks for taking the time to do this! The way you broke out the examples is great. It's a much better format for meditation than my original linear flow.

    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

      Excellent! I struggled a bit with seq_concat and seq_concatmap; I'm glad to have more idiomatic versions.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://438380]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (4)
As of 2019-09-15 08:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    The room is dark, and your next move is ...












    Results (179 votes). Check out past polls.

    Notices?