question about function definition



Your suggestion looks good to me.  the original question suggests a
misunderstanding of programming language conventions.
in %i15, i is a parameter to the function template and logically speaking is
"bound"  and then used in the function body.
 
The obvious way of making the definition for w[1](x)  is to write
w[1](x):=x
 and your friend might consider if that makes more sense than i:1   etc.
RJF
 


  _____  

From: maxima-bounces at math.utexas.edu [mailto:maxima-bounces at math.utexas.edu]
On Behalf Of Barton Willis
Sent: Wednesday, September 05, 2007 8:19 AM
To: maxima at math.utexas.edu
Subject: question about function definition



A user (and friend) asked me:

I've been using Maxima for a project at work but have a little problem
defining arrays of functions: 
  
(%i13) kill(w); 
(%o13) done 
(%i14) i:1; 
(%o14) 1 
(%i15) w[i](t) := t^i; 
(%o15) w[i](t):=t^i 
(%i16) w[2](t); 
(%o16) t^2 
  
The assignment %i15 seems to think i is a free variable instead of having
the fixed value of 1. How can I change %i15 so only w[1] is affected? 
I suggested:

(%i1) i : 1$ 
(%i2) define (w[i](x), x^i); 
(%o2) w[1](x):=x 

(%i3) w[1](z); 
(%o3) z 

(%i4) w[1]; 
(%o4) lambda([x],x) 

(%i5) w[2](42); 
(%o5) w[2](42) 

but I'm not an expert with such things.  Is there a better way? 

BW