[Swift-user] Questions on use of iterate statement

Ben Clifford benc at hawaga.org.uk
Fri Feb 20 07:45:59 CST 2009


In many (all?) cases you should be able to declare an array outside of the 
iteration, with each element of the array holding the result of each step, 
like this:

int j[];
iterate i {
  j[i] = i * i;
  trace(j[i]);
} until (j[i]>15);

That was the main way in which I invisioned iterate being used when I 
implemented it, i think, so that you would map steps of your iteration 
using a single mapper declaration on j[] rather than inside the iteration 
body. That comes from imagining it as something like a functional 'unfold' 
expression (eg 
http://www.haskell.org/ghc/docs/latest/html/libraries/base/Data-List.html#9) 
where entire structures such as lists are constructed as a single 
expression.

It seems reasonable that body variables be made available to the 
termination expression, though, to support the style that you attempted, 
so I'll put that in the bugzilla as a language feature request.

-- 




More information about the Swift-user mailing list