Version 3 of first-class functions

Updated 2011-05-21 13:49:14 by aspect

A concept that exists in functional and semi-functional languages including Scheme, Javascript, Haskell, ML. By definition, they do not exist in languages where functions inhabit a different namespace than variables: for example C, Perl, Algol .. and Tcl.

lambda as used with apply are first class, but they do not (yet?) completely replace procedures defined with proc.

The principle is that functions (procedures) are "first class citizens", like numbers, strings or any other value. Thus, they can be:

  • stored in variables
  • passed to functions
  • returned from functions

like any other value. Note that functions are usually opaque objects, so introspection is not available.

First-class functions permit coding styles that are not available in languages without them (C is a good example):

See Playing Scheme for an example of trying to make Tcl's functions first class.