question about sublists



How about a name more mnemonic about indices?

Like
   find_index, list_index, or locate_index

Of course, the actual function could actually find many indices for various
predicates.

A user could always make an alias for him or herself if the name is too long.

-sen

On Thu, 4 Jan 2007, Robert Dodier wrote:

> On 1/3/07, sen1 at math.msu.edu <sen1 at math.msu.edu> wrote:
>
>>   Given a list, say xx: [2,1,3,3,5], how would I use 'sublist' to
>>   extract the indices where '3' occurs?
>
> I think this is a general problem and Maxima should have a built-in
> function for it. How about if we call it "find".
>
> Here's an attempt which worked OK for the one example I tried:
> find (L, p) := block ([I : makelist (i, i, 1, length (L))], sublist
> (I, lambda ([i], is(p(L[i])))));
>
> xx: [2,1,3,3,5];
> P(x) := x=3;
> find (xx, P);
>  => [3, 4]
> find (xx, lambda ([x], x=3));
>  => [3, 4]
>
> Of course we would want to rewrite it in Lisp.
>
> All the best,
> Robert
> _______________________________________________
> Maxima mailing list
> Maxima at math.utexas.edu
> http://www.math.utexas.edu/mailman/listinfo/maxima
>

-- 
  ---------------------------------------------------------------------------
  | Sheldon E. Newhouse            |    e-mail: sen1 at math.msu.edu           |
  | Mathematics Department         |       				   |
  | Michigan State University      | telephone: 517-355-9684                |
  | E. Lansing, MI 48824-1027 USA  |       FAX: 517-432-1562                |
  ---------------------------------------------------------------------------