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: Macros considered harmful Date: Tue, 06 Sep 2022 12:01:01 -0400 Message-ID: References: <7e24d0aa-9980-6204-5064-5a92963ae7bd@secure.kjonigsen.net> <83026cfc-8a85-9939-bab4-5b60d4812af9@gmail.com> <87fsh4ikl3.fsf@tcd.ie> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="34036"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (gnu/linux) Cc: =?windows-1252?Q?Cl=E9ment?= Pit-Claudel , emacs-devel@gnu.org To: "Basil L. Contovounesios" Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Tue Sep 06 18:09:38 2022 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 1oVb8r-0008e2-Q6 for ged-emacs-devel@m.gmane-mx.org; Tue, 06 Sep 2022 18:09:37 +0200 Original-Received: from localhost ([::1]:52846 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oVb8q-00050S-Qm for ged-emacs-devel@m.gmane-mx.org; Tue, 06 Sep 2022 12:09:36 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:36096) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oVb0x-0007IP-ID for emacs-devel@gnu.org; Tue, 06 Sep 2022 12:01:29 -0400 Original-Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:57302) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oVb0i-000365-7d for emacs-devel@gnu.org; Tue, 06 Sep 2022 12:01:25 -0400 Original-Received: from pmg1.iro.umontreal.ca (localhost.localdomain [127.0.0.1]) by pmg1.iro.umontreal.ca (Proxmox) with ESMTP id C405C100117; Tue, 6 Sep 2022 12:01:09 -0400 (EDT) Original-Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg1.iro.umontreal.ca (Proxmox) with ESMTP id D6C8910001F; Tue, 6 Sep 2022 12:01:07 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1662480067; bh=5w31W7gZy7hDNQIP05DffOz4Tz51MD7D1mdsG6+FNzw=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=CQpeLe9lU9crOSHc/xDgdUxeWUippKiHE/mJmfgI4n2Gt8BW3+v9ZxpocQS17X7i8 hLUsmvSkZ6gYy903X+3wN8SGJFfZW2cAUwj460xcnkY+PdIefF0FyWdyvuWeILhHnE HESuB/sBmv4/6Q3BkwLvAEavx6KHfHm0VWVfkCHoQcApvA/neOldrvpTAS21BuZaBw HsNKuxpR5fs/8P2hC/ua8JwcvKy0joEoLek29E35QRcPB5qya36CYjMKybis726IWI dQnIVdedPtjdD3w1aGaHpt14Mhsa6FlMa7q/U+7438992++LsViTpaQ0NCntEyHN9T Ge0SuJ5wxP7HQ== Original-Received: from lechazo (lechon.iro.umontreal.ca [132.204.27.242]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id C308F120879; Tue, 6 Sep 2022 12:01:07 -0400 (EDT) In-Reply-To: <87fsh4ikl3.fsf@tcd.ie> (Basil L. Contovounesios's message of "Tue, 06 Sep 2022 18:33:28 +0300") 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, T_SCC_BODY_TEXT_LINE=-0.01 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" Xref: news.gmane.io gmane.emacs.devel:294791 Archived-At: >> Admittedly, another way around these kinds of problems is to teach the >> compiler how to deal with an unknown macro. I.e. something like >> (declare-macro my-foo ...) so that if the compiler see (my-foo ...) but >> `my-foo` can't be macroexpanded (because the macro is not yet defined), >> it doesn't incorrectly compile it into a function call, but instead >> residualizes it into something like a call to `eval`. Making it >> interact correctly with lexical scoping could be tricky (I guess the >> simplest solution would be to residualize the whole toplevel expression >> in which the macro call was found). A low-tech way to do it is to let the programmer do it by hand, e.g.: (defmacro smalltalk--when-fboundp (sym exp) (declare (indent 1) (debug (symbolp form))) (if (fboundp sym) exp ;; `sym' is not defined during compilation, but keep the test at run-time, ;; in case we use the compiled file on a newer Emacs. `(eval '(if (fboundp ',sym) ,exp)))) It can still break if you use in `exp` lexically scoped vars declared in the context, but that's considered a "programmer's problem" :-( > Another downside of macros not directly addressed by this approach is > that packages using them may have the outrageous desire to both support > older Emacsen and build cleanly, at the same time! Recall, for example, > this unresolved shortdoc thread: > https://lists.gnu.org/r/emacs-devel/2021-09/msg01719.html Would this kind of `--when-fboundp` help there? Stefan