Re: Converting a list to arguments for a function --- How?
- To: mathgroup at smc.vnet.net
- Subject: [mg118703] Re: Converting a list to arguments for a function --- How?
- From: Richard Hofler <rhofler at bus.ucf.edu>
- Date: Sat, 7 May 2011 07:35:55 -0400 (EDT)
Virgil,
One way to give you what I think you want is to write the argument of your function so it is followed by *two* underlines, not the usual one.
In[1]:= f1[{lst__}]:= Total[lst]
f2[{lst__}]:= Mean[lst]
(* Perhaps you want a more complicated function *)
f3[{lst__}]:= N[Exp[lst[[2]]/lst[[1]]],3]
In[4]:= list = {4,1,1};
In[5]:= f1[{list}]
f2[{list}]
f3[{list}]
Out[5]= 6
Out[6]= 2
Out[7]= 1.28
HTH,
Richard Hofler
-----Original Message-----
From: Virgil Stokes [mailto:vs at it.uu.se]
Sent: Friday, May 06, 2011 7:25 AM
To: mathgroup at smc.vnet.net
Subject: [mg118703] [mg118666] Converting a list to arguments for a function --- How?
Suppose I have a list,
list = {4,1,1}
and I wish to use it as follows
f[4,1,1]
Is there a simple way (without looping through the elements list) to transfer
the elements of list to the arguments for f?