emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Are "proper" closures used in Emacs sources?


From: Stefan Monnier
Subject: Re: Are "proper" closures used in Emacs sources?
Date: Tue, 12 Jan 2021 10:57:18 -0500
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux)

> it's been quite some time since lexical binding was introduced to
> Elisp.  Apart from possible optimizations and being less error-prone, it
> allows for all the cool tricks with closures.  Are there any places in
> Emacs core where "proper" closures are actually used?  (By "proper",
> I mean closures with non-empty lexical environment, actually using said
> environment.)

Yes.  Of course, there are lots of "proper" closures used at places
where the old code used dynamic scoping instead, such as:

    (mapcar (lambda (x) (concat x y)) foo)

I.e. using "downward funargs".  But there are also several places where
we use proper closures that survive their enclosing scope.
The completion-table functions do that a fair bit, for example, as does
`cl-generic`.  `gv-ref` is another example, along with `thunk`.
Several process filters and sentinels do that as well.

And then there are all the places where we replaced

    `(lambda ...)

with proper closures.

[ And then, there's `add-function` which relies on "proper closures" but
  it does it by manually constructing the bytecode objects rather than by
  relying on the `lexical-binding` support for lexical scope, so it's
  somewhat different (it's more like the use of `(lambda ...), just with
  byte-code objects).  ]


        Stefan




reply via email to

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