First-Class Function.
By first-class we mean that functions can be computed, passed, stored, etc. wherever other values can be computed passed stored, etc.
在函数式编程体系中,函数也是第一等公民:这是因为 All functions are values。函数就像所有其他类型的值一样,可以作为 higher-order 函数的参数,返回值,甚至可以被存储。
函数的 first-class 性质使得 function closure 的概念被提出,并进一步催生了匿名函数 (anonymous function),高阶函数 (higher-order function),函数的 combination,callback 与 currying 等机制。
一些典型的函数比如 map, filter, fold 等在函数式编程体系中可以很方便的实现。
The term higher-order function refers to the function that takes or returns other functions.
到底什么是函数式编程 (functional programming)?实际上,对此并没有一个准确的定义。但一般来说,函数式编程语言有以下特点:
- 函数是第一等公民:using functions as values.
- NOT using mutable data in most or all cases.
- 函数式编程鼓励使用递归 (recursive) 与递归数据结构。(支持尾递归优化)
- 函数式编程中的 function 最贴近数学中对函数的原始定义。
- 使用 laziness 的特性。