Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: (tye)Re: Why Closures?

by jdporter (Canon)
on Nov 05, 2002 at 16:35 UTC ( #210500=note: print w/ replies, xml ) Need Help??


in reply to (tye)Re: Why Closures?
in thread Why Closures?

Functional programming is where you treat functions like data. That is, you have functions that take functions as arguments and return functions as values. Just using pointers to functions (a.k.a. code references in Perl) allows you to do that to some extent, but not enough to really call it functional programming.
Sorry, tye, I have to disagree with you. Functional programming is generally defined as programming without side-effects. At its most extreme, this means programming without external state of any kind.

Perl can not be considered a functional language in a purist sense, because it supports non-functional programming. However, it does support functional programming, so it is possible to "use Perl as a functional language", if one chooses.

Also, even given your definition of FP, Perl satisfies the definition perfectly. The only thing LISP-family languages can do that Perl can't, is treat function definitions as runtime-modifiable data. (That is, a lisp program can rewrite any of its functions at will.) But, while powerful, this ability is not generally considered to be essential to the definition of functional programming.


Comment on Re: (tye)Re: Why Closures?
Re: Re: (tye)Re: Why Closures?
by Jenda (Abbot) on Nov 05, 2002 at 22:04 UTC

    IMHO it's better to use the positive definition "FP allows you to treat functions as data" than the negative one "FP is without side effects".

    If you insisted on the negative definition then even most officialy functional languages would not be functional. And if the FP was only about the restriction it would not be very attractive ;-)

    For me FP means two things. Higher order functions+closures (which is something we have in Perl) and a good general type system with real polymorphism (map: (( 'a -> 'b ), 'a list) -> 'b list) (which is something that we don't have in Perl, but since we have no types I don't feel restricted).

    Jenda

    P.S.: It's a shame Microsloth did not steal either from FP for it's .Net :-(
    C# still feels like something 30 years old :-(

      IMHO it's better to use the positive definition "FP allows you to treat functions as data" than the negative one "FP is without side effects".
      Suit yourself. You'll find yourself in the minority opinion wrt computer scientists.
      If you insisted on the negative definition then even most officialy functional languages would not be functional.
      Not true, there are some "pure" FP languages. Of course, like most single-paradigm languages, people don't use them very much!

        If you read once more what did I say you'll find out that I DID NOT say there are no pure FP languages. I've spent some time with one (Concurrent Clean) and I DID like it!

        I am not using it now though, noone around here would be able to cooperate with me :-(

        The reason why did I like Clean was not because it restricted me (no side-effects), but because of the restriction it was able to offer something (laziness). Of course the generality of the type system and ability to compose functions at will was appreciated as well.

        Jenda

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (5)
As of 2014-10-02 03:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    What is your favourite meta-syntactic variable name?














    Results (45 votes), past polls