## Question 1 @ 2022-10-04 19:15

Which of following is sensible and is formatted properly WRT indentation?

• (With 'y {Num 2}
{Mul {Id 'y} {Num 3}})
• (With {y 2}
{* y 3})
• {with {y 2}
{* y 3}}
• (With 'y
(Num 2)
(Mul (Id 'y) (Num 3)))
• {with {x 2} {* y 3})}
• (With {y (Num 2)} (Mul (Id 'y) (Num 3)))
• (With 'y (Num 2) (Mul (Id 'y) (Num 3)))

## Question 2 @ 2022-10-04 19:22

What would be the result of this expression using our (hack of a) lazy evaluation implementation?

{with {y x}
{with {x {/ 1 0}}
{+ 2 y}}}

• 1
• 2
• A bad syntax error
• A runtime error
• A compilation error
• An unbound `x` error

## Question 3 @ 2022-10-04 19:29

In WAE, we had this bit in our `subst` function:

[(With bound-id named-expr bound-body)
(With bound-id
(subst named-expr from to)
(if (eq? bound-id from)      ; <============
bound-body                  ; <=========
(subst bound-body from to)))]  ; <======

If we replace the marked line with `(subst bound-body from to)` in `subst` below, what would we get?

{with {x 5}
{+ x {with {x 3}
{with {y x} y}}}}

• `6`
• `8`
• `10`
• `Unbound X`
• `Unbound Y`
• `Bad Syntax`
• `Infinite loop`

## Question 4 @ 2022-10-04 19:37

Choose all options that explains the problem with the following definition of substitution in WAE?

Substitution definition: To substitute an identifier `i` in an expression `e` with an expression `v`, replace all instances of `i` that are not themselves binding instances, and that are not in any nested scope, with the expression `v`.

(Choose all of the correct answers)

• There is nothing wrong with this.

• This fails to distinguish between the binding instance and the bound instance of `i`.

• It fails to replace any instance of `i` that is in any nested scope of `j`, where `j` is different from `i`.

• It fails to replace any instance of `i` that is not itself a binding instance and is free in `e`.