关于first-class object的解释
定义,什么是编程语言的第一等公民?
In computer science, a programming language is said to have first-class functions if it treats functions as first-class citizens。
解释:
In programming language design, a first-class citizen (also type, object, entity, 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, modified, and assigned to a variable.
一个一等公民(即类型、对象、实体、或值等等)在一门特定的编程语言中能够支持其他大多数实体所支持的操作。
例子Ruby。
Ruby是在Python之前风靡世界的高级面向对象编程语言。
Ruby是单类继承关系,一切都继承自Class类。所以说Class类是第一公民。
Classes in Ruby are first-class objects, each is an instance of class Class.
BasicObject继承Class类,Object类继承BasicObject。
Object is the default root of all Ruby objects.
例子,类Object的类是Class类。
2.6.2 :019 > Object.class
=> Class
Python
在Python,函数是第一类对象。In Python, functions are first class object (first class citizen too!).