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. JS 排列组合

    function $CL(arr, n, noLC, arrDan) { //从arr中取n个组合,然后 var r = [], sum = 0; n = n - arrDan.length; (fu ...

  2. 条款21: 必须返回对象时,不要强行返回对象的reference

    总结: 绝不要返回一个local栈对象的指针或引用:绝不要返回一个被分配的堆对象的引用:绝不要返回一个静态局部对象(为了它,有可能同时需要多个这样的对象的指针或引用). 条款4中给出了“在单线程环境中 ...

  3. 项目中js调用service和procedure的办法

    Ajax.js /**通用ajax服务的定义对象 * services可以是单个服务对象,也可以是service服务数组 * 具体服务的定义请参考appendServices成员函数 */ funct ...

  4. Web开发在线工具

    JSON: JSON格式化工具 JSON检验并格式化工具 专为Web开发者准备的 63个免费在线工具

  5. django 基础入门(一)

    1. django 基本命令 新建project django-admin.py startproject project-name 新建app python manage.py startapp a ...

  6. QtInternal 之 高效使用QString(使用QLatin1String,QStringRef,QStringBuilder,QStringMatcher等相关类)

    注意:本文翻译自  http://developer.qt.nokia.com   中的  UsingQStringEffectively   ,中文译文见  简体中文版 ,如果你对翻译wiki感兴趣 ...

  7. Windows Phone 8初学者开发—第1部分:系列介绍

    原文 Windows Phone 8初学者开发—第1部分:系列介绍 您好,欢迎来到这个包含35课为Window Phone 8平台创建应用程序的系列教程.我叫Bob Tabor,在过去的11年中我一直 ...

  8. java.lang.Math类,方法学习笔记

    /**java.lang 包中的Math 类提供有常量 * 并包含有用于执行基本数学运算的 * 方法,如初等指数.对数.平方根 * 用于进行更高级的数学运算.由于 * 在Math 类的方法都是静态的, ...

  9. 域用户允许更改IP地址

    1.在DC上设置不好使. 2.需在本地用户组里添加到network.......组里. 注意:有的时候,连接不到DC上,是由于DNS的事,需要先去掉不必要的dns地址. 添加完后,需要重启或注销. 另 ...

  10. git阶段学习总结

    学习git大约有两个星期了,脑子里总算有点干货了,可以拿出来总结一下: git,用于版本控制的,刚开始觉得它是linux下默认的命令,其实也是个工具需要apt-get install git 安装一下 ...