list even values of a tree in scheme











up vote
0
down vote

favorite












Write a program that returns the list of even numbers of a tree



I do this:



(define (list_pares arbol)
(cond
[(empty? arbol) 0]
[(and (es-hoja? arbol) (even? (dato-tree arbol)))
(list (dato-tree arbol))]
[else
(cond
[(even? (dato-tree arbol))
(append (list (dato-tree arbol))
(list_pares (left-tree arbol))
(list_pares (right-tree arbol)))]
[else
(append
(list_pares (left-tree arbol))
(list_pares (right-tree arbol)))])]))


But when run:



(list_pares (list 2 empty (list 5 (list 4 empty empty) (list 9 (list 6 empty empty) empty))))


returns me this error:



append: last argument must be a list, but received 0


how could it?










share|improve this question




























    up vote
    0
    down vote

    favorite












    Write a program that returns the list of even numbers of a tree



    I do this:



    (define (list_pares arbol)
    (cond
    [(empty? arbol) 0]
    [(and (es-hoja? arbol) (even? (dato-tree arbol)))
    (list (dato-tree arbol))]
    [else
    (cond
    [(even? (dato-tree arbol))
    (append (list (dato-tree arbol))
    (list_pares (left-tree arbol))
    (list_pares (right-tree arbol)))]
    [else
    (append
    (list_pares (left-tree arbol))
    (list_pares (right-tree arbol)))])]))


    But when run:



    (list_pares (list 2 empty (list 5 (list 4 empty empty) (list 9 (list 6 empty empty) empty))))


    returns me this error:



    append: last argument must be a list, but received 0


    how could it?










    share|improve this question


























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      Write a program that returns the list of even numbers of a tree



      I do this:



      (define (list_pares arbol)
      (cond
      [(empty? arbol) 0]
      [(and (es-hoja? arbol) (even? (dato-tree arbol)))
      (list (dato-tree arbol))]
      [else
      (cond
      [(even? (dato-tree arbol))
      (append (list (dato-tree arbol))
      (list_pares (left-tree arbol))
      (list_pares (right-tree arbol)))]
      [else
      (append
      (list_pares (left-tree arbol))
      (list_pares (right-tree arbol)))])]))


      But when run:



      (list_pares (list 2 empty (list 5 (list 4 empty empty) (list 9 (list 6 empty empty) empty))))


      returns me this error:



      append: last argument must be a list, but received 0


      how could it?










      share|improve this question















      Write a program that returns the list of even numbers of a tree



      I do this:



      (define (list_pares arbol)
      (cond
      [(empty? arbol) 0]
      [(and (es-hoja? arbol) (even? (dato-tree arbol)))
      (list (dato-tree arbol))]
      [else
      (cond
      [(even? (dato-tree arbol))
      (append (list (dato-tree arbol))
      (list_pares (left-tree arbol))
      (list_pares (right-tree arbol)))]
      [else
      (append
      (list_pares (left-tree arbol))
      (list_pares (right-tree arbol)))])]))


      But when run:



      (list_pares (list 2 empty (list 5 (list 4 empty empty) (list 9 (list 6 empty empty) empty))))


      returns me this error:



      append: last argument must be a list, but received 0


      how could it?







      scheme racket






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 11 at 3:46









      Cœur

      17k9102140




      17k9102140










      asked Jun 2 '14 at 5:38









      user3672728

      196




      196
























          1 Answer
          1






          active

          oldest

          votes

















          up vote
          0
          down vote



          accepted










          Your error message comes from this:



           [(empty? arbol) 0]


          So when the resursion where you append the result end with an 0 instead of an empty list you get this problem because (append '(something) 0 '(something else)) is not allowed.



          What should you really return if you are given an empty tree and should return a list of even values from it?






          share|improve this answer





















          • then it would be this [(empty? arbol) empty ] Thanks :)
            – user3672728
            Jun 2 '14 at 8:20











          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',
          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%2f23987932%2flist-even-values-of-a-tree-in-scheme%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








          up vote
          0
          down vote



          accepted










          Your error message comes from this:



           [(empty? arbol) 0]


          So when the resursion where you append the result end with an 0 instead of an empty list you get this problem because (append '(something) 0 '(something else)) is not allowed.



          What should you really return if you are given an empty tree and should return a list of even values from it?






          share|improve this answer





















          • then it would be this [(empty? arbol) empty ] Thanks :)
            – user3672728
            Jun 2 '14 at 8:20















          up vote
          0
          down vote



          accepted










          Your error message comes from this:



           [(empty? arbol) 0]


          So when the resursion where you append the result end with an 0 instead of an empty list you get this problem because (append '(something) 0 '(something else)) is not allowed.



          What should you really return if you are given an empty tree and should return a list of even values from it?






          share|improve this answer





















          • then it would be this [(empty? arbol) empty ] Thanks :)
            – user3672728
            Jun 2 '14 at 8:20













          up vote
          0
          down vote



          accepted







          up vote
          0
          down vote



          accepted






          Your error message comes from this:



           [(empty? arbol) 0]


          So when the resursion where you append the result end with an 0 instead of an empty list you get this problem because (append '(something) 0 '(something else)) is not allowed.



          What should you really return if you are given an empty tree and should return a list of even values from it?






          share|improve this answer












          Your error message comes from this:



           [(empty? arbol) 0]


          So when the resursion where you append the result end with an 0 instead of an empty list you get this problem because (append '(something) 0 '(something else)) is not allowed.



          What should you really return if you are given an empty tree and should return a list of even values from it?







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Jun 2 '14 at 8:09









          Sylwester

          33.5k22854




          33.5k22854












          • then it would be this [(empty? arbol) empty ] Thanks :)
            – user3672728
            Jun 2 '14 at 8:20


















          • then it would be this [(empty? arbol) empty ] Thanks :)
            – user3672728
            Jun 2 '14 at 8:20
















          then it would be this [(empty? arbol) empty ] Thanks :)
          – user3672728
          Jun 2 '14 at 8:20




          then it would be this [(empty? arbol) empty ] Thanks :)
          – user3672728
          Jun 2 '14 at 8:20


















           

          draft saved


          draft discarded



















































           


          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f23987932%2flist-even-values-of-a-tree-in-scheme%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

          List item for chat from Array inside array React Native

          Thiostrepton

          Caerphilly