
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!

Please submit this homework electronically to [email protected].
(define sum (lambda (y) (cond ((null? y) 0) ((cons? y) (+ (car y) (sum (cdr y)))))))
(define EvalExp (lambda (exp) (cond ((number? exp) exp) ((eq? (car exp) โ+) (+ (EvalExp (cadr exp)) (EvalExp (caddr exp)))) ((eq? (car exp) โ-) (- (EvalExp (cadr exp)) (EvalExp (caddr exp)))))))
To see how the Scheme function work, you can test the given function in DrScheme with the following test cases
(EvalExp โ(+ (- 5 1) (+ 2 7))) 13 (EvalExp โ15) 15 (EvalExp โ(- (+ 1 9) 5)) 5
Your translation should use the following datatype definition.
datatype AST = Number of int | Plus of AST * AST | Minus of AST * AST;