Difference between revisions of "First-class function"
Karl Jones (Talk | contribs) (First) |
(No difference)
|
Revision as of 06:46, 15 June 2015
In computer science, a programming language is said to have first-class functions if it treats functions as first-class citizens.
Specifically, this means the language supports passing functions as arguments to other functions, returning them as the values from other functions, and assigning them to variables or storing them in data structures.
Some programming language theorists require support for anonymous functions (function literals) as well.
In languages with first-class functions, the names of functions do not have any special status; they are treated like ordinary variables with a function type.
The term was coined by Christopher Strachey in the context of "functions as first-class citizens" in the mid-1960s.
Functional programming
First-class functions are a necessity for the functional programming style, in which the use of higher-order functions is a standard practice.
A simple example of a higher-ordered function is the map function, which takes, as its arguments, a function and a list, and returns the list formed by applying the function to each member of the list.
For a language to support map, it must support passing a function as an argument.
External links
- First-class function @ Wikipedia