[Swift-devel] Problem with iterate

Ben Clifford benc at hawaga.org.uk
Wed Feb 17 10:58:42 CST 2010


> I have put together this really simple iteration example, which I expected
> to work (and it used to work in the past):

mmm.

yeah, the static analysis of when array elements are allowed to be 
assigned doesn't work well there.

If anyone is looking at fixing it, I think its something like the iterate 
statement being tagged as a writer of "all of statePathFiles", which then 
conflicts with the first line being a partial writer of statePathFiles. 

If anyone is *really* look at fixing it, get rid of foreach and iterate 
and put in proper dataflow based iteration (map, foldr, whatever) such 
that arrays are single-assignment.

>         statePathFiles[0]=initFunc("hello");
> 
>         iterate it{
>                 trace(@strcat("Iteration: ",it));
>                 statePathFiles[it+1]=catFunc(statePathFiles[it]);
>         } until (it==0);
> }

> Please suggest  solutions for it .

probably the two solutions above are not what you're looking for.

but:

move the statePathFiles[0] assignment into the iterate loop, by saying 
something like the below (but you'll have to adjust the array indices too, 
I think, because you need to start one earlier now). something like this:

iterate it { 
  if(it==0) {  statePathFiles[0]=initFunc("hello"); } else
   {statePathFiles[it+1]=catFunc(statePathFiles[it]);}
  } until(it==0);


-- 



More information about the Swift-devel mailing list