Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Determining whether a function is used in an arithmetic context
- X-seq: zsh-users 22783
- From: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- To: Zsh Users <zsh-users@xxxxxxx>
- Subject: Re: Determining whether a function is used in an arithmetic context
- Date: Tue, 25 Jul 2017 00:03:48 -0700
- Cc: dana <dana@xxxxxxx>
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brasslantern-com.20150623.gappssmtp.com; s=20150623; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=tci23MNY/dgohIYjmQ1gNGUFIi4T7oesZi2HZFe1zGA=; b=z7uJzbRFLWay8nNdhn1HNKX+FEEfOnv4vjwzaylbOpTMgtAIkPWboxfRiDRz985fK3 VQkclKyK28jtVqn/BSKV9gZByMoT2kPrHDt/oH/jIEOR/M7M8Fy9WxZl0LMwVtaIKn0m kCWoQJsqzFLAEAMbBAi3nB/DmXqnacMs1Ql/wL3hPeKVTJAOFh/hOoLwKLIx7f+AzoPO nTvKFzWku1jxA2NzVTPkba2JtEf9x4YAJ7vHpIYFreLNhJTB9qBeo86X4eR7Ru14Jt5h tVuAnzEXhRuAsRkvkn1HFzKGoxagY/5CfmD3KPSQgkjBBYF1Zf5SR0SAnc8yw7PjVFCu fh2w==
- In-reply-to: <CA+_8RBDSKtMkaQM+UXxavB5NCc1M=HbBhiJbboCMDtCH2e37yA@mail.gmail.com>
- List-help: <mailto:zsh-users-help@zsh.org>
- List-id: Zsh Users List <zsh-users.zsh.org>
- List-post: <mailto:zsh-users@zsh.org>
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
- References: <CA+_8RBDSKtMkaQM+UXxavB5NCc1M=HbBhiJbboCMDtCH2e37yA@mail.gmail.com>
On Mon, Jul 24, 2017 at 8:47 PM, dana <dana@xxxxxxx> wrote:
>
> I was playing with arithmetic functions recently and i wanted to have one
> of them behave differently depending on whether it's used in an arithmetic
> context or not. I can't seem to figure out a *reliable* way to detect that
I guess I'd do it like this:
myfunc() {
if [[ ${funcstack[2]} == myfunc_math ]]
then print In math context
else print Not in math context
fi
}
myfunc_math() {
myfunc "$@"
}
functions -M myfunc 1 1 myfunc_math
> The %_ prompt expansion seemed like it might be the way to go — it produces
> math when used in an arithmetic command... but not an arithmetic
> *substitution*, strangely. (Is that expected?)
Yes, it's expected, because it's the parser state -- by the time the function is
actually executing, the parser is done. %_ is only meaningful during program
input (typically interactively) or in an execution trace, not during
execution itself.
I think it's accidental that it has a value during arithmetic commands.
Messages sorted by:
Reverse Date,
Date,
Thread,
Author