Setf weird expansion
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
add a comment |
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
2
OK. I understand now. The twov
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
.
– phs
16 hours ago
1
Strangely, the code forsetf
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.
– phs
16 hours ago
1
You might like to play withprint-gensym
to better see what's going on.
– Stefan
13 hours ago
@stefan: I have emacs-26.1 and it has noprint-gensym
AFAICT :-( Does anyone have an explanation why the(gensym "v")
in source filegv.el
does not appendgensym-counter
?!
– phs
12 hours ago
I'm pretty sure you do haveprint-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
.
– Stefan
7 hours ago
add a comment |
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
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
elisp-macros setf
edited 12 hours ago
Drew
48.6k463107
48.6k463107
asked 17 hours ago
phsphs
522212
522212
2
OK. I understand now. The twov
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
.
– phs
16 hours ago
1
Strangely, the code forsetf
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.
– phs
16 hours ago
1
You might like to play withprint-gensym
to better see what's going on.
– Stefan
13 hours ago
@stefan: I have emacs-26.1 and it has noprint-gensym
AFAICT :-( Does anyone have an explanation why the(gensym "v")
in source filegv.el
does not appendgensym-counter
?!
– phs
12 hours ago
I'm pretty sure you do haveprint-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
.
– Stefan
7 hours ago
add a comment |
2
OK. I understand now. The twov
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
.
– phs
16 hours ago
1
Strangely, the code forsetf
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.
– phs
16 hours ago
1
You might like to play withprint-gensym
to better see what's going on.
– Stefan
13 hours ago
@stefan: I have emacs-26.1 and it has noprint-gensym
AFAICT :-( Does anyone have an explanation why the(gensym "v")
in source filegv.el
does not appendgensym-counter
?!
– phs
12 hours ago
I'm pretty sure you do haveprint-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
.
– 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
add a comment |
1 Answer
1
active
oldest
votes
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)
1
Worth noting that settingprint-gensym
andprint-circle
tot
produces a printed representation which can read back to something equivalent.
– npostavs
3 hours ago
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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)
1
Worth noting that settingprint-gensym
andprint-circle
tot
produces a printed representation which can read back to something equivalent.
– npostavs
3 hours ago
add a comment |
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)
1
Worth noting that settingprint-gensym
andprint-circle
tot
produces a printed representation which can read back to something equivalent.
– npostavs
3 hours ago
add a comment |
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)
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)
answered 16 hours ago
philsphils
27.6k23769
27.6k23769
1
Worth noting that settingprint-gensym
andprint-circle
tot
produces a printed representation which can read back to something equivalent.
– npostavs
3 hours ago
add a comment |
1
Worth noting that settingprint-gensym
andprint-circle
tot
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
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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))
returnsnil
.– phs
16 hours ago
1
Strangely, the code for
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.– 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 filegv.el
does not appendgensym-counter
?!– phs
12 hours ago
I'm pretty sure you do have
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
.– Stefan
7 hours ago