Trying to understand what setf
can do, I called
(macroexpand '(setf (aref vec i) val))
⇒ (let* ((v vec) (v i)) (aset v v val))
This seems obviously wrong.
However I couldn't create an actual instance where (setf (aref ..
fails. E.g.
(setq vec (make-vector 10 nil) i 3 val 'foo)
⇒ foo
(setf (aref vec i) val)
⇒ foo
vec
⇒ [nil nil nil foo nil nil nil nil nil nil]
Can someone explain what is going on here?
v
symbols are not the same and(let* ((form (macroexpand '(setf (aref vec i) val))) (symb1 (caar (cadr form))) (symb2 (caar (cdadr form)))) (equal symb1 symb2))
returnsnil
.setf
in source filegv.el
seems to create thev
symbols with a vanilla use of(gensym "v")
and this should append a counter value after the "v" prefix, creating uninterned symbolsv0
,v1
,v2
, etc.print-gensym
to better see what's going on.print-gensym
AFAICT :-( Does anyone have an explanation why the(gensym "v")
in source filegv.el
does not appendgensym-counter
?!print-gensym
, you likely just looked at the wrong place (tryC-h o
instead ofC-h f
). Thelet*
in your expanded code is likely generated bymacroexp-let2
which usesmake-symbol
rather thangensym
.