Exam-style question
Try this first
A student says, 'A value is first-class only if it is a function.' Assess this statement using the specification requirement and give relevant examples.
Model answer
What a good answer should say
- The statement is incorrect.
- Functions are first-class objects in functional programming languages and in imperative programming languages that support such objects, but first-class objects are not limited to functions.
- A first-class object or value may appear in an expression, be assigned to a variable, be assigned as an argument, or be returned in a function call.
- Integers, floating-point values, characters and strings are examples of values that are first-class in many programming languages.
Explanation
Why this works
The answer must reject the claim that only functions can be first-class. It should use the listed properties of first-class objects and include examples from the specification.
Common mistake
No common mistake is linked to this question yet.
