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))
It already work fine!
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.