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
|
show 1 more 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
Mar 11 at 9:58
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
Mar 11 at 10:05
2
You might like to play withprint-gensym
to better see what's going on.
– Stefan
Mar 11 at 12:35
@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
Mar 11 at 13:59
1
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
Mar 11 at 19:01
|
show 1 more 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 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 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
Mar 11 at 9:58
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
Mar 11 at 10:05
2
You might like to play withprint-gensym
to better see what's going on.
– Stefan
Mar 11 at 12:35
@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
Mar 11 at 13:59
1
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
Mar 11 at 19:01
|
show 1 more 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
Mar 11 at 9:58
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
Mar 11 at 10:05
2
You might like to play withprint-gensym
to better see what's going on.
– Stefan
Mar 11 at 12:35
@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
Mar 11 at 13:59
1
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
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
|
show 1 more 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)
3
Worth noting that settingprint-gensym
andprint-circle
tot
produces a printed representation which can read back to something equivalent.
– npostavs
Mar 11 at 22:31
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)
3
Worth noting that settingprint-gensym
andprint-circle
tot
produces a printed representation which can read back to something equivalent.
– npostavs
Mar 11 at 22:31
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)
3
Worth noting that settingprint-gensym
andprint-circle
tot
produces a printed representation which can read back to something equivalent.
– npostavs
Mar 11 at 22:31
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 Mar 11 at 10:16
philsphils
27.8k23769
27.8k23769
3
Worth noting that settingprint-gensym
andprint-circle
tot
produces a printed representation which can read back to something equivalent.
– npostavs
Mar 11 at 22:31
add a comment |
3
Worth noting that settingprint-gensym
andprint-circle
tot
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
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
Mar 11 at 9:58
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
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 filegv.el
does not appendgensym-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 (tryC-h o
instead ofC-h f
). Thelet*
in your expanded code is likely generated bymacroexp-let2
which usesmake-symbol
rather thangensym
.– Stefan
Mar 11 at 19:01