4 ms·
In a language where functions are in the same namespace as variables (like the majority of languages), I would expect A, in a lisp-2 I would expect B. But I do
by gpderetta 2y ago
In a language where functions are in the same namespace as variables (like the majority of languages), I would expect A, in a lisp-2 I would expect B.
But I don't see how's that relevant, this is not about the scope of bindings, but about the lifetime of objects.
As Steve explained in a sibling comment, _ is in fact not a variable name, and doesn't extend the lifetime of the object. The semantic is perfectly reasonable and I'm sure it has a good reason to be that way, but the difference between two similarly looking syntaxes is surprising and violates the principle of least astonishment.
FWIW, C++ temporary lifetime extensions are also surprising in many cases.
[Note: I don't know if rust is defined in term of temporary lifetime extensions, it is just a way to understand it for a c++ programmer like me]
- steveklabnik 2y agoThe definitions are a bit different than in C++ but the overall effect is the same: https://doc.rust-lang.org/stable/reference/expressions.html#temporaries https://doc.rust-lang.org/stable/reference/expressions.html#...