

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!


The homework requires you to solve the following problems via scheme programming. You need to develop your scheme programs using the DrScheme environment and submit your solution file electronically at
www.cs.utsa.edu/~cs
(define Btree (lambda (parent left right) (if (and (null? left) (null? right)) parent (cons parent (cons left (cons right โ())))))) (PostOrderVisitBtree Btree โ()) (PostOrderVisitBtree Btree 7) (PostOrderVisitBtree Btree โ(+ 3 5)) (PostOrderVisitBtree Btree โ(+ (* 3 x) (- 5 y))) (PostOrderVisitBtree Btree โ(+ (* 3 x) (- 5 (/ 2 y))))
(define Op (lambda (x) (cond ((eq? x โ+) +) ((eq? x โ-) -) ((eq? x โ*) *) ((eq? x โ/) /) (else x) )))
(define Eval (lambda (parent left right) (if (and (number? left) (number? right)) ((Op parent) left right) (Btree parent left right))))
(PostOrderVisitBtree Eval2 โ()) (PostOrderVisitBtree Eval2 โ(+ 3 5)) (PostOrderVisitBtree Eval2 โ(+ (* 3 x) (+ 5 2))) (PostOrderVisitBtree Eval2 โ(+ (* 3 2) (- 5 (/ 108 2))))
The output from the above tests should be
empty 7 (list โ+ 3 5) (list โ+ (list โ* 3 โx) (list โ- 5 โy)) (list โ+ (list โ* 3 โx) (list โ- 5 (list โ/ 2 โy))) empty 8 (list โ+ (list โ* 3 โx) 7)
(define Tree (lambda (parent children) (if (null? children) parent (cons parent children))))
(define reduce (lambda (f0 f1 f2 x) (cond ((null? x) f0) (else (f2 (f1 (car x)) (reduce f0 f1 f2 (cdr x))))))) (define Eval (lambda (parent children) (if (and (cons? children) (reduce true number? (lambda (x y) (and x y)) childre (reduce 0 (lambda (x) x) (Op parent) children) (Tree parent children))))
(PostOrderVisitTree Tree โ()) (PostOrderVisitTree Tree 7) (PostOrderVisitTree Tree โ(+ 3 5 7 9)) (PostOrderVisitTree Tree โ(+ (* 3 x z) (- 5 y x))) (PostOrderVisitTree Tree โ(+ (* 3 x 7) (- 5 (/ 2 y 9))))
(PostOrderVisitTree Eval โ()) (PostOrderVisitTree Eval 7) (PostOrderVisitTree Eval โ(+ 3 5 7 9)) (PostOrderVisitTree Eval โ(+ (* 3 x z) (- 5 y x))) (PostOrderVisitTree Eval โ(+ (* 3 x 7) (- 5 (/ 2 y 9))))