First-class function: Difference between revisions

Content deleted Content added
SmackBot (talk | contribs)
m Date/fix maintenance tags
exclude compiling and eval
Line 2:
{{Mergefrom|Function literal|date=March 2007}}
 
In [[computer science]], a [[programming language]] is said to support '''first-class functions''' if it treats [[function (programming)|function]]s as [[first-class object]]s. Specifically, this means that functionsthe canlanguage besupports createdconstructing new functions during the execution of a program, storedstoring them in data structures, passedpassing them as arguments to other functions, and returnedreturning them as the values of other functions. This concept doesn't cover any means external to the language and program ([[metaprogramming]]), such as invoking a [[compiler]] or an [[eval]] function to create a new function.
 
These features are a necessity for the [[functional programming]] style, in which (for instance) the use of [[higher-order function]]s is a standard practice. A simple example of a higher-ordered function is the ''[[Map (higher-order function)|map]]'' or ''mapcar'' 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.