Loading...
intermediate
Problem 06 • Step 08
apply-twice
Every function you’ve written so far takes a number as input. apply-twice takes a function.
apply-twice(f)(x) applies f to x, then applies f again to the result. So apply-twice(double)(3) doubles 3 to get 6, then doubles 6 to get 12.
The structure is two nested lambdas — like max. But where max took two numbers, apply-twice takes a function and a value. The outer lambda receives f. The inner lambda receives x. The body needs to call f twice.
Think about what f(x) looks like in the language: it’s [f, x], a function call. Now, how do you feed that result into f again?