

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!


CS 3721: Programming Languages Lab Lab #05: eval expression
Due date: February 26, 3:30pm. At the beginning of the next recitation.
Goals of this lab:
(code-modifier ’3 ’7 ’(* 3 (+ 3 5))) => (* 7 (+ 7 5)) (code-modifier ’+ ’* ’(lambda (x) (+ x x))) => (lambda (x) (* x x))
(eval ’(* 7 (+ 7 5))) => 84
(let ((f (eval ’(lambda (g x) (g x x))))) (f * 5)) ; let body => 25 What do the following expressions evaluate to? Please, fill in the blanks. (eval ’(- 7 12 5)) => _____ (eval (cons ’- ’(7 12 5))) => _____ (eval (cons ’- (cdr ’(7 12 5)))) => _____ The following expressions evaluate to 13, and 15, respectively. However, the expressions are not complete. Please, fill in the missing code. (eval (cons ’+ (cons (eval ’(+ 3 4)) (cons (eval ’(* 2 3)) _____ )))) => 13 (eval (cons ’+ (cons (eval ’(* 2 3)) (cons (eval ’(+ 3 4)) _____ )))) => 15 Now, using the eval expression, and your code-modifier function, write an expression that modifies the expression, (lambda (x y) (+ x y)) to (lambda (x y) (* x y)) and evaluates this modified function with the arguments 3, and 5. The result should be 15. (Hint: Think about building a convenient expression before passing it to the eval expression as an argument.)