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?
scheme racket
add a comment |
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?
scheme racket
add a comment |
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?
scheme racket
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
scheme racket
edited Nov 11 at 3:46
Cœur
17k9102140
17k9102140
asked Jun 2 '14 at 5:38
user3672728
196
196
add a comment |
add a comment |
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?
then it would be this [(empty? arbol) empty ] Thanks :)
– user3672728
Jun 2 '14 at 8:20
add a comment |
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?
then it would be this [(empty? arbol) empty ] Thanks :)
– user3672728
Jun 2 '14 at 8:20
add a comment |
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?
then it would be this [(empty? arbol) empty ] Thanks :)
– user3672728
Jun 2 '14 at 8:20
add a comment |
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?
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?
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
add a comment |
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
add a comment |
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%2f23987932%2flist-even-values-of-a-tree-in-scheme%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