From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Alan Mackenzie Newsgroups: gmane.emacs.devel Subject: Re: Why shouldn't we have a #if .... #else .... #endif construct in Emacs Lisp? Date: Wed, 6 Sep 2023 09:56:34 +0000 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="23587"; mail-complaints-to="usenet@ciao.gmane.io" Cc: ulm@gentoo.org, emacs-devel@gnu.org To: Richard Stallman Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Wed Sep 06 11:57:33 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 1qdpHv-0005vC-NN for ged-emacs-devel@m.gmane-mx.org; Wed, 06 Sep 2023 11:57:31 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qdpHA-0008Ma-LE; Wed, 06 Sep 2023 05:56:44 -0400 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 1qdpH9-0008MS-Bq for emacs-devel@gnu.org; Wed, 06 Sep 2023 05:56:43 -0400 Original-Received: from mail.muc.de ([193.149.48.3]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qdpH5-0005jS-7V for emacs-devel@gnu.org; Wed, 06 Sep 2023 05:56:43 -0400 Original-Received: (qmail 60856 invoked by uid 3782); 6 Sep 2023 11:56:36 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=muc.de; i=@muc.de; q=dns/txt; s=default; t=1693994196; h=date : to : cc : subject : message-id : references : mime-version : content-type : content-transfer-encoding : in-reply-to : from : from; bh=IINEfIFr2i1W7fs2umNKqi8GDyV7Qg6QU44B41oghis=; b=o15dqlh/e9NuToq/Hkq4yX/pk6ufOl+o2ACX52SJDnL1jdOQAVo6ydiR0rV75QFeSACBI KJsyZ0Ld4Hd2inPJ5WqN4FREMDIy5lMRJGBtseqnAbz7LCXBk17ISOciKbpB9//IWmnw2zC APj0Y+EyAo8wqTUg0rhtuY6bA48GNceV4PQR825BQ/PE7x8ZoIyACX1uLOWKaomW3+pqUDx ZT8VCMdoVrqrgigClC2jyJLPfxZsavV4GFNRaEaKC/vvpWITxsc7tyXEbPDA7BLlvgAQW+J G08rze6T2q13wATNxTu9S09myQ1lcjYezHzZdoH+lCNgMeBIT+IKYKYG+dyQ== Original-Received: from acm.muc.de (p4fe1538c.dip0.t-ipconnect.de [79.225.83.140]) (using STARTTLS) by colin.muc.de (tmda-ofmipd) with ESMTP; Wed, 06 Sep 2023 11:56:35 +0200 Original-Received: (qmail 4541 invoked by uid 1000); 6 Sep 2023 09:56:34 -0000 Content-Disposition: inline In-Reply-To: X-Submission-Agent: TMDA/1.3.x (Ph3nix) X-Primary-Address: acm@muc.de Received-SPF: pass client-ip=193.149.48.3; envelope-from=acm@muc.de; helo=mail.muc.de X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 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, SPF_HELO_PASS=-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.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:310179 Archived-At: Hello, Richard. On Tue, Sep 05, 2023 at 20:58:38 -0400, Richard Stallman wrote: > [[[ To any NSA and FBI agents reading my email: please consider ]]] > [[[ whether defending the US Constitution against all enemies, ]]] > [[[ foreign or domestic, requires you to follow Snowden's example. ]]] > > For example, in CC Mode there is a chunk of code looking like .... > > (when (fboundp 'electric-indent-local-mode) ; Emacs 24.4 or later. > > (electric-indent-local-mode (if c-electric-flag 1 0))) > > , and there are quite a few instances like it. Here, there is a comment > > about which versions are relevant, but that is somewhat unusual. Note > > here that we would have to test both the major and minor version numbers > > to do this correctly. > > I intend to replace that code with > > (static-if (fboundp 'electric-indent-local-mode) ; Emacs 24.4 or later. > > (electric-indent-local-mode (if c-electric-flag 1 0))) > > .. (hash-if has been renamed static-if.) It would be more work to > > replace it with > > (when (or (> emacs-major-version 24) > > (and (= emacs-major-version 24) > > (>= emacs-minor-version 4))) > > (electric-indent-local-mode (if c-electric-flag 1 0))) > If you want to have a conditional about version mumbers, > I think that is the right way to write it. Originally, I wasn't really thinking about version numbers being the prime use case, but it was easy to use them as an example to get the discussion going. > Or, if you want to keep the condition about the availability of > electric-indent-local-mode, how about keeping the code unchanged > > (when (fboundp 'electric-indent-local-mode) ; Emacs 24.4 or later. > > (electric-indent-local-mode (if c-electric-flag 1 0))) > and inform the byte compiler that (fboundp 'electric-indent-local-mode) > can be optimized based on the Emacs version? This way you won't need > to change the source code, and we will get the ideal results. I don't know how to do this. Early on in the thread, Ulrich Müller suggested using (when (eval-when-compile (fboundp 'electric-indent-local-mode)) (electric-indent-local-mode (if c-electric-flag 1 0))) , in which the conditional gets optimised away at compile time. But that's still a change in the source code. > > static-if is a completely ordinary macro which is 10 lines long > > (including doc string), and there's a new section in the elisp manual for > > it. > I think the simplicity of the source code as it will be > counts for more than the simplicity of a new macro > which, with my approach, we don't need to add. We must also take into account the additional complexity of the defmacro and defun macros (etc.) and the byte compiler to handle the new special case. As I've already said, there are just 45 occurrences of emacs-major-version in the Lisp sources. > -- > Dr Richard Stallman (https://stallman.org) > Chief GNUisance of the GNU Project (https://gnu.org) > Founder, Free Software Foundation (https://fsf.org) > Internet Hall-of-Famer (https://internethalloffame.org) -- Alan Mackenzie (Nuremberg, Germany).