In computer science, a programming language is said to have first-class functions if it treats functions as first-class citizens. Specifically, this means the language supports passing functions as arguments to other functions, returning them as the values from other functions, and assigning them to variables or storing them in data structures.[1] Some programming language theorists require support for anonymous functions as well.[2] In languages with first-class functions, the names of functions do not have any special status; they are treated like ordinary variables with a function type.[3] The term was coined byChristopher Strachey in the context of “functions as first-class citizens” in the mid-1960s.[4]

First-class functions are a necessity for the functional programming style, in which the use of higher-order functions is a standard practice. A simple example of a higher-ordered function is the map 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, especially in the presence of non-local variablesintroduced in nested and anonymous functions. Historically, these were termed the funarg problems, the name coming from "function argument".[5] In early imperative languages these problems were avoided by either not supporting functions as result types (e.g. ALGOL 60Pascal) or omitting nested functions and thus non-local variables (e.g. C). The early functional language Lisp took the approach of dynamic scoping, where non-local variables refer to the closest definition of that variable at the point where the function is executed, instead of where it was defined. Proper support for lexically scoped first-class functions was introduced in Scheme and requires handling references to functions as closures instead of bare function pointers,[4] which in turn makes garbage collection a necessity.

First-class value can be

  1. passed as an argument
  2. returned from a subroutine
  3. assigned into a variable.

Second-class value just can be passed as an argument.

Third-class value even can't be passed as an argument.

更多:

http://en.wikipedia.org/wiki/First-class_function

http://stackoverflow.com/questions/2578872/about-first-second-and-third-class-value

随机推荐

  1. Ubuntu 15.04 安装rmagick 2.15.4

    apt-get install  pkg-config, libmagick-dev,libmagickcore-dev, libmagickwand-dev, gem install rmagick

  2. NSArray的4种遍历方式

    前言:NSArray对应的是java的List,不同的是其元素不能更改,不过其派生类NSMutableArray可以更改,遍历的方式跟java的List基本一样 一.  for循环 Student * ...

  3. [条款36]绝不重新定义继承而来的non-virtual函数

    看下面的两个类的声明代码: class B { public: void mf(); //something to do }; class D : public B { public: void mf ...

  4. hdu 4180

    题意; 求接近规定 分数 的 最大分数用到 farey 数列的第二条性质 1 #include <iostream> #include<stdio.h> using names ...

  5. 在word中批量制作条形码

    条码打印软件可以批量生成条形码然后直接打印,但是有些客户不需要直接打印,而是想将生成的条形码在word中进行排版,发给自己的客户或者下属部门来打印.那么如何实现在word中批量制作条形码呢? 操作很简 ...

  6. springMVC + mybatis 搜索 分页等

    mybatis-3.0.5spring-core-3.2.0.RELEASE等MyBatis3+Spring3当前Spring版本(3.0.5)中未提供对MyBatis3的支持使用第三方jar包进行整 ...

  7. 阿尔宾我饿iejr89e 如何

    http://www.huihui.cn/share/8112372 http://www.huihui.cn/share/8112363 http://www.huihui.cn/share/811 ...

  8. android 破解九宫格

    将目录切换到D:/adb目录下,命令如下 敲入命令 adb shell 然后回车,可以见到如下结果 再敲入命令cd /data/system然后回车, 再执行 rm gesture.key 回车,搞定 ...

  9. ArcGIS Engine 改变线IPolyline的方向

    有时候需要改变一下线的方向来组成要要的图形,可以按一下方法来变换一下. 如果看官有好的方法的话,请不吝贴上为谢! private IPolyline ChangeDirection(IPolyline ...

  10. 查看一个int数组里边的每个数字出现过几次

    public void aa() { int[] a = { 1, 2, 3, 4, 5, 4, 3, 2, 1 }; Hashtable ht = new Hashtable(); for (int ...