Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re: Why Perl Is Not My Favourite Functional Programming Language

by itub (Priest)
on Nov 06, 2004 at 00:11 UTC ( [id://405673]=note: print w/replies, xml ) Need Help??


in reply to Why Perl Is Not My Favourite Functional Programming Language
in thread A mini-language for sequences (part 1)

Have you tried prototypes?
  • Comment on Re: Why Perl Is Not My Favourite Functional Programming Language

Replies are listed 'Best First'.
Re^2: Why Perl Is Not My Favourite Functional Programming Language
by FoxtrotUniform (Prior) on Nov 06, 2004 at 02:50 UTC
    Have you tried prototypes?

    Briefly. I don't fully grok the try/catch example in perldoc perlsub, so I may be missing something, but my failed attempts look like:

    #! /usr/bin/perl use strict; use warnings; sub curry(&@) { my ($fn, @args) = @_; return sub { $fn->(@args, @_); } } &curry(+, 2)->();
    which of course does not compile. (There's also the issue that in order to really do higher-order functions with prototypes, I'd need to somehow examine fn's prototype and preserve it in the returned sub.)

    I'm thinking that a source filter might help, turning builtins used as values into anonymous subs, but I don't know very much about source filters — I'm not even sure that they do what I think they do.

    --
    Yours in pedantry,
    F o x t r o t U n i f o r m

    "Anything you put in comments is not tested and easily goes out of date." -- tye

      Perhaps I misunderstood what you wanted. While you are certainly in trouble if you want to curry the + operator, I see no problem with a function such as sum.

      use strict; use warnings; use List::Util qw(sum); sub curry(&@) { my ($fn, @args) = @_; return sub { $fn->(@args, @_); } } my $f = curry { sum(@_) } 5; print $f->(3); # prints 8 (5 + 3)
Re^2: Why Perl Is Not My Favourite Functional Programming Language
by dragonchild (Archbishop) on Nov 06, 2004 at 03:10 UTC
    How would prototypes help? All that does is allow for some syntactic sugar. It doesn't deal with the problems FoxtrotUniform mentioned. In addition, Perl5 doesn't really have solid support for lists, and arrays are not lists. Perl6 will deal with it better, by allowing you to pass lists to a function, but Perl5 requires you to deal with array references, which is just another hack.

    Being right, does not endow the right to be rude; politeness costs nothing.
    Being unknowing, is not the same as being stupid.
    Expressing a contrary opinion, whether to the individual or the group, is more often a sign of deeper thought than of cantankerous belligerence.
    Do not mistake your goals as the only goals; your opinion as the only opinion; your confidence as correctness. Saying you know better is not the same as explaining you know better.

      I was refering to the idea that prototypes allow you to imitate the way builtins such as grep and map are called (without having to say "sub", but now I'm not so sure if it that was the issue).

        It wasn't. I just noticed that my original node was a bit vague about why I didn't like the builtin/user function distinction; I've updated it. Sorry about the confusion.

        --
        Yours in pedantry,
        F o x t r o t U n i f o r m

        "Anything you put in comments is not tested and easily goes out of date." -- tye

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (4)
As of 2024-04-19 04:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found