[Swift-devel] Problem with iterate

Ben Clifford benc at hawaga.org.uk
Sat Feb 20 05:51:48 CST 2010


> > how you would do things differently to help this kind of analysis be 
> > easier to do? BTW, I have a student in my class that is interested 
> > automated parallelization of code, so this conversation is highly 
> > relevant for his project (and my understanding).

I think that deadlocks will always be possible. Especially given 
yesterday's playing with Haskell, I'm fairly convinced that its "not easy" 
to find them.

But I think data and control structures can be written that will nudge 
programmers in the direction of not going that way; and that are easier to 
analyse.

I'm fairly sure operators that look like map/fold/scan in Haskell would 
make that easier. Certainly it would make things different.

What I mean there is, rather than having a foreach where the body of the 
loop can do anything it wants, make that body much more constrained in 
what it can do.

eg in haskell, I can say this:

$ ghci
Prelude> map  (\x -> 10 * x)   [1,2,3,4,5]
[10,20,30,40,50]

This is doing pretty much what a foreach is often used for. But the body 
(take a value and multiply by 10) is very constrained in what it can 
output. It cannot assign any values to variables - it can only output a 
value, which is then placed (by map) in the corresponding part of the 
output list.

So what would that do to SwiftScript? Well you could get rid of any 
partial assignment to arrays and say the equivalent of:

let a = map  (\x -> 10 * x)   [1,2,3,4,5]

Now a is single assignment, rather than more generally monotonically 
assigned. I think that is one part that is awkward in the present 
swiftscript.

But equally on the usability side, making people learn what a lambda 
expression is and how that fits into the above syntax might be awkward. 
Maybe its a price worth paying. A first approximation would probably be to 
make example syntax and see if its possible to explain to skenny or other 
similar character in a few paragraphs.

-- 



More information about the Swift-devel mailing list