PLQ #9Done on:   Tuesday, November 12th

Question 1 @ 2024-11-12 18:44

What’s the purpose of a compiler — what does it do?

(Choose the best answer.)


Question 2 @ 2024-11-12 18:45

What’s wrong with the following compiler?

(define (compile expr)
  (cases expr
    [(Num n)  (lambda ([env : ENV]) (RktV n))]
    [(Id name) (lambda ([env : ENV]) (lookup name env))]
    ...
    [(Call fun-expr arg-exprs)
    (define cfun (compile fun-expr))
    (define compiled-args (map compile arg-exprs))
    (lambda ([env : ENV])
      (define fval ...)
      (define arg-vals ...)
      (cases fval
        [(FunV names body fun-env)
          (define compiled-body (compile body))
          (compiled-body (extend names arg-vals fun-env))]
        ...))]
    ...))

Question 3 @ 2024-11-12 18:48

What will the following evaluate to in the lazy PL language?

(define (my-if cond then else) (if cond then else))
(my-if (list (/ 1 0)) 0 1)

Question 4 @ 2024-11-12 18:49

We know that we can define if as a plain function in lazy Racket:

(define (my-if cond then else) (if cond then else))

And in fact, if (the builtin value) is itself a function. Can the same be said on cond?


Yes, No

Question 5 @ 2024-11-12 18:51

Assume this code in the lazy PL language:

(define foo (cons 1 (cons 2 (cons 3 bar))))
(define bar (cons 'boom (map add1 foo)))

How does the value that foo is bound to look like?


Question 6 @ 2024-11-12 18:54

Of the following Racket (or #lang pl) features, which ones are side-effects?


if set-box! unbox random define error