From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Lynn Winebarger Newsgroups: gmane.emacs.devel Subject: Re: Using the content of a dynamic variable in a macro Date: Sat, 25 Feb 2023 07:32:00 -0500 Message-ID: References: <87o7pi9m9s.fsf@cassou.me> <83fsaukruu.fsf@gnu.org> <87lekm9j2v.fsf@cassou.me> Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="0000000000006fe91c05f5856f41" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="29967"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Eli Zaretskii , emacs-devel To: Damien Cassou Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Sat Feb 25 13:32:49 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 1pVtjN-0007dY-Lc for ged-emacs-devel@m.gmane-mx.org; Sat, 25 Feb 2023 13:32:49 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pVtis-00083t-VQ; Sat, 25 Feb 2023 07:32:18 -0500 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 1pVtir-00083Q-HZ for emacs-devel@gnu.org; Sat, 25 Feb 2023 07:32:17 -0500 Original-Received: from mail-pj1-x102d.google.com ([2607:f8b0:4864:20::102d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pVtiq-00056s-02; Sat, 25 Feb 2023 07:32:17 -0500 Original-Received: by mail-pj1-x102d.google.com with SMTP id u10so1670324pjc.5; Sat, 25 Feb 2023 04:32:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=MZwifdg3V2AYKI2D+QTV5l7LZjrn/pPvAdfyPGuW6vM=; b=UBQVGLrucc9fkXmdxZq73W1oLQcIlOG+AnhpPFIwilmIuaeLtfJlHQE/E2OTj+inNZ FBFxRWpJX2zEP1zFw4VDpoUXswwOF2s5I8ySX5GDp1JNgE8/c4SVKq7rEksO80HyAdWm +2e1qgDDp9iIijFxaLgQXsLuE84f0o7zm0pdrmp9uyX+tdJGXsfOz5Kdc7HOrsUtzPyP 9aznNtcehqiEhJW8B1QZWip/51ldFf7uprAUhblw5R7FkB9r5oqZ8A1nVxuPR0WOlpad KYQQ0EQQ77yY9P2VgncY41D4tw3VaZdU4VrmLNi0LkzcOnfVbpzweOFsXtdFUGIThqVz bRmA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=MZwifdg3V2AYKI2D+QTV5l7LZjrn/pPvAdfyPGuW6vM=; b=h9ciA/TrItbI3rRXJuQRhzqsFgQwIQZZeuFgDVuI5AXFMXV6/K9mH8BCdT/UsTASev q5TxlfloBupFOwbZVbCJEsqavcoTEgp0Tga0rA3ybHO+3o1V7z0Wh9D166FrMBL1b6E/ JoAzSYjFCTZmBSGYONs9rhwm5Skg5BCamEOwSOd9bTMR1ktlG4c+Ug1oPwhYRelNIjj/ 2vA/mjcn+/6QToe1kVwpTIzkCCFsN5dZCJl1XKEoYyilv2GNwWvxhIr0Bwzw7oh93qTX W7DwI3YqUz7Bu8CG2K99ohYee7+YdqNZcuVcAgGYIwqORslmqT3Ixx02n8vuxwhk5iFs 0MNQ== X-Gm-Message-State: AO0yUKWP9+gnZ8IAw0PnGninpgZ8Ux4UpegxnUs/E0qw8lQWOnpsgy/T j2X/R3sjJHpd0WQiII8EVM9W7Gu5XLHJOs/6DJNCM2Ku X-Google-Smtp-Source: AK7set+rVY6Cyj29oTaRApoLHrotCuKFgqMkj7YvD5T/VEtyrYxOp9wkkdP3JGrWy2Ee4Es7Zwxftfq5OHXord+1aB0= X-Received: by 2002:a17:90a:2a04:b0:236:704e:7bba with SMTP id i4-20020a17090a2a0400b00236704e7bbamr2684969pjd.1.1677328332612; Sat, 25 Feb 2023 04:32:12 -0800 (PST) In-Reply-To: <87lekm9j2v.fsf@cassou.me> Received-SPF: pass client-ip=2607:f8b0:4864:20::102d; envelope-from=owinebar@gmail.com; helo=mail-pj1-x102d.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, HTML_MESSAGE=0.001, 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: , 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:303799 Archived-At: --0000000000006fe91c05f5856f41 Content-Type: text/plain; charset="UTF-8" On Sat, Feb 25, 2023, 5:19 AM Damien Cassou wrote: > Eli Zaretskii writes: > >> Why isn't the compiler aware of the foo-var variable? > > > > Because lexical-binding is turned on? > > yes it is but I miss the deep understanding to fully understand. > Lexical binding isn't the issue - the variable is global in scope. The issue is that when you explicitly run the byte-compiler in batch mode, the "defvar" expression is only compiled, not evaluated, while the defmacro is evaluated, and the application of the macro function is evaluated during compilation. Hence you need "eval-when-compile" per Tomas's response. The reason it works in interactive mode is that the defvar is evaluated, not compiled, and the macro function is evaluated in the run-time environment. Lynn --0000000000006fe91c05f5856f41 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
On Sat, Feb 25, 2023, 5:19 AM Damien Cassou <damien@cassou.me> wrote:
Eli Zaretskii <eliz@gnu.org> writes:
>> Why isn't the compiler aware of the foo-var variable?
>
> Because lexical-binding is turned on?

yes it is but I miss the deep understanding to fully understand.

Lexical bin= ding isn't the issue - the variable is global in scope.
The issue is that when you explicitly run the byte-compiler in ba= tch mode, the "defvar" expression is only compiled, not evaluated= , while the defmacro is evaluated, and the application of the macro functio= n is evaluated during compilation.
Hence you need &q= uot;eval-when-compile" per Tomas's response.
The reason it works in interactive mode is that the defvar is evaluated, = not compiled, and the macro function is evaluated in the run-time environme= nt.

Lynn

--0000000000006fe91c05f5856f41--