什么是First-class citizen?

什么是First-class citizen?

  In programming language design, a first-class citizen (also typeobjectentity, or value) in a given programming language is an entity which supports all the operations generally available to other entities. These operations typically include being passed as an argument, returned from a function, and assigned to a variable.

  第一类公民(first-class citizen),是支持所有operation的entity。这些operation包括作为函数参数函数返回值直接赋值给变量


First and second class objects

  A real number may appear in an expression or be assigned to a variable, and either may appear as an actual parameter in a procedure call. A procedure, on the other hand, may only appear in another procedure call either as the operator (the most common case) or as one of the actual parameters. There are no other expressions involving procedures or whose results are procedures. Thus in a sense procedures in Algol are second class citizens—they always have to appear in person and can never be represented by a variable or expression (except in the case of a formal parameter)。

  实数可以出现在一个表达式、赋给一个变量、作为函数调用的参数。但方法,只能在一个方法调用过程中作为operator、作为其他方法的实际的参数。方法的应用范围不如实数大,所以称为二等公民。

参考:https://en.wikipedia.org/wiki/First-class_citizen#cite_note-1

  

原文地址:https://www.cnblogs.com/tekkaman/p/4866309.html