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: Mon, 28 Aug 2023 20:06:27 +0000 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="28679"; mail-complaints-to="usenet@ciao.gmane.io" Cc: emacs-devel@gnu.org To: Ulrich Mueller Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Mon Aug 28 22:07:25 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 1qaiWD-0007GN-1h for ged-emacs-devel@m.gmane-mx.org; Mon, 28 Aug 2023 22:07:25 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qaiVP-0007Ed-Vs; Mon, 28 Aug 2023 16:06:36 -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 1qaiVO-0007EU-9P for emacs-devel@gnu.org; Mon, 28 Aug 2023 16:06:34 -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 1qaiVL-00073z-CT for emacs-devel@gnu.org; Mon, 28 Aug 2023 16:06:34 -0400 Original-Received: (qmail 88914 invoked by uid 3782); 28 Aug 2023 22:06:28 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=muc.de; i=@muc.de; q=dns/txt; s=default; t=1693253188; h=date : to : cc : subject : message-id : references : mime-version : content-type : in-reply-to : from : from; bh=OKcZNqHlkudqu5O/YrdDYHYG/cAdSIjcv3NU822dnA8=; b=BLb129g5vPoI9K+Z43xu2QjjvxifMAWpQMzjpDxJQVVqcqoqZH00i+oaNKMDCnTBiFc3r i0zBIav2MON0FLQS2DEK60bl6w+PCGAFlfqhsrfjWEwlmfrhvhsEyLGARyXpo2QaCvlS/XF Xy4/1YnHjXBlYEc/gMKl/ROlVPCRlggtZXUXqprXeQB88QtK58zGg29dqAHNloo0F/bWy9U p4il8FfzXNsmf1+DuOG2yWrF5AJwfnSEVlzo6vi6fBc2K39dz7wNsJjuquXFQ3jjmAn7Sbu +WiV/JfyyrEqhIrLs7k66iNXapRk1nZshZJgeKmA/rRg8Z1VDG97kwR8NhGw== Original-Received: from acm.muc.de (pd953a405.dip0.t-ipconnect.de [217.83.164.5]) (using STARTTLS) by colin.muc.de (tmda-ofmipd) with ESMTP; Mon, 28 Aug 2023 22:06:27 +0200 Original-Received: (qmail 5524 invoked by uid 1000); 28 Aug 2023 20:06:27 -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:309452 Archived-At: Hello, Ulrich. On Mon, Aug 28, 2023 at 21:47:57 +0200, Ulrich Mueller wrote: > >>>>> On Mon, 28 Aug 2023, Alan Mackenzie wrote: > > In C, we have the very useful conditional compilation directives > > introduced by #if or #ifdef, etc., which end at #end. > > In Emacs Lisp we have no such construct. This is a Bad Thing. > > More and more, especially recently, irritating warning messages are > > occurring for, for example, obsolete variables and functions inside > > conditionals which ensure they aren't used. For example: > > (when (< emacs-major-version 24) > > (defadvice .....)) > > produces the warning about defadvice being obsolete. (I haven't actually > > tested this example). What we really want here is for the defadvice only > > to be _compiled_ when (< emacs-major-version 24), rather than compiled > > unconditionally and not run. > I believe (eval-when-compile (< emacs-major-version 24)) would work? I've twisted my head into knots in the past trying to work out how to use eval-when/and-compile for this purpose. The point is, I don't want the defadvice to be evaluated at compile time; I just want it to be compiled (or not). > > I propose a new function, hash-if, which would do what we want. The > > above example could then be written something like: > > (hash-if (< emacs-major-version 24) > > (defadvice .....) > > (advice-add .....)) > But the old Emacs version wouldn't have the function, so it couldn't be > used like this. What am I missing? That's a very good point. I would propose that we suggest to package maintainers that they include the entire source of hash-if inside a suitable conditional in their packages. It's only 13 lines of code, including a doc string. It would appear that the compiler-macro mechanism existed at the latest in Emacs 21.4. I don't know how well it worked in these earlier versions. -- Alan Mackenzie (Nuremberg, Germany).