Setf weird expansion












5















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
    16 hours ago








  • 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
    16 hours ago






  • 1





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

    – Stefan
    13 hours ago











  • @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
    12 hours ago













  • 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
    7 hours ago
















5















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
    16 hours ago








  • 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
    16 hours ago






  • 1





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

    – Stefan
    13 hours ago











  • @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
    12 hours ago













  • 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
    7 hours ago














5












5








5


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 12 hours ago









Drew

48.6k463107




48.6k463107










asked 17 hours ago









phsphs

522212




522212








  • 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
    16 hours ago








  • 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
    16 hours ago






  • 1





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

    – Stefan
    13 hours ago











  • @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
    12 hours ago













  • 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
    7 hours ago














  • 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
    16 hours ago








  • 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
    16 hours ago






  • 1





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

    – Stefan
    13 hours ago











  • @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
    12 hours ago













  • 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
    7 hours ago








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
16 hours ago







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
16 hours ago






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
16 hours ago





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
16 hours ago




1




1





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

– Stefan
13 hours ago





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

– Stefan
13 hours ago













@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
12 hours ago







@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
12 hours ago















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
7 hours ago





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
7 hours ago










1 Answer
1






active

oldest

votes


















7














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



















  • 1





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

    – npostavs
    3 hours ago











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









7














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



















  • 1





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

    – npostavs
    3 hours ago
















7














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



















  • 1





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

    – npostavs
    3 hours ago














7












7








7







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 16 hours ago









philsphils

27.6k23769




27.6k23769








  • 1





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

    – npostavs
    3 hours ago














  • 1





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

    – npostavs
    3 hours ago








1




1





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

– npostavs
3 hours ago





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

– npostavs
3 hours ago


















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

How to label and detect the document text images

Vallis Paradisi

Tabula Rosettana