MathGroup Archive 1999

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

Search the Archive

the simplest way?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg16350] the simplest way?
  • From: "Antoine Zahnd" <antoine.zahnd at iprolink.ch>
  • Date: Thu, 11 Mar 1999 02:16:33 -0500
  • Sender: owner-wri-mathgroup at wolfram.com

Hello,

I have two questions with lists, each time to avoid the Length function.


1) For example, how to write a function that will go thru the elements of a
list of
integers, and will return False as soon as an odd number is found, without
using
Length?


With Length it is easy, but not so clean ...
f[l_]:= Block[{k},For[k=1,k<=Length[l],k++,If[OddQ[l[[k]]],Return[True]]];
False];


2) Is it possible to write the following function without Length?

l={1,2,3};
Table[ReplacePart[l,l[[i]]-1,i],{i,1,Length[l]}]
{{0,2,3},{1,1,3},{1,2,2}}

More generally, is there a way to write something like:
(for x in l ... collect (f x) )	, and the collection of the (f x) are
returned
in a list?

I don't see how to write a Lisp style dolist function in Mathematica
without the Length!

Hope that the questions make sens ...

Thank you very much for your help. 

antoine.zahnd at iprolink.ch




  • Prev by Date: Re: Position of element in a list
  • Next by Date: Select peculiarity
  • Previous by thread: Re: Making large movies
  • Next by thread: Re: the simplest way?