Setf weird expansion












6















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?










share|improve this question




















  • 2





    OK. I understand now. The two 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)) returns nil.

    – phs
    Mar 11 at 9:58








  • 1





    Strangely, the code for setf in source file gv.el seems to create the v symbols with a vanilla use of (gensym "v") and this should append a counter value after the "v" prefix, creating uninterned symbols v0, v1, v2, etc.

    – phs
    Mar 11 at 10:05






  • 2





    You might like to play with print-gensym to better see what's going on.

    – Stefan
    Mar 11 at 12:35











  • @stefan: I have emacs-26.1 and it has no print-gensym AFAICT :-( Does anyone have an explanation why the (gensym "v") in source file gv.el does not append gensym-counter ?!

    – phs
    Mar 11 at 13:59








  • 1





    I'm pretty sure you do have print-gensym, you likely just looked at the wrong place (try C-h o instead of C-h f). The let* in your expanded code is likely generated by macroexp-let2 which uses make-symbol rather than gensym.

    – Stefan
    Mar 11 at 19:01
















6















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?










share|improve this question




















  • 2





    OK. I understand now. The two 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)) returns nil.

    – phs
    Mar 11 at 9:58








  • 1





    Strangely, the code for setf in source file gv.el seems to create the v symbols with a vanilla use of (gensym "v") and this should append a counter value after the "v" prefix, creating uninterned symbols v0, v1, v2, etc.

    – phs
    Mar 11 at 10:05






  • 2





    You might like to play with print-gensym to better see what's going on.

    – Stefan
    Mar 11 at 12:35











  • @stefan: I have emacs-26.1 and it has no print-gensym AFAICT :-( Does anyone have an explanation why the (gensym "v") in source file gv.el does not append gensym-counter ?!

    – phs
    Mar 11 at 13:59








  • 1





    I'm pretty sure you do have print-gensym, you likely just looked at the wrong place (try C-h o instead of C-h f). The let* in your expanded code is likely generated by macroexp-let2 which uses make-symbol rather than gensym.

    – Stefan
    Mar 11 at 19:01














6












6








6


1






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?










share|improve this question
















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?







elisp-macros setf






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 11 at 13:40









Drew

48.8k463107




48.8k463107










asked Mar 11 at 8:40









phsphs

534212




534212








  • 2





    OK. I understand now. The two 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)) returns nil.

    – phs
    Mar 11 at 9:58








  • 1





    Strangely, the code for setf in source file gv.el seems to create the v symbols with a vanilla use of (gensym "v") and this should append a counter value after the "v" prefix, creating uninterned symbols v0, v1, v2, etc.

    – phs
    Mar 11 at 10:05






  • 2





    You might like to play with print-gensym to better see what's going on.

    – Stefan
    Mar 11 at 12:35











  • @stefan: I have emacs-26.1 and it has no print-gensym AFAICT :-( Does anyone have an explanation why the (gensym "v") in source file gv.el does not append gensym-counter ?!

    – phs
    Mar 11 at 13:59








  • 1





    I'm pretty sure you do have print-gensym, you likely just looked at the wrong place (try C-h o instead of C-h f). The let* in your expanded code is likely generated by macroexp-let2 which uses make-symbol rather than gensym.

    – Stefan
    Mar 11 at 19:01














  • 2





    OK. I understand now. The two 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)) returns nil.

    – phs
    Mar 11 at 9:58








  • 1





    Strangely, the code for setf in source file gv.el seems to create the v symbols with a vanilla use of (gensym "v") and this should append a counter value after the "v" prefix, creating uninterned symbols v0, v1, v2, etc.

    – phs
    Mar 11 at 10:05






  • 2





    You might like to play with print-gensym to better see what's going on.

    – Stefan
    Mar 11 at 12:35











  • @stefan: I have emacs-26.1 and it has no print-gensym AFAICT :-( Does anyone have an explanation why the (gensym "v") in source file gv.el does not append gensym-counter ?!

    – phs
    Mar 11 at 13:59








  • 1





    I'm pretty sure you do have print-gensym, you likely just looked at the wrong place (try C-h o instead of C-h f). The let* in your expanded code is likely generated by macroexp-let2 which uses make-symbol rather than gensym.

    – Stefan
    Mar 11 at 19:01








2




2





OK. I understand now. The two 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)) returns nil.

– phs
Mar 11 at 9:58







OK. I understand now. The two 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)) returns nil.

– phs
Mar 11 at 9:58






1




1





Strangely, the code for setf in source file gv.el seems to create the v symbols with a vanilla use of (gensym "v") and this should append a counter value after the "v" prefix, creating uninterned symbols v0, v1, v2, etc.

– phs
Mar 11 at 10:05





Strangely, the code for setf in source file gv.el seems to create the v symbols with a vanilla use of (gensym "v") and this should append a counter value after the "v" prefix, creating uninterned symbols v0, v1, v2, etc.

– phs
Mar 11 at 10:05




2




2





You might like to play with print-gensym to better see what's going on.

– Stefan
Mar 11 at 12:35





You might like to play with print-gensym to better see what's going on.

– Stefan
Mar 11 at 12:35













@stefan: I have emacs-26.1 and it has no print-gensym AFAICT :-( Does anyone have an explanation why the (gensym "v") in source file gv.el does not append gensym-counter ?!

– phs
Mar 11 at 13:59







@stefan: I have emacs-26.1 and it has no print-gensym AFAICT :-( Does anyone have an explanation why the (gensym "v") in source file gv.el does not append gensym-counter ?!

– phs
Mar 11 at 13:59






1




1





I'm pretty sure you do have print-gensym, you likely just looked at the wrong place (try C-h o instead of C-h f). The let* in your expanded code is likely generated by macroexp-let2 which uses make-symbol rather than gensym.

– Stefan
Mar 11 at 19:01





I'm pretty sure you do have print-gensym, you likely just looked at the wrong place (try C-h o instead of C-h f). The let* in your expanded code is likely generated by macroexp-let2 which uses make-symbol rather than gensym.

– Stefan
Mar 11 at 19:01










1 Answer
1






active

oldest

votes


















8














From your comment you've figured this out for yourself, but...



In the macro expansion you're seeing the printed representation of two independent symbols with the same name. Most likely both of those symbols are uninterned.



A printed representation like this, if passed back to the lisp reader, would not be equivalent to the original, as the lisp reader would intern the symbols.



This is similar to:



(list (make-symbol "v") (make-symbol "v"))
(v v)





share|improve this answer



















  • 3





    Worth noting that setting print-gensym and print-circle to t produces a printed representation which can read back to something equivalent.

    – npostavs
    Mar 11 at 22:31











Your Answer








StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "583"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2femacs.stackexchange.com%2fquestions%2f48257%2fsetf-weird-expansion%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









8














From your comment you've figured this out for yourself, but...



In the macro expansion you're seeing the printed representation of two independent symbols with the same name. Most likely both of those symbols are uninterned.



A printed representation like this, if passed back to the lisp reader, would not be equivalent to the original, as the lisp reader would intern the symbols.



This is similar to:



(list (make-symbol "v") (make-symbol "v"))
(v v)





share|improve this answer



















  • 3





    Worth noting that setting print-gensym and print-circle to t produces a printed representation which can read back to something equivalent.

    – npostavs
    Mar 11 at 22:31
















8














From your comment you've figured this out for yourself, but...



In the macro expansion you're seeing the printed representation of two independent symbols with the same name. Most likely both of those symbols are uninterned.



A printed representation like this, if passed back to the lisp reader, would not be equivalent to the original, as the lisp reader would intern the symbols.



This is similar to:



(list (make-symbol "v") (make-symbol "v"))
(v v)





share|improve this answer



















  • 3





    Worth noting that setting print-gensym and print-circle to t produces a printed representation which can read back to something equivalent.

    – npostavs
    Mar 11 at 22:31














8












8








8







From your comment you've figured this out for yourself, but...



In the macro expansion you're seeing the printed representation of two independent symbols with the same name. Most likely both of those symbols are uninterned.



A printed representation like this, if passed back to the lisp reader, would not be equivalent to the original, as the lisp reader would intern the symbols.



This is similar to:



(list (make-symbol "v") (make-symbol "v"))
(v v)





share|improve this answer













From your comment you've figured this out for yourself, but...



In the macro expansion you're seeing the printed representation of two independent symbols with the same name. Most likely both of those symbols are uninterned.



A printed representation like this, if passed back to the lisp reader, would not be equivalent to the original, as the lisp reader would intern the symbols.



This is similar to:



(list (make-symbol "v") (make-symbol "v"))
(v v)






share|improve this answer












share|improve this answer



share|improve this answer










answered Mar 11 at 10:16









philsphils

27.8k23769




27.8k23769








  • 3





    Worth noting that setting print-gensym and print-circle to t produces a printed representation which can read back to something equivalent.

    – npostavs
    Mar 11 at 22:31














  • 3





    Worth noting that setting print-gensym and print-circle to t produces a printed representation which can read back to something equivalent.

    – npostavs
    Mar 11 at 22:31








3




3





Worth noting that setting print-gensym and print-circle to t produces a printed representation which can read back to something equivalent.

– npostavs
Mar 11 at 22:31





Worth noting that setting print-gensym and print-circle to t produces a printed representation which can read back to something equivalent.

– npostavs
Mar 11 at 22:31


















draft saved

draft discarded




















































Thanks for contributing an answer to Emacs Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2femacs.stackexchange.com%2fquestions%2f48257%2fsetf-weird-expansion%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Biblatex bibliography style without URLs when DOI exists (in Overleaf with Zotero bibliography)

ComboBox Display Member on multiple fields

Is it possible to collect Nectar points via Trainline?