You are mistaken and this is an excellent question to understand a small portion of the "Main Evaluation" that happens in every single Mathematica call. Let's start with a very simple expression
Print[1+1]
Why do you think Mathematica prints 2 and not 1+1, because this is what I told it to do? The answer is that the standard evaluation chain (read: the function does not handle its arguments in a special way), Mathematica always evaluates the arguments of a function before it calls the function. This means here that first 1+1 is evaluated to 2 and then Print[2]
is called.
Now look at your example and you understand easily, that you are searching your error in the wrong place. Let us assume, you have called your first line test0[..]
then a
has a value of 2. Now, apply the same rule I described above to the line
test0[2, test1[]]
What do you think happens if before test0
is even called, its arguments and especially test1[]
is evaluated. Do you see, that test1[]
does evaluate to 2? Therefore, your Return
line just gives the constant value 2 and not the result of calling test1
. The third result works the same way but in the meantime, you have assigned a new value to a
.
To solve this, you have to force Mathematica to keep your test1
argument unevaluated
test0[1, Unevaluated[test1[]]]
test0[2, Unevaluated[test1[]]]
test0[3, Unevaluated[test1[]]]