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 22786
- From: dana <dana@xxxxxxx>
- To: Zsh Users <zsh-users@xxxxxxx>
- Subject: Re: Determining whether a function is used in an arithmetic context
- Date: Tue, 25 Jul 2017 16:20:29 -0500
- Cc: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dana-is.20150623.gappssmtp.com; s=20150623; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=Jm7suXaEkbnjwpf74Abnn6jA1YVRRxlx/ChtM5Vjjbg=; b=mOWxVf7bbKsJc1ymhUQV0g9hPfc/VOYQVy7aKpDf7B+BLDF66ed62NCW/N7bDlZsVD XUhXAHD+w4x2JYO8NfWW7xQCsPR6Cwv/kwBXq1hcmSUaOOYfakC0oVuDXcYjyMv1Qp+K k9Ah1+fMQB/c+VAcU9pDkDMC/xuoVq3A/HpL0+HEumvnK10bep12knCNAzqhTwuDLQJ4 cIsMutfqYitrlCdVigN1L2JzUKCT9jxOSz/z91bvQScXtAo6nHcu3GOvmE86/oBybnbX qFZtxxVjb3fhLEke2T9AT/Mb7d7c1MjjOwojOomjbSRs8B3V69FTZinX6Uc95W9h18ev f0QA==
- In-reply-to: <CAH+w=7Zw050rLmJWN+ON27AZ=V7Qhace8ms8F-PYCp0biaUH5Q@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> <CAH+w=7Zw050rLmJWN+ON27AZ=V7Qhace8ms8F-PYCp0biaUH5Q@mail.gmail.com>
I suppose that'll do. Thanks!
On 25 July 2017 at 02:03, Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> wrote:
> 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