# PLQ #7Done on:   Tuesday, March 8th

## Question 1 @ 2022-03-08 18:56

In Schlac, using our definitions and encoded values, what does the following code block evaluate to?

(if (lambda (x y) y)
((lambda (x) (x x)) (lambda (x) (x x)))
(* 3 5))

• It evaluates both results in parallel, giving us just 15 from the second branch.
• It evaluates to the encoded value of 15; since Schlac is a lazy language.
• It would never terminate, since evaluating the omega-combinator results in an infinite loop.
• It’s a syntax error: a curried language means that we would need to use `((* 3) 5)` as the second expression.
• This is not a valid Church encoding.

## Question 2 @ 2022-03-08 18:59

Which of the following is the combinator version of the Church encoding for the `cdr` function?

• `(lambda (a b) (a b a))`
• `(lambda (x) (x (lambda (x y) x)))`
• `(lambda (x) (x (lambda (x y) y)))`
• `(lambda (x y) (lambda (s) (s x y)))`
• `(lambda (n) (lambda (f x) (f (n f x))))`
• `(lambda (x) (x x))`

## Question 3 @ 2022-03-08 19:01

In class, we briefly discussed the difference the functionality of `bind` and and `bind*` from HW#8. What would the following code snippet evaluate to?

{bind {{x 1}}
{bind* {{x 2}
{y x}}
{bind {{x 3}}
y}}}

• 1
• 2
• 3
• Unbound identifier
• None of the above

## Question 4 @ 2022-03-08 19:04

How can the following Racket code be fixed so that we actually get the factorial of 4?

(let ([fact (lambda (n)
(if (= n 0)
1
(* n (fact (- n 1)))))])
(fact 4))

• We need to repeat the binding at least 4 times.
• Do nothing; dynamic scoping would make recursion immediately available.
• Replace the `let` with a `letrec`.
• Replace the `let` with a `let*`.
• We must define it as a locally recursive function, otherwise it won’t work.

## Question 5 @ 2022-03-08 19:07

In class last week, we briefly discussed `letrec` and its differences from `let*` and `let`. Which of the following answers is true about our extended FLANG language that has a proper `rec` recursive binder with no tricks and no Y combinator complexity?

• The implementation requires code with side effects.
• Recursive subtype declarations are needed to make it work.
• `{rec {x E1} E2}` is equivalent to `{call {fun {x} E2} E1}`.
• The environment must be functional so it can refer to itself.
• The evaluator must be lazy.
• We no longer need environments for the implementation.