Problem 6: Tree in Scheme (100 pts)

Let's design a tree data abstraction in scheme! As tree in python, a tree has a label and branches -- a list of trees.

Hint: Recall the function-based tree ADT in python.

(define (tree label branches) 'YOUR-CODE-HERE ) (define (label t) 'YOUR-CODE-HERE ) (define (branches t) 'YOUR-CODE-HERE ) (define (is-leaf t) 'YOUR-CODE-HERE ) ; A tree for test (define t1 (tree 1 (list (tree 2 (list (tree 5 nil) (tree 6 (list (tree 8 nil))))) (tree 3 nil) (tree 4 (list (tree 7 nil)))))) ;;; Tests ; scm> (label t1) ; 1 ; scm> (label (car (branches t1))) ; 2 ; scm> (is-leaf (car (cdr (branches t1)))) ; #t ; scm> (branches (car (cdr (branches t1)))) ; ()

Test your implementation with ok:

$ python ok -q tree