Subject: Q about arguments scoping in function definition
From: Andrey Siver
Date: Mon, 8 Oct 2007 13:19:36 +0400
Dear all,
This question came to community
http://community.livejournal.com/maxima_platform/2524.html?view=10460#t10460
and I resend it to the russain mailing list and finally the author did not
get exhaustive answer. Here is MAXIMA code:
(%i1) f(x) := x*2;
(%o1) f(x) := x 2
(%i2) n : 100;
(%o2) 100
(%i3) t(n, f, x) := f(n+x);
(%o3) t(n, f, x) := f(n + x)
(%i4) s(a) := a*3;
(%o4) s(a) := a 3
(%i5) p(a) := t(2, s, a);
(%o5) p(a) := t(2, s, a)
(%i6) p(a);
(%o6) 2 (a + 2)
The questions are:
1) Why definition for s(a) did not substitute during the evaluation of p(a)?
But in the same time the definition for n in t(2,s,a) was applied.
2) When the substitution for f(x) was applied? If it were in (%i3) when the
output (%o3) is propably incorrect.
3) If we make diffinition of f(x) after the diffinition of t(n, f, x) then
the s(a) will be applied. It looks very strange that the definition of
t(n,f,x) depends on definition of f(x).
Best regards,
-Andrey