From: "Lawrence Velázquez" <larryv@zsh.org>
To: linuxtechguy@gmail.com
Cc: zsh-users@zsh.org
Subject: Re: anonymous function question
Date: Mon, 22 Aug 2022 23:36:03 -0400 [thread overview]
Message-ID: <4f73130d-1d7b-46af-ab04-72a04fc89727@www.fastmail.com> (raw)
In-Reply-To: <CA+rB6GKnzYir24SimTsqvROE=h22crW-LLFj8LR8N6ufD_Lw=w@mail.gmail.com>
On Mon, Aug 22, 2022, at 10:11 PM, Jim wrote:
> Is this normal for an anonymous function?
This is not just about anonymous functions. You can observe the
same behavior with regular functions and other complex commands.
% unsetopt INTERACTIVE_COMMENTS
% foo() {
function> setopt INTERACTIVE_COMMENTS
function> #echo test
function> }
% foo
foo:2: command not found: #echo
% unsetopt INTERACTIVE_COMMENTS
% (
subsh> setopt INTERACTIVE_COMMENTS
subsh> #echo test
subsh> )
zsh: command not found: #echo
% unsetopt INTERACTIVE_COMMENTS
% if :; then
then> setopt INTERACTIVE_COMMENTS
then> #echo test
then> fi
zsh: command not found: #echo
> Why doesn't setting interactive_comments within an anonymous function work?
Someone please correct me if I'm mistaken, but I believe that:
- Comment removal is performed during parsing. Thus, setting and
unsetting INTERACTIVE_COMMENTS changes how parsing is done.
- A complex command is parsed *in its entirety* before *any* of its
commands are executed. Thus, a command within a complex command
cannot affect how the rest of the complex command is parsed.
Therefore, a complex command cannot enable or disable comments
within itself. It can affect subsequent commands, though:
% unsetopt INTERACTIVE_COMMENTS
% {
cursh> setopt INTERACTIVE_COMMENTS
cursh> #echo test
cursh> }
zsh: command not found: #echo
% #echo test
%
I don't know whether any of this is explicitly described in the
documentation.
--
vq
next prev parent reply other threads:[~2022-08-23 3:37 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-08-23 2:11 Jim
2022-08-23 3:36 ` Lawrence Velázquez [this message]
2022-08-23 4:54 ` Jim
2022-08-23 7:21 ` Roman Perepelitsa
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4f73130d-1d7b-46af-ab04-72a04fc89727@www.fastmail.com \
--to=larryv@zsh.org \
--cc=linuxtechguy@gmail.com \
--cc=zsh-users@zsh.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).