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

Mihael Hategan hategan at mcs.anl.gov
Tue Jun 19 10:13:52 CDT 2007


On Tue, 2007-06-19 at 15:00 +0000, Ben Clifford wrote:
> 
> 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.

Should easily translate to something like:

a := swiftArray(for(i, array, ignoreErrors(p(i)))))

> 
> 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);

Doable.

> 
> 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