PLQ #3Done on:   Tuesday, February 9th

Question 1 @ 2021-02-09 18:20

Take the following WAE expression:

      \v/
{with {x x} x}
      /^\

Which kind of an identifier is the FIRST occurrence of x?

  1. Binding.
  2. Bound.
  3. Free.
  4. Lazy.
  5. Eager.

Question 2 @ 2021-02-09 18:22

Take the following WAE expression:

        \v/
{with {x x} x}
        /^\

Which kind of an identifier is the SECOND occurrence of x?

  1. Binding.
  2. Bound.
  3. Free.
  4. Lazy.
  5. Eager.

Question 3 @ 2021-02-09 18:24

Take the following WAE expression:

          \v/
{with {x x} x}
          /^\

Which kind of an identifier is the THIRD occurrence of x?

  1. Binding.
  2. Bound.
  3. Free.
  4. Lazy.
  5. Eager.

Question 4 @ 2021-02-09 18:25

The scope of an identifier…

  1. … is nonsensical, scope is something “of a program”.
  2. … is a lexical (static) property of code.
  3. … is a dynamic runtime property of code.
  4. … cannot be determined without running the code.
  5. … depends on whether we have an eager or a lazy language implementation.
  6. … depends on whether the identifier is bound or free.

Question 5 @ 2021-02-09 18:28

Last time, we have seen the implementation of the WAE evaluator, specifically, this was the evaluation fragment for with:

[(With bound-id named-expr bound-body)
(eval (subst bound-body
              bound-id
              (Num (eval named-expr))))]

We saw that there is a simple way to make it into a lazy binder. How do we do that?

  1. This is already the lazy implementation!
  2. Remove the eval in the last line.
  3. Remove the Num in the last line.
  4. Remove both the Num and the eval in the last line.
  5. Add a subst around the named-expr too.
  6. The actual change needs to be in subst, which needs to always go into the named-expr part.

Question 6 @ 2021-02-09 18:30

Alice has excited about intsets from HW#2, so she wrote some code to find out the length of a (normalized) set:

(: intset-length : INTSET -> Integer)
(define (intset-length set)
  (cases set
    [(Num n) 1]
    [(Range lhs rhs) (+ (- rhs lhs) 1)]
    [(2Sets lhs rhs) (+ (intset-length lhs) (intset-length rhs))]))

Bob says that Alice should add an else clause:

    [else (error "unexpected intset variant")]

Is this correct?

A. No. B. Yes. C. No, adding an else will essentially remove the advantage we get from the Type checker. D. Yes, we need to cover all possible cases. An else clause will help covering additional cases if the INTSET type gets extended. E. No, because adding an else will cause a type error. F. Yes, adding an else is always a good idea, especially for conditionals in a Typed language.