zsh-workers
 help / color / mirror / code / Atom feed
From: Mikael Magnusson <mikachu@gmail.com>
To: Bart Schaefer <schaefer@brasslantern.com>
Cc: zsh workers <zsh-workers@zsh.org>
Subject: Re: Can't call multi-arg math function from array subscript
Date: Sun, 2 Apr 2017 22:36:52 +0200	[thread overview]
Message-ID: <CAHYJk3Q4-18_RKz4kZgBKDAkDO_eS2fmUQU852yHrCwS0hFJQg@mail.gmail.com> (raw)
In-Reply-To: <170402115156.ZM27355@torch.brasslantern.com>

On Sun, Apr 2, 2017 at 8:51 PM, Bart Schaefer <schaefer@brasslantern.com> wrote:
> Single-argument functions are OK:
>
> % string='abcde'
> % onearg() { return $1 }
> % functions -M onearg
> % print ${string[1,onearg(3)]
> abc
>
> Add another argument and strange things start happening:
>
> % twoarg() { return $(( $2 - $1 )) }
> % functions -M twoarg
> % print ${string[1,twoarg(1,4)]}
> twoarg: bad math expression: operand expected at end of string
> twoarg: bad math expression: operand expected at end of string
>
> Why two error messages?
>
> I assume the comma is messing things up; let's try it like this:
>
> % print ${string[1,$(( twoarg(1,4) ))]}
> zsh: parse error
> zsh: parse error
>
> Just to confirm:
>
> % print ${string[1,$(( onearg(4) ))]}
> abcd

I guess this basically confirms that the comma messes up parsing:

% func='twoarg(1,4)'
% print ${string[1,func]}
abc


-- 
Mikael Magnusson


  reply	other threads:[~2017-04-02 20:36 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <CGME20170402185230epcas1p467fce7a708bf94d7f2c8e032327196d9@epcas1p4.samsung.com>
2017-04-02 18:51 ` Bart Schaefer
2017-04-02 20:36   ` Mikael Magnusson [this message]
2017-04-03  8:51   ` Peter Stephenson

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=CAHYJk3Q4-18_RKz4kZgBKDAkDO_eS2fmUQU852yHrCwS0hFJQg@mail.gmail.com \
    --to=mikachu@gmail.com \
    --cc=schaefer@brasslantern.com \
    --cc=zsh-workers@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).