currentoor
currentoor

Reputation: 47

Why do I need to use symbol-value inside mapcar to assign a value?

If I have x initialized as

(setf x 0)

Then I can change the value directly by doing

(setf x 1)

So, when using mapcar, why do I have to use the symbol-value to assign to this symbol?

(mapcar #'(lambda (a b) 
            (setf (symbol-value a) b)) 
         '(x) 
         '(1))

Does it have something to do with the quote?

Upvotes: 0

Views: 149

Answers (1)

sheikh_anton
sheikh_anton

Reputation: 3452

First of all, don't use setf for initialization, define variable by defvar or defparameter.

Second, you getting symbol 'X from your '(x), not a place, to use with setf, so you need to get place by symbol-value, then set it with setf macro.

Upvotes: 1

Related Questions