First class functions are a common feature of [FunctionalLanguages]. In this family of languages, functions can be passed to a function and returned as values of a function, just like any other standard values (numbers, strings, etc). This feature allows for more elegant programming.

For example, in OcamlLanguage :

(* Define a function which takes an integer x and multiplies it by n *)

let times_n n = function x -> x * n ;;

(* Define functions twice and thrice that multiply their input *)
(* by 2 and 3 respectively.                                    *)
(* These functions are values of the times_n function.         *)

let twice = times_n 2;;
let thrice = times_n 3;;

(* Let's try these functions *)

twice 3;;
- : int = 6
thrice 3;;
- : int = 9

FirstClassFunctions (last edited 2008-07-09 05:47:49 by localhost)