unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / Atom feed
* Are "proper" closures used in Emacs sources?
@ 2021-01-12 13:50 Marcin Borkowski
  2021-01-12 15:43 ` tomas
                   ` (3 more replies)
  0 siblings, 4 replies; 6+ messages in thread
From: Marcin Borkowski @ 2021-01-12 13:50 UTC (permalink / raw)
  To: emacs-devel

Hi all,

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.)

TIA,

-- 
Marcin Borkowski
http://mbork.pl



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Are "proper" closures used in Emacs sources?
  2021-01-12 13:50 Are "proper" closures used in Emacs sources? Marcin Borkowski
@ 2021-01-12 15:43 ` tomas
  2021-01-12 15:56 ` Zhu Zihao
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 6+ messages in thread
From: tomas @ 2021-01-12 15:43 UTC (permalink / raw)
  To: emacs-devel

[-- Attachment #1: Type: text/plain, Size: 723 bytes --]

On Tue, Jan 12, 2021 at 02:50:24PM +0100, Marcin Borkowski wrote:
> Hi all,
> 
> 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.)

tar-next-file-displayer of tar-mode.el seems to do (CAVEAT: I just
grepped for "closure" in the .el sources, dismissed the too-obvious
false-positives and half-scanned comments and code, so I might be
off by some amount! Double-check.)

Cheers
 - t

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 198 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Are "proper" closures used in Emacs sources?
  2021-01-12 13:50 Are "proper" closures used in Emacs sources? Marcin Borkowski
  2021-01-12 15:43 ` tomas
@ 2021-01-12 15:56 ` Zhu Zihao
  2021-01-12 15:57 ` Stefan Monnier
  2021-01-12 16:48 ` Andrea Corallo via Emacs development discussions.
  3 siblings, 0 replies; 6+ messages in thread
From: Zhu Zihao @ 2021-01-12 15:56 UTC (permalink / raw)
  To: Marcin Borkowski; +Cc: emacs-devel

[-- Attachment #1: Type: text/plain, Size: 575 bytes --]


Marcin Borkowski writes:

> Hi all,
>
> 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.)
>
> TIA,

thunk.el & generator.el 


-- 
Retrieve my PGP public key:

  gpg --recv-keys D47A9C8B2AE3905B563D9135BE42B352A9F6821F

Zihao

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 255 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Are "proper" closures used in Emacs sources?
  2021-01-12 13:50 Are "proper" closures used in Emacs sources? Marcin Borkowski
  2021-01-12 15:43 ` tomas
  2021-01-12 15:56 ` Zhu Zihao
@ 2021-01-12 15:57 ` Stefan Monnier
  2021-01-12 16:48 ` Andrea Corallo via Emacs development discussions.
  3 siblings, 0 replies; 6+ messages in thread
From: Stefan Monnier @ 2021-01-12 15:57 UTC (permalink / raw)
  To: Marcin Borkowski; +Cc: emacs-devel

> 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




^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Are "proper" closures used in Emacs sources?
  2021-01-12 13:50 Are "proper" closures used in Emacs sources? Marcin Borkowski
                   ` (2 preceding siblings ...)
  2021-01-12 15:57 ` Stefan Monnier
@ 2021-01-12 16:48 ` Andrea Corallo via Emacs development discussions.
  2021-01-12 17:22   ` Stefan Monnier
  3 siblings, 1 reply; 6+ messages in thread
From: Andrea Corallo via Emacs development discussions. @ 2021-01-12 16:48 UTC (permalink / raw)
  To: Marcin Borkowski; +Cc: emacs-devel

Marcin Borkowski <mbork@mbork.pl> writes:

> Hi all,
>
> 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.)

I've put a print in `byte-compile-make-closure' and did a bootstrap.

I'm counting 7289 occurrences in the Emacs code base.  Is this a correct
estimation?

  Andrea



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Are "proper" closures used in Emacs sources?
  2021-01-12 16:48 ` Andrea Corallo via Emacs development discussions.
@ 2021-01-12 17:22   ` Stefan Monnier
  0 siblings, 0 replies; 6+ messages in thread
From: Stefan Monnier @ 2021-01-12 17:22 UTC (permalink / raw)
  To: Andrea Corallo via Emacs development discussions.
  Cc: Marcin Borkowski, Andrea Corallo

> I've put a print in `byte-compile-make-closure' and did a bootstrap.
>
> I'm counting 7289 occurrences in the Emacs code base.  Is this a correct
> estimation?

Probably, but I suspect most of them are in the "downward funarg"
category, i.e. they'd work just as well with dynamic scope because they
don't outlive their own scope.


        Stefan




^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2021-01-12 17:22 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-12 13:50 Are "proper" closures used in Emacs sources? Marcin Borkowski
2021-01-12 15:43 ` tomas
2021-01-12 15:56 ` Zhu Zihao
2021-01-12 15:57 ` Stefan Monnier
2021-01-12 16:48 ` Andrea Corallo via Emacs development discussions.
2021-01-12 17:22   ` Stefan Monnier

unofficial mirror of emacs-devel@gnu.org 

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://yhetil.org/emacs-devel/0 emacs-devel/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 emacs-devel emacs-devel/ https://yhetil.org/emacs-devel \
		emacs-devel@gnu.org
	public-inbox-index emacs-devel

Example config snippet for mirrors.
Newsgroups are available over NNTP:
	nntp://news.yhetil.org/yhetil.emacs.devel
	nntp://news.gmane.io/gmane.emacs.devel


AGPL code for this site: git clone http://ou63pmih66umazou.onion/public-inbox.git