From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 734 invoked by alias); 25 Jul 2017 21:21:18 -0000 Mailing-List: contact zsh-users-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Users List List-Post: List-Help: X-Seq: 22786 Received: (qmail 23674 invoked from network); 25 Jul 2017 21:21:17 -0000 X-Qmail-Scanner-Diagnostics: from mail-it0-f47.google.com by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.99.2/21882. spamassassin: 3.4.1. Clear:RC:0(209.85.214.47):SA:0(0.5/5.0):. Processed in 1.775544 secs); 25 Jul 2017 21:21:17 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=0.5 required=5.0 tests=HTML_MESSAGE, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,RCVD_IN_SORBS_SPAM, SPF_PASS,T_DKIM_INVALID autolearn=no autolearn_force=no version=3.4.1 X-Envelope-From: dana@dana.is X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | Received-SPF: pass (ns1.primenet.com.au: SPF record at _netblocks.google.com designates 209.85.214.47 as permitted sender) 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== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=Jm7suXaEkbnjwpf74Abnn6jA1YVRRxlx/ChtM5Vjjbg=; b=dRU7DIzZEusGnjIGLgvnuxILnbtIhbf856bVktxz30CAvNbZYfHgqeT+uD+nGcsJbM PZa3OZpdnYTcRgWIrFI4nAL0QYu+4UtVYBnqAhTWLOwrA7iNLOOJ3m+Fw0dxPykedf81 BAPlNsXToy3I4QQ7JUNT0u5dcpLU7aSHz/CNQ5QnAZ/B7WAyHDGa9ywBYKtm7hEjQjtX CU0EIBeVjZwcyD2RjTsyO6DQIdiNs9saVi2WkolHW2Fr8IvAnrj3OYveAMpGH3kHOZ/c /xrfjS+J0S0ckU8jypMAuicfXfaGYZ3ZMMDYbR2v0cl+egHV3xWzJSDyckvaqrRmatoX bjmA== X-Gm-Message-State: AIVw113Q0N4zCtQWlnVfNsXPFfK2hbFXAz2so1O9+ykORaYnz4Q+D2hf W88rSr4Doy1d9oyNWwMFLoPiWmfs63aVeVQ= X-Received: by 10.36.210.194 with SMTP id z185mr12165533itf.102.1501017670320; Tue, 25 Jul 2017 14:21:10 -0700 (PDT) MIME-Version: 1.0 X-Originating-IP: [208.123.231.44] In-Reply-To: References: From: dana Date: Tue, 25 Jul 2017 16:20:29 -0500 Message-ID: Subject: Re: Determining whether a function is used in an arithmetic context To: Zsh Users Cc: Bart Schaefer Content-Type: multipart/alternative; boundary="94eb2c0554fa0aa02905552ae97f" --94eb2c0554fa0aa02905552ae97f Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable I suppose that'll do. Thanks! On 25 July 2017 at 02:03, Bart Schaefer wrote: > On Mon, Jul 24, 2017 at 8:47 PM, dana wrote: > > > > I was playing with arithmetic functions recently and i wanted to have o= ne > > 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]} =3D=3D 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 =E2=80=94= 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. > --94eb2c0554fa0aa02905552ae97f--