Arbtirary thoughts on nearly everything from a modernist poet, structural mathematician and functional programmer.

Saturday, April 19, 2008

Functional programming in Perl!

Perl has Lisp-like lexical closures and it supports currying.

Both of these happen through perlref, a new feature in perl 5. Essentially, how it works is you can make anything a scalar ($) variable... anything. Sort of.

You can make a scalar variable that points to anything, which is, for the programmer, almost the same thing.

This way you can make a variable that is the curry of a function... I'm not going to go into the details, because my understanding of Perl is, well, yeah... It was fun to find out as I was searching for something else, however.

***
Perl, it seems, is a really fun language, for mostly opposite reasons from scheme. Perl's beauty comes from the amount of pre-imposed structure, but a very large language to work with. Pretty Perl is sort of like really well-written blank verse: it is going to have some obtuse words and awkward grammar, but it still flows well.

Scheme, on the other hand, comes from a small rule set, but a language which can be molded and formed as you please. Scheme would be comparable to some of Cummings better works: It follows (almost) no rules of language, but it drags you around the program nonetheless.

...
Or something like that. The poetry = programming analogy really falls flat under any rigorous scrutiny, but I hope I got the point across:
Perl- a lot of rules, but a lot of ways to exploit them
Scheme- few rules, meaning absolute freedom to exploit anything and everything.

No comments:

Creative Commons License Cory Knapp.