Re:Rust: A Critical Retrospective
by bobbylarrybobby on Thursday May 19, 2022 @08:43PM
(#31442069)
In practice though, getting the AST from the text is a computational task in and of itself and the grammar affects the runtime of that. For instance, Rust's "turbofish" syntax, `f::<T>(args)`, is used to specify the generic type for f when calling it; this is instead of the perhaps more obvious `f<T>(args)`, which is what the definition looks like. Why the extra colons? Because parsing `f<T>(args)` in an expression position would require unbounded lookahead to determine the meaning of the left angle bracket -- is it the beginning of generics or less-than? Therefore, even though Rust could be modified to accept`f<T>(args)` as a valid syntax when calling the function, the language team decided to require the colons in order to improve worst case parser performance.
[ Parent
| on HN ]
This is why using the same character as a delimiter and operator is bad.
Re:Rust: A Critical Retrospective
by colejohnson66 on Friday May 20, 2022 @06:01PM
(#31453059)
How does C# manage to handle without the turbo fish syntax? What’s different in Rust?
Re:Rust: A Critical Retrospective
by bobbylarrybobby on Friday May 20, 2022 @08:28PM
(#31454179)
It's not impossible to handle the ambiguity, it's just that you may have to look arbitrarily far ahead to resolve it. Perhaps C# simply does this. Or perhaps it limits expressions to 2^(large-ish number) bytes.