[Swift-devel] file declaration inside foreach

Yong Zhao yongzh at cs.uchicago.edu
Wed Apr 25 11:07:27 CDT 2007


There was no particular reason, I just don't remember whether we allowed
expression as array index. If so, that should be translated into

path=concat("[", subtract(i,1), "]")

Yong.

On Wed, 25 Apr 2007, Mihael Hategan wrote:

> 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
> >
> >
> > :-(
> >
>
> _______________________________________________
> Swift-devel mailing list
> Swift-devel at ci.uchicago.edu
> http://mail.ci.uchicago.edu/mailman/listinfo/swift-devel
>



More information about the Swift-devel mailing list