On 2/29/12 4:47 PM, Graydon Hoare wrote:
Yeah, I can't either. And since we don't presently know, in other
loops (while, vector-for), whether we exited them by
loop-condition-completion or explicit-break, I can't see how this
would deserve more-special consideration. If you have a Really Special
Loop you can arrange a more subtle protocol between it and its iteratee.
I agree, the simplicity of having the main iteration protocol be:
fn(fn(T) -> bool)
is very, very appealing. I particularly like that the translation will
end up being pretty efficient. Even better, if there is no `ret`
statement within a for loop, the compiler need not emit the temporary
not any checks of the temporary, so there will be no runtime price paid.
So ... do we have a translation that actually gets us TCP-preservation
on ret? If so that's _great_. We've been banging our heads against
this and coming away disappointed since, er, possibly a year ago?
Presuming (of course) that the iterator respects "break", and that the
iterator didn't intend to perform any action after the iteration
terminated, I think it's TCP-preserving. These seem like reasonable
assumptions to me.
Also, now more than ever, I think we should still prohibit explicit
`break`, `cont`, and `ret` statements in sugared lambdas. That is,
these examples should result in an error:
v.iter {|i| ret; }
spawn {|| ret; }
but these would work:
v.iter(fn&(i) { ret; })
spawn(fn~() { ret; })
`break` and `cont` already fail of course. This seems particularly
important as it is likely to be confusing that `ret` works one way in a
for loop and another in in a `v.iter {||...}` loop. I think though that
`fn` lambdas don't look they are trying to be "normal syntax" but rather
nested functions, so having `ret` return out of that nested function
makes sense.
While we're on the topic, what about changing the keyword `cont` to
`next` (or `continue`, although it is long)? To be perfectly frank, I
find the current name rather suggestive of another word that ought not
to be uttered in polite company, particularly when spoken out loud.
Kind of silly I know, but there it is.
Niko
_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev