|
|
This article is in need of attention from an expert on the subject. WikiProject Computer science or the Computer science Portal may be able to help recruit one. (August 2009) |
| This article needs additional citations for verification. Please help improve this article by adding reliable references. Unsourced material may be challenged and removed. (August 2009) |
In computing, a first-class object (also value, entity, and citizen), in the context of a particular programming language, is an entity which can be passed as a parameter, returned from a subroutine, or assigned into a variable.[1] In computer science the term reification is used when referring to the process (technique, mechanism) of making something a first-class object.[citation needed]
The term was coined by Christopher Strachey in the context of “functions as first-class citizens” in the mid-1960s.[2].
Contents |
Definition
An object is first-class when it[citation needed]:
- can be stored in variables and data structures
- can be passed as a parameter to a procedure/function
- can be returned as the result of a procedure/function
- can be constructed at runtime
- has intrinsic identity (independent of any given name)
The term "object" is used loosely here, not necessarily referring to objects in object-oriented programming. The simplest scalar data types, such as integer and floating-point numbers, are nearly always first-class.
Language Examples
In C and C++, it is not possible to create new functions at runtime, whereas other kinds of objects can be created at runtime. As a result, functions in C are not first-class objects; instead, they are sometimes called second-class objects because they can still be manipulated in most of the above fashions (via function pointers). Similarly, strings are not first class objects in FORTRAN 66 because it is not possible to assign them to variables (unlike, for example, numbers).
In Smalltalk, functions (methods) are first class objects, just like Smalltalk classes. Since Smalltalk Operators (+, -) are methods, they are also objects.
In many older languages (for example C) arrays were not first-class: they could not be assigned as objects; only their elements could be directly manipulated. Few languages support continuations and GOTO-labels as first-class objects, though arguably they don't support them as objects at all. Closures were previously also rarely supported as first-class values, although this is common in recent languages.
Notes
- ^ Scott, Michael (2006). Programming Language Pragmatics. San Francisco, CA: Morgan Kaufmann Publishers. p. 140.
- ^ Rod Burstall, "Christopher Strachey—Understanding Programming Languages", Higher-Order and Symbolic Computation 13:52 (2000)
See also
This entry is from Wikipedia, the leading user-contributed encyclopedia. It may not have been reviewed by professional editors (see full disclaimer)




