# PLQ #3Done on:   Tuesday, February 8th

## Question 1 @ 2022-02-08 18:34

Examine the `eval` function below, which operates directly on the given S-expression instead of parsing it into an AST first.

(define (eval sexpr)
(match sexpr
[(number: n) n]
[(list '+ left right) (+ (eval left) (eval right))]
[(list '- left right) (- (eval left) (eval right))]
[else (error 'eval "bad syntax in ~s" sexpr)]))

Which of the following statement(s) is true?

• Separating semantics and syntax improves language extensibility.
• Separating semantics and syntax improves time/space complexity.
• Separating semantics and syntax improves ability to validate syntax.
• Separating semantics and syntax facilitates changes in syntax without affecting semantics.
• It is recommended that syntax and semantics be combined.

## Question 2 @ 2022-02-08 18:36

We defined substitution using which of the following terms?

(Choose all of the relevant terms)

• Compositionality
• Scope
• Bound occurrence
• Eager evaluation
• Lazy evaluation
• Binding instance
• Free occurrence
• Interpretation
• Compilation

## Question 3 @ 2022-02-08 18:40

Which should be a correct way of computing substitution?

Starting from:

{with {x {+ 5 5}} {+ x x}}

• `--> {+ {+ 5 5} {+ 5 5}} --> {+ 10 10} --> 20`
• `--> {with {x 10} {+ x x}} --> {+ 10 10} --> 20`
• `--> {with {x 20} {+ x x}} --> {+ 20 20} --> 40`
• `--> {with {x 10} {+ 10 10}} --> {+ 10 10} --> 20`

## Question 4 @ 2022-02-08 18:42

How would we interpret this: `e[v/x]`

• Evaluate `e` where `x` is substituted by `v`
• Evaluate `e` where `v` is substituted with `x`
• Evaluate `e` where the given parameter is equal to dividing `v` by `x`
• This is an example for “M-expression” syntax, which we’re not using
• Evaluate `v`, replace the `x`s in `e` by the result, and continue

## Question 5 @ 2022-02-08 18:43

What would this evaluate to?

{with {x y} 7}

If we were in our eager language, that would lead to a runtime error about `y` being unbound. But how would that change if we were using a lazy implementation (not evaluate the named expression)?

• That would make it a syntax error
• It is impossible, since we cannot use `y` as a value
• We will still get the same runtime error (“unbound y”)
• Same error but about `x` (“unbound x”)
• We will get a 7
• We will get some undefined value result (`void` in Racket)