the simplest way ...?
- To: mathgroup at smc.vnet.net
- Subject: [mg16413] the simplest way ...?
- From: "schatzi" <antoine.zahnd at iprolink.ch>
- Date: Sat, 13 Mar 1999 02:21:34 -0500
- Sender: owner-wri-mathgroup at wolfram.com
Hello, I have two (basic) 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 integers list, and will return False as soon as an odd number is found, without the use of the Length function? 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