[Swift-devel] on the semantics of 'array closing'

Ben Clifford benc at hawaga.org.uk
Tue Jun 19 10:00:19 CDT 2007



On Tue, 19 Jun 2007, Mihael Hategan wrote:

> > Also, I think there's two new aspects proposed here - of a foreach() 
> > or map() reaching a threshold of "enough results" that it can be 
> > called done,
> 
> With sparse arrays, it would be sufficient to not have the results from
> the iterations that fail. If we had try/catch constructs, that would
> simply translate into:
> foreach k,v in V {
>   try {
>     results[k] = process(V[k]);
>   }
>   catch (*) {}
> }
> thus alleviating the need for a complex foreach construct.

That could fit in with the list comprehension / map syntax too, I guess, 
like some:

 a = [ ignore_errors(p(i)) for i in array];

with ignore_errors being an expression-level equivalent of a try { ...} 
catch{} block.

or it could go on the outside of the map-like structure, like this:

  a = [p(i) for i in array]
  b = n_is_enough(7, a);

so that b gets assigned a value that is the first 7 values of a to be 
computed, and errors in computing the rest of 'a' don't propagate through 
to errors in computing b.

That lets you parameterise the 'n is enough' or 'whatever comes first' 
bits separately from the for construct.

-- 



More information about the Swift-devel mailing list