[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Default lexical-binding to t
From: |
Stefan Monnier |
Subject: |
Re: Default lexical-binding to t |
Date: |
Fri, 08 Nov 2024 13:38:32 -0500 |
User-agent: |
Gnus/5.13 (Gnus v5.13) |
>> | Note that when code using Dynamic Binding is native compiled the
>> | native compiler will not perform any Lisp specific optimization.
> This looks like a choice not to support dynamic binding as well as
> lexical binding.
As Andrea mentions, it's not quite so simple: by its very nature,
dynamic scoping makes static understanding of the code's behavior
is harder. To take an example from, my PL course: 🙂
(let ((x 3)) (+ (f y) x))
with static scoping, the compiler can trivially rewrite this:
(let ((x 3)) (+ (f y) x))
=> (constant propagation)
(let ((x 3)) (+ (f y) 3))
=> (dead variable elimination)
(+ (f y) 3)
but with dynamic scoping, both steps require the compiler to convince
itself that no code reachable from `f` can refer to or modify `x`.
Our compiler is very far from performing enough code analysis to know
anything about `f` when we compile the above code, so it gives up on the
optimization right away.
Of course, this doesn't affect only compilers but also humans.
It's part of the reason why static scoping is used by virtually all
programming languages, whereas dynamic scoping is supported only by
a select few programming languages and is virtually never the default.
Stefan
- Re: Default lexical-binding to t, (continued)
- Re: Default lexical-binding to t, Alan Mackenzie, 2024/11/07
- Re: Default lexical-binding to t, Dmitry Gutov, 2024/11/07
- Re: Default lexical-binding to t, Eli Zaretskii, 2024/11/08
- Re: Default lexical-binding to t, Alan Mackenzie, 2024/11/08
- Re: Default lexical-binding to t, Eli Zaretskii, 2024/11/08
- Re: Default lexical-binding to t, Alan Mackenzie, 2024/11/08
- Re: Default lexical-binding to t, Stefan Monnier, 2024/11/08
- Re: Default lexical-binding to t, Andrea Corallo, 2024/11/07
- Re: Default lexical-binding to t,
Stefan Monnier <=
- Re: Default lexical-binding to t, Sean Whitton, 2024/11/06
- Re: Default lexical-binding to t, Jim Porter, 2024/11/06
- Re: Default lexical-binding to t, Stefan Monnier, 2024/11/06
- Re: Default lexical-binding to t, John Yates, 2024/11/06
- Re: Default lexical-binding to t, Stefan Monnier, 2024/11/08
- Re: Default lexical-binding to t, Jose A. Ortega Ruiz, 2024/11/06
- Re: Default lexical-binding to t, Stefan Monnier, 2024/11/08
- Re: Default lexical-binding to t, Richard Stallman, 2024/11/06
- Re: Default lexical-binding to t, Eli Zaretskii, 2024/11/07
- Re: Default lexical-binding to t, Richard Stallman, 2024/11/06