First-class function

From Wiki @ Karl Jones dot com
Jump to: navigation, search

In computer science, a programming language is said to have first-class functions if it treats functions as first-class citizens.

Description

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.

See also

External links