![]() |
|
Keep It Simple, Stupid | |
PerlMonks |
Functional programming with Perlby spurperl (Priest) |
on Dec 01, 2002 at 13:36 UTC ( [id://216758]=perlmeditation: print w/replies, xml ) | Need Help?? |
Hello fellow Perl monks,
I'm very interested in the Lisp programming language. As
such, I've seen quite a few discussions in LISP related
forums. One that comes up often is that modern languages
(Python, Perl, etc...) are coming closer and closer to
Lisp, employing functional programming tactics. Just to
remind you:
"Functional programming is a style of programming that emphasizes the evaluation of expressions rather than the execution of commands." I've came to think, what reminds of this style in Perl. Here are some examples that immediately popped up in my head: Mapping
Anonymous subs & treating subs as data
Eval: evaluating strings as Perl expressions
The latter reminds me of a nice example the Lisp people like to show. How do you write a Lisp interpreter ? Easy: (loop (print (eval (read)))) You can do the same in Perl, and it isn't less easy (though a bit more obfuscated - the Perl way :)
Note: all of the above are toy examples, chosen to demonstrate their specific purposes. And I wanted to consult you, knowledgeable monks, what other examples do you have in mind ? Some very cool things may be done with the constructs shown above. eval is frequently used in obfuscations, but it is a very powerful tool - for code reading and executing code, etc.
Back to
Meditations
|
|