From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: =?utf-8?Q?K=C3=A9vin_Le_Gouguec?= Newsgroups: gmane.emacs.help Subject: Re: rx and rx-to-string handle (regexp VAR) differently Date: Fri, 09 Jun 2023 07:35:29 +0200 Message-ID: <87r0qlgpum.fsf@gmail.com> References: <87ttvhvdco.fsf@gmail.com> <257320f0-697c-cbc3-fcfc-584d6ac7051c@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="25852"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: help-gnu-emacs@gnu.org To: Platon Pronko Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Fri Jun 09 07:36:07 2023 Return-path: Envelope-to: geh-help-gnu-emacs@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 1q7Un7-0006Z0-SH for geh-help-gnu-emacs@m.gmane-mx.org; Fri, 09 Jun 2023 07:36:05 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1q7Ume-0007V7-Uq; Fri, 09 Jun 2023 01:35: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 1q7Umd-0007Uy-Rg for help-gnu-emacs@gnu.org; Fri, 09 Jun 2023 01:35:35 -0400 Original-Received: from mail-wm1-x32a.google.com ([2a00:1450:4864:20::32a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1q7Umb-0003DG-Nr for help-gnu-emacs@gnu.org; Fri, 09 Jun 2023 01:35:35 -0400 Original-Received: by mail-wm1-x32a.google.com with SMTP id 5b1f17b1804b1-3f7fc9014fdso9336195e9.3 for ; Thu, 08 Jun 2023 22:35:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1686288931; x=1688880931; h=content-transfer-encoding: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=JGOqehyolKVpqxo9cdP5/pslkBB7Z8qgOyp+d1z5Qmo=; b=S/yehk6BeHsO+r3bSXQe+MHcf5y8+TeNQ7aBGLthhIICZc8jy2D+2HcO7k1hNiKARn zctJ18dmuVpqlpcGiacvBH9RrFoEG0A8XJmQJ6l3DZ4mkBMdp81stbi25fz4+NSksCZU 7ozWrvIgvY+AUVdXFYD1lhKgKBEKM30jpJPp5PVKaE9qCOiDtIqTrWzjF8KltjufZQ2V BgdAvgFq1A+WrFYDUn2J6A8h8DgMcK5OwBqOCuuq8YkzWaUl/BrhLimdy+Zv2qNFKdLh yz2FnU1m4Y6Py79u5PB3aqL4HWXPKsVyx8/miH+73VlvP5hdHlGTMg8AKmgL5O7XZT23 aNBw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686288931; x=1688880931; h=content-transfer-encoding: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=JGOqehyolKVpqxo9cdP5/pslkBB7Z8qgOyp+d1z5Qmo=; b=YjX8Mm1j0WRANcfxpnt0k2kWO+sHEFImVKnhRNtfwfNb7l2kULgi09ljcXrsT6Gu+h XDqVeymkGJRLJTMcZUeufxKQeOkuW2vOQJftnm9d0nm5sqPuXK3YDH+T5N6Ja/SZDjsv 7YdqqBjn1fFK/HORTaK0T3SxBxjj14Hb8o7GiS9XgOJbz9eXmryJJZSjNgpUp3HMu9lf e25IbSkHysLEIZ5eo9l3WBGebOMsCTjbPsLyGuDEExvsR/0YjrDfFWEE58LaZjRDuD/f G+teYMwg8eRm1qLRRPZhaKfs35FtNvOAGpCYG0WD3ERTSHEJ5UfP6wSVA3OF8sHfImsd tvkQ== X-Gm-Message-State: AC+VfDyb1bGc0cLqLIryzKNyNbZGohqlHUiqkM561atlU+QqOwu/gYHI EQ6phhLDd0v7pu31ntCk5ReV7dfab4o= X-Google-Smtp-Source: ACHHUZ6SqPtL6np8LioH6UTfEODl7FUKDVmJ/QHZt5FHdnKSJgmaE/D+atB8ce6KSov1NUcmoQdT4A== X-Received: by 2002:adf:ff82:0:b0:2ef:ba4f:c821 with SMTP id j2-20020adfff82000000b002efba4fc821mr57548wrr.36.1686288930986; Thu, 08 Jun 2023 22:35:30 -0700 (PDT) Original-Received: from amdahl30 ([2a01:e0a:253:fe0:2ef0:5dff:fed2:7b49]) by smtp.gmail.com with ESMTPSA id k10-20020adff5ca000000b003077a19cf75sm3376884wrp.60.2023.06.08.22.35.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Jun 2023 22:35:30 -0700 (PDT) In-Reply-To: <257320f0-697c-cbc3-fcfc-584d6ac7051c@gmail.com> (Platon Pronko's message of "Fri, 9 Jun 2023 08:57:52 +0800") Received-SPF: pass client-ip=2a00:1450:4864:20::32a; envelope-from=kevin.legouguec@gmail.com; helo=mail-wm1-x32a.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, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, 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: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.help:143895 Archived-At: Platon Pronko writes: >> Is there a bug to file here, or have I missed something in the >> documentation that explains why rx can work with (regexp VAR) but >> rx-to-string cannot? > > rx-to-string docs explicitly say: "The arguments to =E2=80=98literal=E2= =80=99 and =E2=80=98regexp=E2=80=99 forms > inside FORM must be constant strings." Drats. So they do. Second sentence of the docstring no less; and a completely separate paragraph in "(elisp) Rx Functions". I have no words =F0=9F=A4=A6 > As to "why it was done like this?", I guess that's because (rx) is a macr= o and > (rx-to-string) is a function. So (rx-to-string) tries to evaluate everyth= ing in > a self-contained way, without accessing outside environment (this might p= revent > certain error cases when rx form is created in one place, then stored and > evaluated in a different context). > But (rx) is a macro, and thus it can be free to expand to whatever it lik= es - so > it sets (rx--delayed-evaluation t) and outputs an expression that referen= ces > outside variables. > >> Re(-re)=E2=81=BF-reading that last sentence makes me tentatively conclud= e that >> foo-regexp is not in rx-to-string's "current lexical environment", but >> somehow is in rx's? > > In this case it actually is in rx-to-string's current lexical environment= , but > it just doesn't care - it checks if expression is a literal string and th= rows an > error otherwise. > And in rx's case it also is in the current lexical environment, however t= he > symbol evaluation happens only after the macro was expanded - (rx) itself= simply > returns foo-regexp as-is: > > (macroexpand-1 '(rx foo)) ;; output: foo-regexp Thanks for the perspective, much appreciated!