Nerderati

You're probably not nerdy enough.

The PHP 5.3 Y-Combinator

by jperras

One trick that seems to be all the rage these days is to show off fancy results from functional languages in their imperative counterparts. Now, I love functional languages; OCaml/Haskell/Erlang give me a programmer hard-on that imperative languages can only dream of. In that vein, I present to you a very clever implementation of the y-combinator in PHP 5.3 that Nate Abele came up with a few nights ago while we were discussing fixed-point combinators over instant messenger:

(see the original Twitter post)

Sexy, right?

If you’re keen on fooling around with the gist, your first challenge is to implement a memoized-version of the above y-combinator. Your second (which will take you significantly longer), is to come up with a valid reason to actually use this in in production code.

Published: November 27, 2009
Filed Under: Functional, PHP, Programming

Comments

spacer

Would like to see an article using php 5.4 as I struggle to grok this (for reasons unknown). Seems the best way to learn is to blog about it!

posted by Donal on 10.11.12 at 11:22 pm
Leave a Comment

« Previous Post
Next Post »
gipoco.com is neither affiliated with the authors of this page nor responsible for its contents. This is a safe-cache copy of the original web site.