Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: anonymous function question
- X-seq: zsh-users 27987
- From: Lawrence Velázquez <larryv@xxxxxxx>
- To: linuxtechguy@xxxxxxxxx
- Cc: zsh-users@xxxxxxx
- Subject: Re: anonymous function question
- Date: Mon, 22 Aug 2022 23:36:03 -0400
- Archived-at: <https://zsh.org/users/27987>
- Feedback-id: iaa214773:Fastmail
- In-reply-to: <CA+rB6GKnzYir24SimTsqvROE=h22crW-LLFj8LR8N6ufD_Lw=w@mail.gmail.com>
- List-id: <zsh-users.zsh.org>
- References: <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
Messages sorted by:
Reverse Date,
Date,
Thread,
Author