On Thu, Jun 7, 2012 at 2:27 PM, Patrick Walton <[email protected]> wrote:
> On 6/7/12 2:20 PM, Gareth Smith wrote:
>
> If you allow all block lambdas to have early returns with "ret", then this:
>
>    fn f() {
>        for int::range(1, 10) |i| {
>            ret i;
>        }
>    }
>
> Has a very different meaning from:
>
>    fn f() {
>        int::range(1, 10) |i| {
>            ret i;
>        }
>    }
>
> IMHO this is likely to be pretty confusing.
>
> Also, eliminating "do" makes this ambiguous:
>
>    spawn() || {
>        ...
>    }
>
> Is ambiguous with bitwise-or. This is also ambiguous:
>
>    spawn || {
>        ...
>    }
>
> In any case, I think this looks nicer:
>
>    do spawn {
>        ...
>    }

To throw one other option out there, we do support breaking out of a
closure with the "fn@" closure syntax:

```
fn foo(x: int, f: fn(int)) {
    f(x);
}

fn main() {
    foo(5, fn@(x: int) {
        #error("%?", x);
        if x == 5 { ret }
        #error("%?", x);
    });

    foo(6, fn@(x: int) {
        #error("%?", x);
        if x == 5 { ret }
        #error("%?", x);
    });
}
```

(As an aside, it sure would be nice if the fn@ closures inferred their types...)
_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev

Reply via email to