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
letmut a = 0;letmut b = 1;(a, b) = (b, a);// a = 1, b = 0
But if you do the same thing in Rune, it says error: Cannot assign to expression. Swapping variables like this is often very useful. Please fix this so we can do this in Rune as well.
The text was updated successfully, but these errors were encountered:
was allowed but unfortunately this currently throws a Pattern might panic warning. A warning is not the end of the world but it'd be cool if there was some static checking of tuple size in cases like this to automatically suppress it.
This will be possible in 0.14 with #663. Before that change we weren't allowed to perform these kinds of optimizations easily, because we couldn't tell if a or b were Copy types. Copy types (like numbers) demanded that for each assignment a clone of the value is used, so a reassignment like the above has distinct behaviors depending on whether a and b are Copy or not. While the above transformation might've been possible, it would be more difficult to implement coherently.
In 0.14 an onwards, all dynamic values (including primitives) are instead always structurally shared:
let a = 11;let b = 22;let closure = || a;(b, a) = (a, b);
b += 1;assert_eq!(closure(),12);
For dynamic languages, this allows for arbitrarily complex transformations, without having to perform static analysis such as seeing the assignment of a and b.
In Rust, you can to this:
But if you do the same thing in Rune, it says
error: Cannot assign to expression
. Swapping variables like this is often very useful. Please fix this so we can do this in Rune as well.The text was updated successfully, but these errors were encountered: