[Swift-user] Silly question about generating arrays

Michael Wilde wilde at mcs.anl.gov
Thu Nov 29 11:23:46 CST 2012


> 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);
>   }
> }

Are you looking for a pattern like this?


$ cat nestedranges.swift

int matmax[] = [5, 6, 7];
  
foreach max, indexmax in matmax {
 
  int matsize[] = [1:max];

  foreach s, i in matsize {
    tracef("magigquares[%i] = magicsq (MCRPath, %i)\n", max, s); 
  }
}

$ swift nestedranges.swift | sort

Progress:  time: Thu, 29 Nov 2012 17:22:25 +0000
Final status: Thu, 29 Nov 2012 17:22:25 +0000

RunID: 20121129-1722-myxnkhg3
Swift trunk swift-r6074 cog-r3517
magigquares[5] = magicsq (MCRPath, 1)
magigquares[5] = magicsq (MCRPath, 2)
magigquares[5] = magicsq (MCRPath, 3)
magigquares[5] = magicsq (MCRPath, 4)
magigquares[5] = magicsq (MCRPath, 5)
magigquares[6] = magicsq (MCRPath, 1)
magigquares[6] = magicsq (MCRPath, 2)
magigquares[6] = magicsq (MCRPath, 3)
magigquares[6] = magicsq (MCRPath, 4)
magigquares[6] = magicsq (MCRPath, 5)
magigquares[6] = magicsq (MCRPath, 6)
magigquares[7] = magicsq (MCRPath, 1)
magigquares[7] = magicsq (MCRPath, 2)
magigquares[7] = magicsq (MCRPath, 3)
magigquares[7] = magicsq (MCRPath, 4)
magigquares[7] = magicsq (MCRPath, 5)
magigquares[7] = magicsq (MCRPath, 6)
magigquares[7] = magicsq (MCRPath, 7)
$ 



More information about the Swift-user mailing list