What is the correct represention of (a (b . c) d) in box notation?












1















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?










share|improve this question

























  • Shido's answer represents (a (b . c) . d)

    – lurker
    Jan 8 at 0:32
















1















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?










share|improve this question

























  • Shido's answer represents (a (b . c) . d)

    – lurker
    Jan 8 at 0:32














1












1








1








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?










share|improve this question
















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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



















  • 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












2 Answers
2






active

oldest

votes


















7














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.






share|improve this answer































    0














    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.






    share|improve this answer























      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
      });


      }
      });














      draft saved

      draft discarded


















      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









      7














      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.






      share|improve this answer




























        7














        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.






        share|improve this answer


























          7












          7








          7







          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.






          share|improve this answer













          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.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Dec 31 '18 at 14:45









          RenzoRenzo

          17.5k43043




          17.5k43043

























              0














              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.






              share|improve this answer




























                0














                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.






                share|improve this answer


























                  0












                  0








                  0







                  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.






                  share|improve this answer













                  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.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Dec 31 '18 at 12:33









                  tfbtfb

                  2,4021312




                  2,4021312






























                      draft saved

                      draft discarded




















































                      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.




                      draft saved


                      draft discarded














                      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





















































                      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

                      Monofisismo

                      Angular Downloading a file using contenturl with Basic Authentication

                      Olmecas