dcsimg
Linux Today: Linux News On Internet Time.





More on LinuxToday


What's New in PHP V5.3, Part 2: Closures and lambda Functions

Dec 11, 2008, 20:33 (0 Talkback[s])
(Other stories by John Mertic)

WEBINAR:
On-Demand

How to Help Your Business Become an AI Early Adopter


[ Thanks to jmalasko for this link. ]

"The concepts of closures and lambda functions are definitely not new ones; they both come from the functional programming world. Functional programming is a style of programming that moves the focus from executing commands to the evaluation of expressions. These expressions are formed using functions, which are combined to get the results we may be looking for. This style of programming was more often used in an academic setting, but it is also seen in the realms of artificial intelligence and mathematics, and can be found in commercial applications with languages like Erlang, Haskell, and Scheme.

"Closures were originally developed in the 1960s as part of Scheme, one of the most well-known functional programming languages. Lambda functions and closures are often seen in languages that allow functions to be treated as first-class values, meaning that the functions can be created on the fly and passed as parameters to other languages.

"Since that time, closures and lambda functions have found their way out of the functional programming world and into languages like JavaScript, Python, and Ruby. JavaScript is one of the most popular languages that supports closures and lambda functions. It actually uses them as a means to support object-oriented programming, where functions are nested inside other functions to act as private members. Listing 1 provides an example of how JavaScript uses closures."

Complete Story

Related Stories: