On Saturday, June 9, 2012, Patrick Walton wrote:

> On 06/09/2012 02:24 PM, Gareth Smith wrote:
>
>> As I understand it, given point 2 of the proposal, the above code would
>> not be valid. Instead it would look like:
>>
>> spawn(|| {
>> ...
>> });
>>
>> Is that correct? If so, would the semantics of the directly above be
>> identical to:
>>
>> do spawn {
>> ...
>> }
>>
>> ?
>>
>
> Yes, except that continue/break/ret would be valid in the latter but not
> the former.
>
> Patrick
>

If you can use break/continue/whatever to return early, does this mean you
can break with a return value? How would this interact syntactically with
labels if they were ever added? Also, am I correct that ret will only work
if the block is passed as a stack closure, since otherwise the continuation
could escape? It seems to me like this non-local return could have other
issues as well, though I also feel that it's important to be able to do it.

It has been pointed out that "break" may be misleading, since you don't
actually break from the do expression as might be expected. It seems what
you're trying to do is yield a result to the caller and allow it to
continue, so something along the lines of "yield" or "continue" might
express the idea better. "res" for "result" could work too, but it's
similar enough to "ret" to potentially cause confusion.
_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev

Reply via email to