Skip to content

Comment on Underscore.phpparent

Comments

> PHP will start to look a lot like Perl.

You had a typo, there.

For all of its other sins, simple functional programming (that is, first-order functions and the basic uses thereof, rather than immutability and the other more modern FP characteristics) is easier than in most languages. In fact it's easier in Perl than in Erlang, a putatively-functional language!

    map { $_ * 2 } (1, 2, 3)                   - Perl
    lists:map(fun (X) -> X * 2 end, [1, 2, 3]) - Erlang
    map (*2) [1, 2, 3]                         - Haskell
The last one for comparison. Erlang can do better with a list comprehension, though:
    [X * 2 | X <- [1, 2, 3]]
which except for case also works for Haskell. But that exclusively works with only map and filter (in Erlang [1]), Erlang is still surprisingly klunkier than Perl for everything else (folds, actually passing functions around, etc).

[1]: Haskell recently re-added monad comprehensions, so comprehensions aren't as limited anymore. http://blog.n-sch.de/2010/11/27/fun-with-monad-comprehension...

This. is. not. reddit. No FTFY type of comments please.

AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.