| Author |
Comment/Response |
Pedro Alves
|
10/27/98 12:07pm
> > >
> > Is it possible to apply a list of elements as arguments of a function without going through ''for'' and ''table''?
> >
> > eg: something that transforms {a,b,c} in f[a,b,c]
> >
> > If not is it possible to make this as a ''suffix'' form? (eg: {a,b,c} </?> f )
> >
> > If possible reply to mail address.
> >
> > Thanks
> >
>
> =====
>
> It is not exactly clear what you are wanting to do. I will guess that you have
> some function that evaluates for 1, 2, and 3 as f[1], f[2], and f[3] respectively, but that f[{1,2,3}] returns at least partially unevaluated. If the goal is to apply f to 1, 2, and 3, that can be done in at least two ways:
>
> - Use Map
>
> In[1]:= Map [f, {1,2,3}]
> Out[1]= {f[1],f[2],f[3]}
>
> If applying f to a List is common you can use the Listable Attribute
>
> In[2]:= SetAttributes[f, Listable]
>
> Now f is automatically applied to each element of the list:
>
> In[3]:= f[{1,2,3}]
> Out[3]= {f[1],f[2],f[3]}
>
> Tom Zeller
> Forum Moderator.
No, not like this. I have a list {1,2,3} and I want to apply it to a three argument function f. What I do is this:
f[ {1,2,3}[[1]]], {1,2,3}[[2]], {1,2,3}[[3]] ]
There must be an easier way...
URL: , |
|