Talk:First-class object
From Wikipedia, the free encyclopedia
Overheard:
> While you can't create new functions and unbound methods in C++ at > runtime, > you can take their address and pass that around as a first class > object. True, though that usually devolves into a semantic issue about whether functions are first-class if you can only manipulate pointers to them. I usually say C has first-class functions if you squint. C++ doesn't have first-class bound member function pointers, as you point out, and another obvious example in C++ is the lack of first-class classes -- a feature in Python that is extremely powerful, since it almost makes the "factory" pattern automatic in Python (the class object itself is just a callable type that creates instances).
[link]
Not being a programmer, I am not sure what to make of this in regards to the statement in the article relating to C not having first class functions... --Lenehey 22:59, May 4, 2005 (UTC)
I think this just means -- as far as C goes -- that while the functions themselves aren't first-class, you can usefully refer to them with objects that are first-class, which means that you get most of the "first-class-ness" except the creatability. C++ still doesn't allow the creation of new functions, but with templating and/or operator overloading, it's possible to create new objects that both syntactically and semantically act like closures of existing functions at runtime and thus get a bit closer to "real" first-class functions. I'll rewrite the statement to say something about this. --Tardis 21:26, 20 July 2005 (UTC)
Also, C++ does not support closures, which I find an important tool. Not sure if that is a requirement to first-class functions or not. --Spoon! 02:36, 1 September 2006 (UTC)
[edit] Is it is, or is it aint?
The article basically defines a first-class object as an entity which can be used in programs without restriction (when compared to other kinds of objects in the same language), in the context of a particular programming language.
And then gives this a a list of possible usages for a first-class object:
- being expressible as an anonymous literal value
- being storable in variables
- being storable in data structures
- having an intrinsic identity (independent of any given name)
- being comparable for equality with other entities
- being passable as a parameter to a procedure/function
- being returnable as the result of a procedure/function
- being constructable at runtime
Now isn't this too loose? I've got some problems or at least questions about at least two of these;
- 1 - It's not clear to me that being able to construct an object with a literal is a pre-requisite. I'm taking literal here in the common sense that there is a syntax which the compiler understands to construct an instance/data value at compile time. This really excludes way too many objects, I think.
- 5 - I'm not sure what this means. Maybe if we mean identity comparison, but to my mind equality usually has to do with some kind of 'state' equivalence, and not all first-class objects are so comparable.
Is there a reference to the source of this list? or did it just come about here?
Since it's often a topic of dispute whether or not a programming language supports certain constructs as first-class, I'm troubled that this definition seems to make things so language dependent. Since, C doesn't allow functions to be constructed at run-time, BUT the definition is language dependent, we might as well say that functions in C are first class. But are they? --Rick 14:59, 23 August 2006 (UTC)