From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.devel Subject: Re: Are "proper" closures used in Emacs sources? Date: Tue, 12 Jan 2021 10:57:18 -0500 Message-ID: References: <875z42s1r3.fsf@mbork.pl> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="14001"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) Cc: "emacs-devel@gnu.org" To: Marcin Borkowski Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Tue Jan 12 16:58:19 2021 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kzM3n-0003Vk-25 for ged-emacs-devel@m.gmane-mx.org; Tue, 12 Jan 2021 16:58:19 +0100 Original-Received: from localhost ([::1]:33592 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kzM3m-0004gn-3A for ged-emacs-devel@m.gmane-mx.org; Tue, 12 Jan 2021 10:58:18 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:42610) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kzM30-0003n6-CP for emacs-devel@gnu.org; Tue, 12 Jan 2021 10:57:30 -0500 Original-Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:17747) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kzM2x-0000z8-Tu for emacs-devel@gnu.org; Tue, 12 Jan 2021 10:57:29 -0500 Original-Received: from pmg2.iro.umontreal.ca (localhost.localdomain [127.0.0.1]) by pmg2.iro.umontreal.ca (Proxmox) with ESMTP id 8241980722; Tue, 12 Jan 2021 10:57:26 -0500 (EST) Original-Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg2.iro.umontreal.ca (Proxmox) with ESMTP id DAD63805EF; Tue, 12 Jan 2021 10:57:19 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1610467039; bh=KpZH8DAXRILrhDS3JTh/b9czOXk9vs8lj/1NOb09qjI=; h=From:To:Cc:Subject:References:Date:In-Reply-To:From; b=QmSbOHv9EgKJlrPKtIERZsngI09uHoZJ8upDmjq2AXOZxsLob1zYnR+rp4MPhmWlk /xy+s2qznvfrXGXNhIUvHyFFiBSCIC054cUxI2gS4d454zknfjZ8Cj0C4Rkaf8b3qK URceuegVGg6AT5chXjBDvZAimFSoAYgm5X0OkQTDzZicZj662G0dIeVn4jvxVZIkAs 3m/mdfQj1rBhPiHlUaEi/Vn0YR4g9OrJig96HDT+oqINU8bA2JmMj2KHJ5lQ5w0raU 7oTjqEMH0345Hn8hvENdYeaZexPWrBbAdFtk7AccL2W6WYgF04gthxj0s863RNDAem TFxFszdeLiyLw== Original-Received: from alfajor (unknown [45.72.224.181]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id A712A120433; Tue, 12 Jan 2021 10:57:19 -0500 (EST) In-Reply-To: <875z42s1r3.fsf@mbork.pl> (Marcin Borkowski's message of "Tue, 12 Jan 2021 14:50:24 +0100") Received-SPF: pass client-ip=132.204.25.50; envelope-from=monnier@iro.umontreal.ca; helo=mailscanner.iro.umontreal.ca X-Spam_score_int: -42 X-Spam_score: -4.3 X-Spam_bar: ---- X-Spam_report: (-4.3 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.io gmane.emacs.devel:262991 Archived-At: > 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