Consider this piece of code:
(defvar lst '(1 1))
(defmacro get-x (x lst)
`(nth ,x ,lst))
(defun get-y (y lst)
(nth y lst))
Now suppose I want to change the value of the items in the lst list, the car with get-x and cdr with get-y. When I try to change the value using get-x (using setf), everything goes fine, but if I try it with get-y, it signals an error (abbreviated):
; caught STYLE-WARNING:; undefined: (SETF GET-STUFF)
Why is this happening?
I myself suspect that this is because the macro simply expands, and the nth function simply returns a reference to the value of the element in the list, and the function, on the other hand, evaluates the function call to nth and returns the value of the reference value (it sounds confusing).
Am I right in my suspicions? If I am right, then how do I know what is just a reference to the value and the actual value?