[Swift-devel] Problem with iterate

Ben Clifford benc at hawaga.org.uk
Sun Feb 21 02:37:58 CST 2010


> And then ML would just have full static scoping, so whatever is visible
> in the scope of foo's definition is visible in its invocation.

But that only works if your variables are visible. For static parameters, 
sure. But:

foreach p1 in [1,2,3] { foreach p2 in [10,20,30] { o[p1][p2] = p1 + p2 }}

o = map outerbody [1,2,3]

outerbody p = map innerbody [10,20,30]

innerbody q = q + ?

So you end up wanting to define innerbody inside the scope of outerbody,

outputbody p = let
  innerbody q = q + p
 in map innerbody [10,20,30]

which looks pretty un-c-like indeed. But I guess something like that is 
necessary if you want to access loop variables from nested loops (which I 
think is desirable).



More information about the Swift-devel mailing list