3 ms·
> This code does exactly the same thing as Rust code Except it doesn't - because after the final parenthesis of the Lisp snippet, the let-binding is finished,
by kleiba 3y ago
> This code does exactly the same thing as Rust code
Except it doesn't - because after the final parenthesis of the Lisp snippet, the let-binding is finished, i.e., the introduced variables are no longer in scope. That is not the case after the end of the last line in the Rust example.
The whole point of parentheses is to mark where something starts and where it ends. Here, it is where the scope of the let-defined variables starts and ends. Without some sort of "parenthesizing", there might be a start, but it's much harder to mark where something ends.
- sgeisenh 3y agoI think it's more subtle than that. Rust has a notion of non-lexical lifetimes (https://rust-lang.github.io/rfcs/2094-nll.html https://rust-lang.github.io/rfcs/2094-nll.html) and the compiler often completely avoids the use of the stack for small, trivially droppable values, regardless of their lexical scope. In some ways, `let` in Rust is a more C-like variant of the `let ... in ... end` construct from OCaml. Not to mention that you can always introduce a new lexical scope with `{ ... }` in Rust code.
- User23 3y agoI believe there are Common Lisp implementations that will happily stack allocate dynamic extent values.