Mathematica 9 is now available
Student Support Forum
-----
Student Support Forum: 'pure function arguement problem' topicStudent Support Forum > General > Archives > "pure function arguement problem"

Next Comment >Help | Reply To Topic
Author Comment/Response
m prior
09/18/07 5:18pm

I'm try ing to create pure functions with variable number of arguements. First I build a list of symbols for the arguements. Then I try to use that list in the call to Function[{args},body].

However this does not seem to produce the same effect as if I manual define the arguments. In the automated method the arguments seem to remain unevaluated.

Any ideas why this does not work as expected ... ?

Many thanks in advance,

Matt

In[165]:= MakeSymbolArray[v_,size_]:= Map[Symbol[ToString[v]<>ToString[#]]&,Range[1,size]]

In[166]:= sa=MakeSymbolArray[pp,2]
Out[166]= {pp1,pp2}

In[167]:= f=Function[sa,2^pp1 3^pp2]
Out[167]= Function[sa,2^pp1 3^pp2]

In[168]:= f[2,3]
Out[168]= 2^pp1 3^pp2


In[169]:= f=Function[{pp1,pp2},2^pp1 3^pp2]
Out[169]= Function[{pp1,pp2},2^pp1 3^pp2]

In[170]:= f[2,3]
Out[170]= 108

In[171]:= Map[Head,{pp1,pp2}]
Map[Head,sa]
Out[171]= {Symbol,Symbol}
Out[172]= {Symbol,Symbol}






URL: ,

Subject (listing for 'pure function arguement problem')
Author Date Posted
pure function arguement problem m prior 09/18/07 5:18pm
Re: pure function arguement problem yehuda ben-s... 09/23/07 1:49pm
Next Comment >Help | Reply To Topic