Loading...
intermediate
Problem 08 • Step 02
Remembering Two Values
box remembers one value. Now define pair, a function that remembers two values.
The problem: a function can only return one thing. But a pair has two values inside. How does the caller say which one it wants?
box ignored its inner parameter. pair can’t afford to. The caller needs to pass something, a signal, to indicate “give me the first” or “give me the second.” What’s the simplest signal you can think of?
evaluate(call(call(call("pair", 3), 4), ???)) // 3
evaluate(call(call(call("pair", 3), 4), ???)) // 4
pair takes three arguments one at a time (curried): first x, then y, then a selector. The selector decides which value comes out.