Exam-style question
Try this first
Explain what it means for a function to be a first-class object. Include two ways in which it may be used and identify the programming-language contexts in which this applies.
Model answer
What a good answer should say
- A function is a first-class object when it can be treated as a value in the language.
- It may appear in an expression, be assigned to a variable, be assigned as an argument to another function, and be returned in a function call.
- In particular, the specification states that a function can be an argument to another function as well as the result of a function call.
- This applies in functional programming languages and in imperative programming languages that support first-class objects.
Explanation
Why this works
A complete answer must describe the general properties of first-class objects and must connect those properties specifically to functions. It should also distinguish the two language contexts given in the specification rather than claiming that every imperative language supports first-class functions.
Common mistake
No common mistake is linked to this question yet.
