Post #2598520
2023-03-19 09:39 UTC
@bugaevc@floss.social @saagar@federated.saagarjha.com See e.g. https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=fa44e230278a181a3e0444b970fb6d72 , which is a naive implementation of the original code in Rust and does not compile.
The "trick" here is that you can only have one mutable reference to the reader or multiple immutable ones. Which is broken here.
There are cases where you rely on the order but this rule is not broken, notably when using implicitly shared global state like stdout. But it at least covers all (?) cases where mutability is explicitly modeled: you simply can't have one argument affect any of the others.
I should add that using the arguments in the other order actually works (because of left-to-right evaluation), but that's not the original code and IMHO also a language design mistake.
Replies (0)
No replies.