News for hackers. Stuff that matters.
Re:Zig's Curious Multi-Sequence for Loops by defen on Monday February 27, 2023 @03:22PM (#34961389)
That's cool. At the same time though, it almost feels like a distinction without a difference in some ways - Zig has a special built-in syntax; Rust doesn't use special syntax, but it does use complex special-cased unsafe code in the stdlib in order to implement a safe + performant API.
Re:Zig's Curious Multi-Sequence for Loops by masklinn on Monday February 27, 2023 @03:29PM (#34961472)
On the other hand, the "special cased unsafe code" is applicable to more than just zip, more than just the one array type, and is available in userland (though currently unstable so nightly only, both to implement it on a bespoke type and to rely on it).
Re:Zig's Curious Multi-Sequence for Loops by brundolf on Monday February 27, 2023 @03:44PM (#34961605)
Rust's is built on top of (and exposed to) Iterators, which are a very general concept that can be rooted in all kinds of data structures, composed in all kinds of ways, and collected/processed in all kinds of ways (i.e. the user's code might not even contain an actual loop). The code continues to work in many situations, even where the optimization doesn't apply

You trade some special-case syntax and ergonomics for that generality, but it is very general even if not all of it is optimized in the same way