[Swift-devel] file declaration inside foreach

Mihael Hategan hategan at mcs.anl.gov
Wed Apr 25 10:04:05 CDT 2007


That with the assumption that k[i-1] would work.
It seems that k[i] = k[i-1] + i gets translated into this:
assign(dpath="[i]", dvar=k, 
  svar = sum(getFieldValue(var=k, path=concat("[]")), getFieldValue(i))
)

Seems like k[i-1] is translated into the wrong thing there
(path=concat("[]")).
This comes from the fact that paths like [i] are passed directly instead
of the value being extracted.

Yong, do you remember why we did this?


On Wed, 2007-04-25 at 07:35 +0000, Ben Clifford wrote:
> 
> On Tue, 24 Apr 2007, Mihael Hategan wrote:
> 
> > Because the jobs are independent. You are creating iteratiion-local
> > variables between which there is no dependency.
> > 
> > What you want is something like this:
> > file[] lattice <...>;
> > lattice[0] = initialLattice;
> > for i in 1...2 {
> >   lattice[i] = app(lattice[i-1]);
> > }
> 
> I just tried this:
> 
> int r[] = [1:2:1];
> int k[];
> 
> k[0]=100;
> 
> foreach i in r {
> k[i] = k[i-1] + i;
> }
> 
> and I get this:
> 
> $ swift for.swift 
> Swift V 0.0405
> RunID: 2hp99svgoyjd2
> Execution failed:
>         String index out of range: 0
> 
> 
> :-(
> 




More information about the Swift-devel mailing list