Difficulty: Easy
Correct Answer: (lambda (x) (+ (* 2 x) 1))
Explanation:
Introduction / Context:
Lisp uses prefix notation and functional forms to represent expressions. Writing a mathematical function such as f(x) = 2x + 1 requires understanding of lambda expressions, function application, and the use of arithmetic operators in prefix form.
Given Data / Assumptions:
Concept / Approach:
In Lisp, multiplication is written as (* a b) and addition as (+ a b). A lambda expression is written (lambda (args) body). Thus, to compute 2x + 1, we multiply x by 2 and then add 1 to the result inside the lambda body.
Step-by-Step Solution:
Verification / Alternative check:
Apply the lambda to a test value: ((lambda (x) (+ (* 2 x) 1)) 3) evaluates to 7, which matches 23+1.
Why Other Options Are Wrong:
Common Pitfalls:
Accidentally using infix notation or omitting parentheses leads to syntax errors. Ensure operators are in prefix form and expressions are fully parenthesized.
Final Answer:
(lambda (x) (+ (* 2 x) 1))
Discussion & Comments