emacs-devel
[Top][All Lists]
Advanced

[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




reply via email to

[Prev in Thread] Current Thread [Next in Thread]