You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Right now there are two ways to get a slice. Through the slice syntax, and through the slice function.
I suggest changing the slice function to take a single &Ranged argument. Ranged is a new trait somewhere along these lines:
And changing the slicing_syntax to create a temporary Range object that has both the iterator trait and the Ranged trait.
let x = [99i8,10,15,6];// current syntaxlet a = x[1..3];let b = x.slice(1,3);// hypothetical syntax:let c = x.slice(1..3);// and this would work, toofor i in1..3{println!("test: {}", i);}
The new slice function would look somewhat like this:
i didn't really mention this properly: I don't suggest a forced conversion of a range notation to a range object. It should instead be like an int/float literal declaration without a fixed type.
let r = 2..4;for i in r {println!("test: {}", i);}let x = [99i8,10,15,6];let a = x[r];// error, is already a range iteratorfor j in r {// error, iterator already used up? or by copy?}
this would allow the syntax to be used in the future for new things.
For example the loop could check for out of bounds at compile time. Or a special syntax could check if an integer or float value is in a specific range. If the range notation were always converted to a specific type this would cause problems in the future.
Right now there are two ways to get a slice. Through the slice syntax, and through the slice function.
I suggest changing the slice function to take a single &Ranged argument. Ranged is a new trait somewhere along these lines:
And changing the slicing_syntax to create a temporary Range object that has both the iterator trait and the Ranged trait.
The new slice function would look somewhat like this:
here's a list of slice_syntax examples mapping to range function calls:
no actual empty range exists, but
n..m
form <= n
would cause an empty range to be created, as it currently happens with the slicing_syntax, too.The text was updated successfully, but these errors were encountered: