MathGroup Archive 2009

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: List of position-specifying functions


Something like this?

In[7]:= (Function[x, x[[#1]]] & ) /@ plist
Out[7]= {Function[x, x[[2]]], Function[x, x[[5]]], Function[x, x[[4]]],
   Function[x, x[[6]]], Function[x, x[[3]]]}


Adriano Pascoletti

2009/8/6 Ray Koopman <koopman at sfu.ca>

> I have a list of distinct positive integers, such as
>
> In[1]:= plist = {2, 5, 4, 6, 3};
>
> I want to convert it to a list of position-specifying functions,
> such as might be used as the second argument in SplitBy or GatherBy.
> One way that works is:
>
> In[2]:= plist /. p_Integer->(#[[p]]&)
>
> Out[2]= { #1[[2]]&, #1[[5]]&, #1[[4]]&, #1[[6]]&, #1[[3]]& }
>
> I've been trying to get the same thing using Map,
> but I haven't been able to do it. Any suggestions?
>
>


  • Prev by Date: Re: List of position-specifying functions
  • Next by Date: Re: List of position-specifying functions
  • Previous by thread: Re: List of position-specifying functions
  • Next by thread: Re: List of position-specifying functions