Content deleted Content added
No edit summary |
expand |
||
Line 1:
In [[computer science]], a [[programming language]] is said to support '''first
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'' 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.
Support for first class functions is widely considered to be a required feature for [[functional programming language]]s. [[Lisp programming language|Lisp]], [[Scheme programming language|Scheme]], [[ML programming language|ML]], and [[Haskell programming language|Haskell]] are examples of functional programming languages that support first class functions. First class fuctions exist in non functional languages; [[Python programming language|Python]] or [[Lua programming language|Lua]], for example.▼
There are certain implementation difficulties in passing functions as arguments and returning them as results. Historically, these were termed the [[funarg problem]]s, the name coming from "function argument". A different set of difficulties arises when programs can create functions at runtime; if the program is compiled, this means that the runtime environment must itself include a compiler.
Most modern programming languages support functions defined statically at compile time. [[C programming language|C]] additionally supports function pointers, which can be stored in data structures and passed as arguments to other functions. Nevertheless, C is not considered to support first class functions, since in general functions cannot be created dynamically during the execution of a program. The closest analog in C is that of a dynamically compiled function created by a [[just-in-time compiler]], which is compiled as an array of [[machine language]] instructions in memory and then cast to a function pointer. However, this technique is specific to the underlying hardware architecture and is therefore neither general nor portable.▼
== Availability ==
▲
▲
==See also==
|