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: Sat, 2 Sep 2023 19:43:29 +0000 Message-ID: References: <834jkca9k0.fsf@gnu.org> 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="5143"; mail-complaints-to="usenet@ciao.gmane.io" Cc: stefankangas@gmail.com, emacs-devel@gnu.org, mattiase@acm.org To: Eli Zaretskii Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Sat Sep 02 21:44:22 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 1qcWXe-0001BE-3x for ged-emacs-devel@m.gmane-mx.org; Sat, 02 Sep 2023 21:44:22 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qcWWv-0004SV-FI; Sat, 02 Sep 2023 15:43:37 -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 1qcWWt-0004SI-PG for emacs-devel@gnu.org; Sat, 02 Sep 2023 15:43:35 -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 1qcWWq-0004mm-SU for emacs-devel@gnu.org; Sat, 02 Sep 2023 15:43:35 -0400 Original-Received: (qmail 18514 invoked by uid 3782); 2 Sep 2023 21:43:30 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=muc.de; i=@muc.de; q=dns/txt; s=default; t=1693683810; h=date : to : cc : subject : message-id : references : mime-version : content-type : content-transfer-encoding : in-reply-to : from : from; bh=QSCw8wAhEls/4W/IDvsFiab0xB6hs8wSnq3uHq+0Q4I=; b=lJQIjqqsvHujnw0tpQaLn/JYd4/OgFnJIUmdzdZJmOR6aLps+q/K6M3/Pzk1FP4sWOmKc fRWB46h8HM4cf5F+ydBFaWe2V4Rz9JpgovhCCjwEm9feVpN2dbgR4KK51cox4JjHmyD/oOl Y8MPPGBcY/Jl5zo0EdwoXsb4mzKlv/JXuSJFZX+gThhLnWwrKZaO5B9n2ZKju0jSwd+IrxZ 0o9sISZEA8BT308OboliazoA2kuzGNObaqodgWPyjamNaiffXcatrw1OBjYq0OeTDU6FSZ3 yZ4i3IgoxZ0NVdnorwx4CS0hO63oRCDuPb8JqlMkruqUaoX546XLkeQI8VMg== Original-Received: from acm.muc.de (p4fe15929.dip0.t-ipconnect.de [79.225.89.41]) (using STARTTLS) by colin.muc.de (tmda-ofmipd) with ESMTP; Sat, 02 Sep 2023 21:43:29 +0200 Original-Received: (qmail 32693 invoked by uid 1000); 2 Sep 2023 19:43:29 -0000 Content-Disposition: inline In-Reply-To: <834jkca9k0.fsf@gnu.org> 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:309908 Archived-At: Hello, Eli. Thanks for the feedback. On Sat, Sep 02, 2023 at 18:17:51 +0300, Eli Zaretskii wrote: > > Date: Sat, 2 Sep 2023 15:06:46 +0000 > > Cc: emacs-devel@gnu.org, > > Mattias Engdegård > > From: Alan Mackenzie > > +@node Conditional Compilation > > +@section Conditional Compilation > > + > > + There will be times when you want certain code to be compiled only > > +when a certain condition holds. This is particularly the case when > > +maintaining Emacs packages; to keep the package compatible with older > > +versions of Emacs you may need to use a function or variable which has > > +become obsolete in the current version of Emacs. > > + > > + You could just use a conditional form to select the old or new form > > +at run time, but this tends to output annoying warning messages about > > +the obsolete function/variable. For such situations, the macro > > +@code{static-if} comes in handy. It is inspired by the conditional > > +compilation directives like @code{#if} in C like languages, and is > > +patterned after the special form @code{if} (@pxref{Conditionals}). > > + > > + To use this facility for an older version of Emacs, copy the source > > +for @code{static-if} from the Emacs source file @file{lisp/subr.el} > > +into your package. > Thanks, but I think the references to #if make the documentation less > helpful than it could be. This manual is for Lisp programmers, and > those are not necessarily familiar with C and its preprocessor > directives. So I think it would be better if you removed the > references to cpp. If you think removing that would make the > documentation less self-explanatory, I suggest to add explanations > that are based on Lisp and on typical situations while writing Lisp > programs, not on cpp. OK, I've removed the bit "It is inspired by .... C like languages" leaving just "It is patterned after the special form @code{if} ..." of the sentence. I thought the comparison with C might be helpful for a lot of users, but I can see how it might be confusing instead. > > --- a/etc/NEWS > > +++ b/etc/NEWS > > @@ -855,6 +855,10 @@ Use 'define-minor-mode' and 'define-globalized-minor-mode' instead. > > See the "(elisp) Porting Old Advice" node for help converting them > > to use 'advice-add' or 'define-advice' instead. > > > > ++++ > > +** There is now conditional compilation, based on the C language's #if. > > +To use this, see the new macro 'static-if'. > Same here. Here, it is actually worse: "based on C language's #if" > could be misinterpreted as meaning the implementation is based on #if > in some way. I would suggest the following text in NEWS: > ** New macro 'static-if' for conditional byte-compilation of code. > This macro hides a form from the byte-compiler based on a > compile-time condition. This is handy for avoiding byte-compilation > warnings about code that will never actually run under some > conditions. static-if actually works for interpreted compilation as well as byte compilation, so I've removed two "byte-"s from your text, leaving: +++ ** New macro 'static-if' for conditional compilation of code. This macro hides a form from the compiler based on a compile-time condition. This is handy for avoiding byte-compilation warnings about code that will never actually run under some conditions. I think it's now ready to commit, except .... I've had some private email which suggested that perhaps static-if should not include the condition-case which copes with an ancient eval from before lexical binding. I can see some merit in the argument (lexical binding happened in 24.1, I think), but on the other hand, that extreme backwards compatibility doesn't really cost us anything (static-if is just 13 lines of code). What do you think? > Thanks. -- Alan Mackenzie (Nuremberg, Germany).