Re: Variable-length list?
- To: mathgroup at smc.vnet.net
- Subject: [mg83459] Re: Variable-length list?
- From: Szabolcs Horvát <szhorvat at gmail.com>
- Date: Wed, 21 Nov 2007 02:45:33 -0500 (EST)
- References: <fhu73f$71m$1@smc.vnet.net>
Hoa Bui wrote: > Hi all, > > I want to have either a module or a function that inputs a > varying-length list M[[nx]], where nx is a parameter, and accesses all > of its elements. > > For example: > > f[M_?(Function[v,VectorQ[v,IntegerQ]]]:=Module[{i,j,k}, > .... > ] > > If M={3,4} then f would do something like: > For [i=1,i<3,i++, > For [j=1,j<4,j++, > Print[i*j]; > ] > ] > > If M={3,4,5} then: > For [i=1,i<3,i++, > For [j=1,j<4,j++, > For [k=1,k<5,j++, > Print[i*j*k]; > ] > ] > ] > ] > > > I wonder if this is doable in Mathematica, and/or what would be a way to do it? > Hi, Never use For[], and don't use Print[] for displaying the result---just return it instead. f[{dd__Integer}] := Array[Times, {dd}] You can still Flatten[] and Print[] the result if this is necessary. -- Szabolcs