[Swift-user] Silly question about generating arrays

Lorenzo Pesce lpesce at uchicago.edu
Thu Nov 29 10:44:29 CST 2012


Hi --

I have a simple problem to which I would like to find a simple and elegant solution.

I will use this example:

int matsize[] = [5, 20, 30, 50, 100, 75, 45, 15];

file MagicSquares[] <simple_mapper; prefix="magicmat.",suffix=".dat">;

foreach s, i in matsize {
  MagicSquares[i] = magicsq (MCRPath, s);
}

This work fine, but let us suppose that instead I need to loop over two sets of variables:

int matmax[] = [5, 20, 30, 50, 100, 75, 45, 15];

for each max, indexmax matmax {

  file MagicSquares[] <simple_mapper; prefix=@strcat("magicmat.",max,"."),suffix=".dat">;
   matsize = "["`seq -s"," max`"]";

   foreach s, i in matsize {
       MagicSquares[i] = magicsq (MCRPath, s);
   }

}

Of course the operation I put in bold is not going to compile and would produce a "string"(?). 
I can think of ways of doing it, but I realized that all methods would return an array that I am not sure is perceived as such by swift.

A multidimensional arrays would probably do the trick too.

What would be the "best" way of doing this?

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/swift-user/attachments/20121129/8ae687dd/attachment.html>


More information about the Swift-user mailing list