What is the value of (cdr ‘(a b c d)) after following LISP statements? [code](write (setf (cdr '(a b c d)) 2)) (write (cdr '(a b c d)))[/code]

Linh Chi

New member
What is the value of (cdr ‘(a b c d)) after following LISP statements?
Code:
(write (setf (cdr '(a b c d)) 2))
(write (cdr '(a b c d)))
A. 2
B. B C D
C. A
D. A 2
 
Answer: b
Explanation: The setf will store the value 2 in (cdr ‘(a b c d)) but when it comes out of the setf braces and (cdr ‘(a b c d)) is again called then it is treated as a new statement and the value of (cdr ‘(a b c d)) again changes to B C D. We can say scope of setf’s cdr remain in that braces only. And the again called cdr has its new scope with its own values.
Output: 2 B C D.
 

Tìm kiếm

Back
Top