First-class function

This is an old revision of this page, as edited by 201.25.248.77 (talk) at 02:23, 14 April 2006. The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

In computer science, a first class function is a programming language construct that allows a function to be treated as a first class object. In particular, a first class function can be created during the execution of a program, stored in a data structure, passed as an argument to another function, and, in some programming languages, modified using the data processing facilities of the language.

Support for first class functions is widely considered to be a required feature for functional programming languages. Lisp, Scheme, ML, and Haskell are examples of functional programming languages that support first class functions. First class fuctions exist in non functional languages; Python or Lua, for example.

Most modern 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