From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: abq@bitrot.link Newsgroups: gmane.emacs.devel Subject: Re: Why is lexical-binding's global value ignored? Date: Sun, 29 Jan 2023 20:53:30 -0700 Message-ID: <43216edcfeada34083e17a8230af2ee3@bitrot.link> References: <25094a24f891856fe0757fa34d80017b@bitrot.link> <83bkmh96gc.fsf@gnu.org> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="18991"; mail-complaints-to="usenet@ciao.gmane.io" Cc: emacs-devel@gnu.org To: Eli Zaretskii Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Mon Jan 30 13:28:05 2023 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 1pMTGV-0004ja-Oy for ged-emacs-devel@m.gmane-mx.org; Mon, 30 Jan 2023 13:28:04 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pMTFh-00020h-Jw; Mon, 30 Jan 2023 07:27:14 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pMLEi-0004Ak-Ih for emacs-devel@gnu.org; Sun, 29 Jan 2023 22:53:40 -0500 Original-Received: from relay4-d.mail.gandi.net ([217.70.183.196]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pMLEg-0006Z3-6I; Sun, 29 Jan 2023 22:53:39 -0500 Original-Received: (Authenticated sender: root@bitrot.link) by mail.gandi.net (Postfix) with ESMTPA id 4AEF4E0003; Mon, 30 Jan 2023 03:53:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bitrot.link; s=gm1; t=1675050811; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=LXcuJ9HvZ94Jk1kDLQq8N66UjKlqqsRAtafKVOspmi0=; b=InZYm79hiymNfgY2peMnF6qH6HmzqX8kRl5XhtYw4ADI4xXpjaJ+1P+Prl7m4syZnZz/Xj lCaCod7gcDPDjV/lN++jx1d1pNq+bEVTejg0PwW95ArYZKkdFlXR1v9kyzhAuBnC9QFSXw oXLIu6Ysw6onBWk93XRCbmqlgsnrz8pE5ePJC+ravJq3a8rRrobJJjkH2SxbIzqmYqXX3S 5t/9ObXyNgsmX1gok9MDUBaWwXN3Oh8JoJwTxipCAK90rwH2jnQnQcE/vJZvyDsAKMoh1G BqBu0S2ms1lO26sF8OD837WykBps/dROUQl8Oe4Y+FKt6XTx/4aVi/aT6MfIlw== In-Reply-To: <83bkmh96gc.fsf@gnu.org> X-Sender: abq@bitrot.link Received-SPF: pass client-ip=217.70.183.196; envelope-from=abq@bitrot.link; helo=relay4-d.mail.gandi.net X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Mailman-Approved-At: Mon, 30 Jan 2023 07:27:10 -0500 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 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-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.devel:302775 Archived-At: On 2023-01-28 23:54, Eli Zaretskii wrote: > Wasn't that already explained? What happens if you say > > (setq-default lexical-binding t) > > and then load a Lisp file that expects dynamic-binding by default? Then it breaks! As I wrote in my response to tomas: “In order to break anything, you would have to do so explicitly, via (setq-default lexical-binding t).” Of course, nobody actually does that. Therefore, it would be safe to honor the global value in Emacs 29. And the reason nobody sets the global value is that currently it would be pointless, because it isn't honored in Emacs 24 through 28. There's no danger of anybody accidentally setting it with plain setq, since it automatically becomes buffer local when set. You have to purposefully shoot yourself in the foot with setq-default. > IOW, the lack of lexical-binding: cookie in a file is interpreted as > having an explicit "lexical-binding: nil" in that file, for the > reasons Tomas explained. But of course, dynamic binding isn't always used intentionally. It's also often used in cases where the programmer gave no consideration to the difference (and often, unconsciously intended lexical binding). Since the longstanding, widespread computer science consensus is to program using lexical binding except in special cases where dynamic binding is intentionally chosen, it's sensible to facilitate a bias in that direction, at least optionally. If you use lots of historical code written with no consideration of the difference, one way to test the code would be to sprinkle lexical-binding: t across the tops of all your files, and keep track of which ones have it set because they actually expect it vs. which ones have it set just so you can test them. Which, ironically, is a bit like using a purely functional language with no dynamic binding or global variables, so you're forced to modify all your function signatures and calls to explicitly pass global state as an argument. Or, a more sensible way to test your historical code would be to simply do (setq-default lexical-binding t) in your init file. But you can't do that in Emacs 24 through 28, because the global value is ignored. If it were honored in Emacs 29, then a news item could be added, suggesting everybody try (setq-default lexical-binding t) in the init file, to test all the packages they use, then add explicit lexical-binding: nil (or defvar) in the cases where dynamic binding is intentional. People who think this is nonsense can harmlessly ignore the suggestion.