In a programming class I take, we briefly (very briefly) touched lambda calculus. I think I have a pretty good grasp of the basics now, but one example given I just don't understand. Am I missing something or is the example possibly false?
$\lambda x.x \; (\lambda y.2*y) \; square \; 3$
The solution to this was $6$, because $\lambda x.x$ (the first function) is applied to $square$ (the first input) which just "disappears" and $\lambda y.2*y$ is applied to $3$, which gives us $6$:
$\lambda x.x \ (\lambda y.2*y) \ square \ 3 \implies (\lambda y.2*y) \ 3 \implies 2 * 3 \implies 6$
EDIT
Regardless of whether the "disappearance" of $square$ is correct, why would the first step be to apply $\lambda x.x$ to $square$ ? Instead of the whole expression, or just the part in parenthesis (which would, afaict, give the same result). I.e., what way of parenthesising is implied from the way it's written above?
/EDIT
The way I understand it, it should be either 18, because:
$\lambda x.x \; (\lambda y.2*y) \; square \; 3$ with parenthesis should be:
$(((\lambda x.x \; (\lambda y.2*y)) \; square) \; 3)$ which gives me:
$(((\lambda y.2*y) \; square) \; 3) \implies ((2*square) \; 3) \implies 2 * square(3) \implies 2 * 9 \implies 18$
or nothing at all, i.e. $((2*square) \; 3)$ doesn't make sense.
Another example that was given:
$(\lambda f.(\lambda x.f(f \; x))) \; square \; 3 \implies (\lambda x.square(square \;x)) \;3 \implies square(square \; 3) \implies square(9) \implies 81$
This second example seems clear to me, I'm just adding it to show something similar.
How would one properly solve $\lambda x.x \; (\lambda y.2*y) \; square \; 3$ ?