Beefy Boxes and Bandwidth Generously Provided by pair Networks Joe
Just another Perl shrine
 
PerlMonks  

Re: Perl6 and Extreme Programming

by vladb (Vicar)
on May 25, 2002 at 21:04 UTC ( #169305=note: print w/ replies, xml ) Need Help??


in reply to Perl6 and Extreme Programming

Thanks for the topic you've picked Ovid. I too am very excited and look forward to many innovative 'tools' in Perl6 that will greatly enhance and support the kind of software development paradigm as XP.

You are asking...

Does anyone familiar with Perl6 care to offer concrete examples of what was meant by the XP quote?

I'm happy to know of one such feature you are inquiring about. The feature is termed as 'higher-order functions'. You can read a full thread on the related RFC. Damian Conaway also touches this subject in one of his diary entries. Moreover, Damian has written an excellent Perl5 module to simulate this feature of Perl6. Not surprisingly the module is called Perl6::Currying.

Having read through these resources, I'm sure you'll agree with me that this feature may well be amongst the few ones welcomed by the practitioners of the XP approach. One can develop a higher-order function and still use the function even with incomplete parameter list. This is great for a lot of resons. First, there's a way for you to write a function and test it in stages. Second, this allows for greater flexibility as to the use of a higher-order function. For example, you can derive lower-order variants of the higher-order functions to accomplish specific (albeit 'narrower' in purpose) tasks!

Anyhow, please do take a read as I can't possibly describe this feature as good as it has already been described in the aforementioned resources! ;-)

_____________________
$"=q;grep;;$,=q"grep";for(`find . -name ".saves*~"`){s;$/;;;/(.*-(\d+) +-.*)$/; $_=["ps -e -o pid | "," $2 | "," -v "," "];`@$_`?{print"+ $1"}:{print" +- $1"}&&`rm $1`; print$\;}


Comment on Re: Perl6 and Extreme Programming
Download Code
Re: Re: Perl6 and Extreme Programming
by chromatic (Archbishop) on May 25, 2002 at 21:58 UTC
    Higher-order functions sound much more like functional programming (lambda calculus) than extreme programming (do only the important things all of the time).

    I'd expect an answer more like, "It will be much easier to write a refactoring engine in Perl 6 -- and here's why.

      It will be much easier to write a refactoring engine in Perl 6 -- and here's why...

      You'll be able to grab the parse-tree from the compiler before it's converted to op-codes. Or after it's been converted, but before it's been reduced, if you prefer. Once you have a structured representation of the code, refactoring is "merely" the application of standard mathematical tree/graph factoring and optimization techniques.

        Or even after it's been reduced, if you really want. :)

        Courtesy of the Ruby folk, I've been getting some exposure to some of the niftier bits of Smalltalk, including the browser setups they have. I really, really want some of that for Parrot and hence perl 6.

Re: Re: Perl6 and Extreme Programming
by Jenda (Abbot) on May 26, 2002 at 22:42 UTC

    I am afraid you have it wrong. "Currying" and "higher-order functions" are two unrelated features that only have one thing in common: they often appear in functional languages. A function is "higher-order" if it accepts a function as it's parameter or if it returns a function (it "created").

    Higher order functions are long supported by Perl 5, even though we usualy do not use that name. (I guess so that we do not scare people away. Higher-order functions sounds too "functional".)

    sub Map { my $sub = shift(); my @new_arr; # want foreach my $item (@_) { push @new_arr, $sub->($item); } @new_arr; } sub foo {$_[0] + 1} @increased = Map \&foo, (1,2,3); print "@increased\n";
    On the other hand a function is curried if it returns a "partialy applied" function if called with only the first few parameters. Of course then it is also higer-order actualy, but that's not the point.
    sub Map { my $sub = shift(); if (@_) { # we are calling it normaly my @new_arr; # want foreach my $item (@_) { push @new_arr, $sub->($item); } return @new_arr; } else { # only the function is passed return sub { my @new_arr; # want foreach my $item (@_) { push @new_arr, $sub->($item); } return @new_arr; } } } sub foo {$_[0] + 1}; $inc = Map \&foo; @increased = $inc->(1,2,3); print "@increased\n";

    (Next day) Actually ... the second function is not a good example. It's both curried and uncurried. If I wanted a plain curried version I'd define it as

    sub Map { my $sub = shift(); return sub { my @new_arr; # want foreach my $item (@_) { push @new_arr, $sub->($item); } return @new_arr; } }
    and then would call it either as
    @incremented = Map(\&foo)->(1,2,3)
    or
    $Inc = Map(\&foo); @incremented = $Inc->(1,2,3)
    As you can see the syntax is not too nice in Perl. Currying is a bit alien to Perl, it looks much more natural in modern functional languages.

      Jenda

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (4)
As of 2014-04-21 01:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (489 votes), past polls