racket - list even values of a tree in scheme -
write program returns list of numbers of tree
i 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 error:
append: last argument must list, received 0
how it?
your error message comes this:
[(empty? arbol) 0]
so when resursion append result end 0 instead of empty list problem because (append '(something) 0 '(something else))
not allowed.
what should return if given empty tree , should return list of values it?
Comments
Post a Comment