| First-class Function |
Website Links For Function |
Information About ™First-class Function |
| CATEGORIES ABOUT FIRST-CLASS FUNCTION | |
| data types | |
| functional programming | |
| SHOPPER'S DELIGHT | |
|
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. 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. AVAILABILITY Languages which are strongly associated with functional programming, such as Lisp , Scheme , ML , and Haskell , all support first-class functions. Other languages which also support them include Python , ECMAScript ( JavaScript ), Lua and Ruby . All modern compiled programming languages support functions defined statically at compile time. 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. SEE ALSO |