From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: "Basil L. Contovounesios" Newsgroups: gmane.emacs.devel Subject: Re: Macros considered harmful Date: Thu, 03 Nov 2022 20:27:51 +0200 Message-ID: <87iljvyjtk.fsf@tcd.ie> 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="38800"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: =?utf-8?Q?Cl=C3=A9ment?= Pit-Claudel , emacs-devel@gnu.org To: Stefan Monnier Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Thu Nov 03 19:28:54 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 1oqexR-0009sN-Vg for ged-emacs-devel@m.gmane-mx.org; Thu, 03 Nov 2022 19:28:54 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oqewg-00032I-6v; Thu, 03 Nov 2022 14:28:06 -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 1oqewY-0002vJ-4o for emacs-devel@gnu.org; Thu, 03 Nov 2022 14:27:58 -0400 Original-Received: from mail-ej1-x62c.google.com ([2a00:1450:4864:20::62c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oqewV-0004Nu-I4 for emacs-devel@gnu.org; Thu, 03 Nov 2022 14:27:57 -0400 Original-Received: by mail-ej1-x62c.google.com with SMTP id ud5so7643890ejc.4 for ; Thu, 03 Nov 2022 11:27:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tcd.ie; s=google21; h=mime-version:user-agent:message-id:date:references:in-reply-to :subject:cc:to:from:from:to:cc:subject:date:message-id:reply-to; bh=ziMNg5vhyPnF/svgb0NNxtf7NDdSCYyx+VUek+FwfpU=; b=R7ad3QTrFHn8h9DTjB2sB4l/wNrCsycro9kDYg1fF5D7W5B82antWxtU+p4bid4J5l joYlylV1SIyp6irMrB1Ppw9rfNefi1JD7DnSO5vygVVR9N8vC6mLztBqLdomxt9LBLqB cmpXC7MZBXcjv/uuuHW1rKRwqqvaEeqc1KxZ6fdAzhJFeFNnc36JtMcRFvFmrTplG/+Y +tR3v0cLk3pftw2v5vuBkEQNm/FqjxSEBHpWNw7GBdt23ZSaE7N4urOjaAfH8lNcBYSE KkC0hTmNISlc26Bbv0bHdKcvOl7F+AFDEKyNCmJQTP/ky+V4RDk0yHIoDPj5jbNi5FzL Hrgg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=mime-version:user-agent:message-id:date:references:in-reply-to :subject:cc:to:from:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=ziMNg5vhyPnF/svgb0NNxtf7NDdSCYyx+VUek+FwfpU=; b=Gmmo9qcOz9f/u564ZLcWlJdKFJR+VEHcrh6vzfUXN63tcypNQI1UdZn6oTstXZYs4G TTivOxxUJB65BOzYCxngO9uNbLAxECRkYwJockkJRXyi5aMJKq46NuA3a/voMmhWSPYo lN2FynpXrulKVc/EvAFMjtozkR9wbN2mqfJ6v5xl0MO+dScowb/j/MLHIQQzR643JqbZ 17qMeVi+4KT2VnpQiZh34bEVmxMU4srnb9rrd64s5D0/EduF9EsWnyF/gf6A1sEaYztB XJgWtqAORFlq4fjpqWUvtLIOodyYcaejMleae3lzvkNxzki1VpyfgG2KgWi5a9zf65jV cpig== X-Gm-Message-State: ACrzQf1xe0DqiVBzX3dQNu/VRGDp+PLt7jNh9KIBSgVaA85m67SiNLyV 8vC4c7FF8Ylzbo9nWzQXm+uZ4A== X-Google-Smtp-Source: AMsMyM62FIsDBC/EbGUHdGi2wESc6lvE0vALpq3c0YNwmlbbeEA6QZFZpwcf3EYzH4/UV9r4NYqQ9g== X-Received: by 2002:a17:906:6a26:b0:7ad:975c:9785 with SMTP id qw38-20020a1709066a2600b007ad975c9785mr32817852ejc.25.1667500073220; Thu, 03 Nov 2022 11:27:53 -0700 (PDT) Original-Received: from localhost ([2a02:587:320c:8829:23:8156:16ed:40c2]) by smtp.gmail.com with ESMTPSA id q22-20020aa7da96000000b00457c85bd890sm820136eds.55.2022.11.03.11.27.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Nov 2022 11:27:52 -0700 (PDT) In-Reply-To: (Stefan Monnier's message of "Tue, 06 Sep 2022 12:01:01 -0400") Received-SPF: pass client-ip=2a00:1450:4864:20::62c; envelope-from=contovob@tcd.ie; helo=mail-ej1-x62c.google.com 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, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=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: , Original-Sender: "Emacs-devel" Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.devel:299092 Archived-At: Stefan Monnier [2022-09-06 12:01 -0400] wrote: >>> 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? Yes, thanks, it allows the macro to be used within with-eval-after-load across all Emacs versions. Sadly eval-after-load is still needed to account for Emacs 28 not autoloading the shortdoc entrypoint macro, but that's down to the package's API/hooks, not the use of macros. -- Basil