Due: Tuesday, Sept 6th by 11:59 PM
In this assignment you will practice using Scheme expressions and values.
Use Racket to type expressions and see the resulting values. Make sure you use #lang eopl.
Record your answers in a plain text file. (Suggestion: use Notepad++.)
Question 1 [20 points]: What values are the results of the following Scheme expressions?
Expression (+ 2 (* 3 4)) (* 2 (+ 3 4)) (integer? 4/5) (* 4/5 5) (integer? (* 4/5 5)) (cons 'go '()) (cons 'go (cons 'west '())) (cons 'west (cons 'go '())) (cons 'go 'west) (pair? (cons 'go 'west)) (list? (cons 'go 'west))
Question 2 [40 points]: Create expressions which, when evaluated, will result in the following values. Important: you may not use quoting except to specify literal symbols (e.g., 'a) and the empty list ('()).
Note that values of the form #( ... ) are vectors.
Value a (a) (a b c) (a (b) c) (((a))) ((a) (b) (c)) #(a b c) #(#(a b) #(c)) #((a b) (c)) (a #(b) c)
In Questions 3-6, there is a pair of expressions and an expected value for each expression. In each expression, a variable f is used.
For each pair of expressions, give a definition of f that will cause each expression to evaluate to its expected value.
Expression Expected value (f 2 3) 5 (f 4 5) 9
A definition of f that causes the expressions to yield their expected values is
(define f (lambda (x y) (+ x y)))
Question 3 [10 points]:
Expression Expected value (f '(a b c)) b (f '(1 2 3)) 2
Question 4 [10 points]:
Expression Expected value (f '(a b)) (b a) (f '(17 42)) (42 17)
Question 5 [10 points]:
Expression Expected value (f car '(a b)) a (f cdr '(1 2 3)) (2 3)
Question 6 [10 points]:
Expression Expected value ((f 2) 3) 5 ((f 5) 6) 11
Submit your answers as a plain text file to Marmoset as assign1:
Do not submit a Word or OpenOffice document.
IMPORTANT: after uploading, you should download a copy of your submission and double-check it to make sure that it contains the correct file(s). You are responsible for making sure your submission is correct. You may receive a grade of 0 for an incorrectly submitted assignment.