Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

RFC: Acme::BottomsUp

by davidrw (Prior)
on Aug 14, 2006 at 18:57 UTC ( [id://567298]=perlmeditation: print w/replies, xml ) Need Help??

Acme::BottomsUp - Write individual statements backwards
This is a fun mostly proof-of-concept module that I'm looking for comments on, especially alternative ways to code it and sample usage /possibilities (practical or otherwise)... It uses Filter::Simple and PPI ; source code below.
Update: 2006-08-15 uploaded to cpan as Acme::BottomsUp

SYNOPSIS
my @arr = (1..10); use Acme::BottomsUp; @arr # first, start w/ numbers grep { $_ % 2 } # then get the odd ones map { $_**3 } # then cube each one join ":", # and glue together print # lastly, display result ; print "ok"; no Acme::BottomsUp;
DESCRIPTION
This module allows you to write multi-line perl statements in reverse order so that it "reads better". For example, normally one would write the code from the SYNOPSIS as:
my @arr = (1..10); print # lastly, display result join ":", # and glue together map { $_**3 } # then cube each one grep { $_ % 2 } # then get the odd ones @arr # first, start with numbers ;

The full source:
package Acme::BottomsUp; use warnings; use strict; our $VERSION = '0.01'; use Filter::Simple; use PPI; FILTER { my $doc = PPI::Document->new(\$_); $_ = join '', map { my $s = $_->content; $s =~ s/;\s*$//s; join("\n", reverse split "\n", $s ) . "\n;" } @{ $doc->find('PPI::Statement') }; }; 1;

Considered (Marza): Split off the "offensive" talk to it's own thread or delete the posts as they have nothing to do with the topic
Unconsidered (holli): enough keep votes (Keep: 13, Edit: 4, Reap: 1)

Replies are listed 'Best First'.
Re: RFC: Acme::BottomsUp
by eyepopslikeamosquito (Archbishop) on Aug 14, 2006 at 21:21 UTC

    Cute. Reminds me of Perl 6 Feed operators. From S06:

    Leftward feeds are a convenient way of explicitly indicating the typical right-to-left flow of data through a chain of operations:
    @oddsquares = map { $_**2 }, sort grep { $_ % 2 }, @nums; # more clearly written as... @oddsquares = map { $_**2 } <== sort <== grep { $_ % 2 } <== @nums +;
    Rightward feeds are a convenient way of reversing the normal data flow in a chain of operations, to make it read left-to-right:
    @oddsquares = (@nums ==> grep { $_ % 2 } ==> sort ==> map { $_**2 });
    Note that the parens are necessary there due to precedence.

      I had no idea that the feed operator existed, but *that* is cool. Thanks for giving me a good reason to go read some Perl6 documentation...
Re: RFC: Acme::BottomsUp
by Fletch (Bishop) on Aug 14, 2006 at 19:58 UTC

    Next write Acme::YodaStatement you must, hrrrmmmm?

      You mean like this old node?

      Alex / talexb / Toronto

      "Groklaw is the open-source mentality applied to legal research" ~ Linus Torvalds

Re: RFC: Acme::BottomsUp
by DrHyde (Prior) on Aug 14, 2006 at 20:06 UTC
    Galloping gay christ that's hideous!

    Well done!

    Considered (Argel): Reap: Inappropriate in certain work envrionments and since it is off-topic no reason to keep it
    Unconsidered (holli): enough keep votes (Keep: 11, Edit: 0, Reap: 3)

    A reply falls below the community's threshold of quality. You may see it by logging in.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlmeditation [id://567298]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (2)
As of 2024-04-26 00:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found