PLQ #5Done on:   Tuesday, February 23rd

Question 1 @ 2021-02-23 18:21

What should I name bar?

(define (foo x)
  (lambda (y) (+ x y)))
(define bar (foo 5))
(bar 12)

Question 2 @ 2021-02-23 18:24

We run this program in the FLANG interpreter that uses environments and closures:

;; Reminder:
(define-type ENV
  [EmptyEnv]
  [Extend Symbol VAL ENV])

(run "{with {x 3}
        {with {f {fun {y} {+ x y}}}
          {with {x 5}
            {call f 4}}}}")

When we execute the body of f, what does env look like?

(Technically, the values should be in NumVs, but it’s simplified away.)


Question 3 @ 2021-02-23 18:27

What do we get if we run the following code:

(define (foobar)
  (+ x y z))

(define (fun z)
  (foobar))

(let* ([x 2] [y 4]) ; same as two nested `let`s
  (fun 3))

(Choose the best answer.)


Question 4 @ 2021-02-23 18:31

What happens when we run the following in Racket?

(define x (make-parameter 10))

(define (div-by y)
  (/ (x) y))

(let ([x 50])
  (let ([f (lambda (y) (parameterize ([x x]) (div-by y)))])
    (f 5)))

Question 5 @ 2021-02-23 18:34

Which one of the following statements is correct?