What is the correct represention of (a (b . c) d) in box notation?
I am doing the exercises in Paul Graham's ANSI Common Lisp. And I have had a key to the exercises by other person, which is:
http://www.shido.info/lisp/pacl2_e.html
After having finished the exercises for Chapter 3, I refer to that key to check my answers one by one. When it gets to the represention of (a (b . c) d)
, I find that I cannot understand Shido's answer, which is:
http://www.shido.info/lisp/acl3-1d75.png
What exactly puzzled me is that in his answer d
is not followed by nil
.
So is his answer right? What is the correct represention of (a (b . c) d)
indeed?
lisp common-lisp
add a comment |
I am doing the exercises in Paul Graham's ANSI Common Lisp. And I have had a key to the exercises by other person, which is:
http://www.shido.info/lisp/pacl2_e.html
After having finished the exercises for Chapter 3, I refer to that key to check my answers one by one. When it gets to the represention of (a (b . c) d)
, I find that I cannot understand Shido's answer, which is:
http://www.shido.info/lisp/acl3-1d75.png
What exactly puzzled me is that in his answer d
is not followed by nil
.
So is his answer right? What is the correct represention of (a (b . c) d)
indeed?
lisp common-lisp
Shido's answer represents(a (b . c) . d)
– lurker
Jan 8 at 0:32
add a comment |
I am doing the exercises in Paul Graham's ANSI Common Lisp. And I have had a key to the exercises by other person, which is:
http://www.shido.info/lisp/pacl2_e.html
After having finished the exercises for Chapter 3, I refer to that key to check my answers one by one. When it gets to the represention of (a (b . c) d)
, I find that I cannot understand Shido's answer, which is:
http://www.shido.info/lisp/acl3-1d75.png
What exactly puzzled me is that in his answer d
is not followed by nil
.
So is his answer right? What is the correct represention of (a (b . c) d)
indeed?
lisp common-lisp
I am doing the exercises in Paul Graham's ANSI Common Lisp. And I have had a key to the exercises by other person, which is:
http://www.shido.info/lisp/pacl2_e.html
After having finished the exercises for Chapter 3, I refer to that key to check my answers one by one. When it gets to the represention of (a (b . c) d)
, I find that I cannot understand Shido's answer, which is:
http://www.shido.info/lisp/acl3-1d75.png
What exactly puzzled me is that in his answer d
is not followed by nil
.
So is his answer right? What is the correct represention of (a (b . c) d)
indeed?
lisp common-lisp
lisp common-lisp
edited Dec 31 '18 at 11:29
1MinLeft
asked Dec 31 '18 at 11:16
1MinLeft1MinLeft
336
336
Shido's answer represents(a (b . c) . d)
– lurker
Jan 8 at 0:32
add a comment |
Shido's answer represents(a (b . c) . d)
– lurker
Jan 8 at 0:32
Shido's answer represents
(a (b . c) . d)
– lurker
Jan 8 at 0:32
Shido's answer represents
(a (b . c) . d)
– lurker
Jan 8 at 0:32
add a comment |
2 Answers
2
active
oldest
votes
You can use the sdraw program:
(load "sdraw.generic.lisp")
(sdraw '(a (b . c) d))
[*|*]--->[*|*]------->[*|*]--->NIL
| | |
v v v
A [*|*]--->C D
|
v
B
From this you can see that your idea is correct.
add a comment |
The way to answer questions like this is to get the system to answer them for you. Unfortunately doing this properly requires understanding of how the CL printing system works which is not that simple (in fact: I have forgotten how to do this properly!). But you can write a mindless function which turns things into strings and which uses the object system to turn various sorts of things into strings in a way which is suitable. This isn't going to work for objects which are not conses but which contain conses, but it is quite adequate for simple purposes:
(defgeneric thing->string (thing)
(:method ((thing t))
;; any kind of thing we don't know about gets printed like this
(format nil "~A" thing))
(:method ((thing cons))
;; conses get printed like this
(format nil "(~A . ~A)"
(thing->string (car thing))
(thing->string (cdr thing)))))
Now: (thing->string ...)
will answer your question.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
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: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
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%2fstackoverflow.com%2fquestions%2f53986804%2fwhat-is-the-correct-represention-of-a-b-c-d-in-box-notation%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
You can use the sdraw program:
(load "sdraw.generic.lisp")
(sdraw '(a (b . c) d))
[*|*]--->[*|*]------->[*|*]--->NIL
| | |
v v v
A [*|*]--->C D
|
v
B
From this you can see that your idea is correct.
add a comment |
You can use the sdraw program:
(load "sdraw.generic.lisp")
(sdraw '(a (b . c) d))
[*|*]--->[*|*]------->[*|*]--->NIL
| | |
v v v
A [*|*]--->C D
|
v
B
From this you can see that your idea is correct.
add a comment |
You can use the sdraw program:
(load "sdraw.generic.lisp")
(sdraw '(a (b . c) d))
[*|*]--->[*|*]------->[*|*]--->NIL
| | |
v v v
A [*|*]--->C D
|
v
B
From this you can see that your idea is correct.
You can use the sdraw program:
(load "sdraw.generic.lisp")
(sdraw '(a (b . c) d))
[*|*]--->[*|*]------->[*|*]--->NIL
| | |
v v v
A [*|*]--->C D
|
v
B
From this you can see that your idea is correct.
answered Dec 31 '18 at 14:45
RenzoRenzo
17.5k43043
17.5k43043
add a comment |
add a comment |
The way to answer questions like this is to get the system to answer them for you. Unfortunately doing this properly requires understanding of how the CL printing system works which is not that simple (in fact: I have forgotten how to do this properly!). But you can write a mindless function which turns things into strings and which uses the object system to turn various sorts of things into strings in a way which is suitable. This isn't going to work for objects which are not conses but which contain conses, but it is quite adequate for simple purposes:
(defgeneric thing->string (thing)
(:method ((thing t))
;; any kind of thing we don't know about gets printed like this
(format nil "~A" thing))
(:method ((thing cons))
;; conses get printed like this
(format nil "(~A . ~A)"
(thing->string (car thing))
(thing->string (cdr thing)))))
Now: (thing->string ...)
will answer your question.
add a comment |
The way to answer questions like this is to get the system to answer them for you. Unfortunately doing this properly requires understanding of how the CL printing system works which is not that simple (in fact: I have forgotten how to do this properly!). But you can write a mindless function which turns things into strings and which uses the object system to turn various sorts of things into strings in a way which is suitable. This isn't going to work for objects which are not conses but which contain conses, but it is quite adequate for simple purposes:
(defgeneric thing->string (thing)
(:method ((thing t))
;; any kind of thing we don't know about gets printed like this
(format nil "~A" thing))
(:method ((thing cons))
;; conses get printed like this
(format nil "(~A . ~A)"
(thing->string (car thing))
(thing->string (cdr thing)))))
Now: (thing->string ...)
will answer your question.
add a comment |
The way to answer questions like this is to get the system to answer them for you. Unfortunately doing this properly requires understanding of how the CL printing system works which is not that simple (in fact: I have forgotten how to do this properly!). But you can write a mindless function which turns things into strings and which uses the object system to turn various sorts of things into strings in a way which is suitable. This isn't going to work for objects which are not conses but which contain conses, but it is quite adequate for simple purposes:
(defgeneric thing->string (thing)
(:method ((thing t))
;; any kind of thing we don't know about gets printed like this
(format nil "~A" thing))
(:method ((thing cons))
;; conses get printed like this
(format nil "(~A . ~A)"
(thing->string (car thing))
(thing->string (cdr thing)))))
Now: (thing->string ...)
will answer your question.
The way to answer questions like this is to get the system to answer them for you. Unfortunately doing this properly requires understanding of how the CL printing system works which is not that simple (in fact: I have forgotten how to do this properly!). But you can write a mindless function which turns things into strings and which uses the object system to turn various sorts of things into strings in a way which is suitable. This isn't going to work for objects which are not conses but which contain conses, but it is quite adequate for simple purposes:
(defgeneric thing->string (thing)
(:method ((thing t))
;; any kind of thing we don't know about gets printed like this
(format nil "~A" thing))
(:method ((thing cons))
;; conses get printed like this
(format nil "(~A . ~A)"
(thing->string (car thing))
(thing->string (cdr thing)))))
Now: (thing->string ...)
will answer your question.
answered Dec 31 '18 at 12:33
tfbtfb
2,4021312
2,4021312
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- 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%2fstackoverflow.com%2fquestions%2f53986804%2fwhat-is-the-correct-represention-of-a-b-c-d-in-box-notation%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
Shido's answer represents
(a (b . c) . d)
– lurker
Jan 8 at 0:32