Answered You can hire a professional tutor to get the answer.

QUESTION

CSE 413, Spring 2011, Assignment 4 Due: Tuesday 3 May, 11:00PM Set-up:scm, which is on the course website. In particular, replace occurrences of...

Please read the specification provided in the pdf file attached to this. Then, add necessary code to the starter code pasted below. Thanks!;; CSE413, Spring 2011, Homework 4 starter code;; definition of structures for MUPL programs(define-struct var (string)) ;; a variable, e.g., (make-var "foo");; a constant number, e.g., (make-int 17)(define-struct add (e1 e2)) ;; add two expressions(define-struct ifgreater (e1 e2 e3 e4));;if e1 > e2 then e3 else e4(define-struct fun (nameopt formal body)) ;; a recursive(?) 1-argument function(define-struct app (funexp actual)) ;; function application(define-struct mlet (var e body)) ;; a mlet expression (let var = e in body) (define-struct apair (e1 e2)) ;; make a new pair;; get first part of an apair;; get second part of an apair;; unit value -- good for ending a list;; evaluate to 1 if e is aunit else 0;; a closure is not in "source" programs; it's what functions evaluate to(define-struct closure (env fun)) ;; These just make writing MUPL programs more convenient(define V make-var)(define I make-int);; lookup a variable in an environment(define (envlookup env str) (cond [(null? env) (error "unbound variable during evaluation" str)][(equal? (caar env) str) (cdar env)][#t (envlookup (cdr env) str)]));; The interpreter(define (eval-prog p) (letrec([f (lambda (env p)(cond [(add? p) (let ([v1 (f env (add-e1 p))][v2 (f env (add-e2 p))])(if (and (int? v1)(int? v2))(make-int (+ (int-num v1) (int-num v2)))(error "MUPL addition applied to non-number")))];; CHANGE you need to add 11 more cases to this cond[#t (error "bad MUPL expression")]))])"CHANGE (to call f appropriately)"))(define (ifaunit e1 e2 e3) "CHANGE")(define (mlet* lstlst e2) "CHANGE") (define (ifeq e1 e2 e3 e4) "CHANGE")(define mupl-map "CHANGE")(define mupl-mapAddN (mlet "map" mupl-map"CHANGE (notice map is now in scope)"));; a simple test case and associated code -- no need to change it;; (though you will likely want more tests of course)(define (list-to-mupllist lst) (if (null? lst)(make-aunit)(make-apair (car lst) (list-to-mupllist (cdr lst)))))(define (muplintlist-to-list lst) (cond [(aunit? lst) ()][(apair? lst) (if (int? (apair-e1 lst))(cons (int-num (apair-e1 lst)) (muplintlist-to-list (apair-e2 lst)))(error "muplintlist-to-list"))][#t (error "muplintlist-to-list")]))(define (test-addN) (eval-prog (make-app (make-app mupl-mapAddN (I 7))(list-to-mupllist (list (I 3) (I 4) (I 9))))))

Show more
Files: hw4.pdf
LEARN MORE EFFECTIVELY AND GET BETTER GRADES!
Ask a Question