Loading...
intermediate
Problem 04 • Step 02
One Rule to Replace Eight
Look at the starting code. The eight operator rules are gone. In their place is a single "l op r" rule that receives three arguments: the left expression, the operator string, and the right expression.
Since every operator (+, -, *, /, <, >, ==, !=) is now a curried function in the environment, the expression [2, "+", 3] is just syntactic sugar for:
[["+", 2], 3]
Which means: look up "+", apply it to 2, then apply the result to 3.
Your "l op r" rule should convert the infix expression into this curried call form, and evaluate it.
TIP
You already have a call rule that handles nested function calls. Reuse it — just reshape the expression and pass it to evaluate.