Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Can't call multi-arg math function from array subscript
- X-seq: zsh-workers 40930
- From: Mikael Magnusson <mikachu@xxxxxxxxx>
- To: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- Subject: Re: Can't call multi-arg math function from array subscript
- Date: Sun, 2 Apr 2017 22:36:52 +0200
- Cc: zsh workers <zsh-workers@xxxxxxx>
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=eK6kn+lAX+pKyY3tIj30gNV11mn83kPcahsCaI3b92U=; b=s8SgrzAK5mWd87ue1y7WqeO2khDtQLYc6Q3xh+p4tcfFMSDzG1Om4ahjXkUYBfImZd QZNB6A9q+nsiJDS/OuEv21Wv8oDsiJEBqIeo9YC5QBqMWF7hBvxjoKtjW3KyfWMlYx77 W7ecFHNbLmhMVgGB0pr6Fcp8MBexSnX2Y5cwdUKJyumj0KpgofrPH/MGDucqbX4PZzqu FqMJWCpuHqBuwmwavZSndPkRIg9aCucGWgve4rlKCRRPJGwZFqjqwauuKZTediczvhzp 2BTdjfZY4rQWJ8L7gf0n8oBJPk3ya/lhpVr/Kpc5NLIh3ZHD2apZZh06vmN7W9YexfxW n7rw==
- In-reply-to: <170402115156.ZM27355@torch.brasslantern.com>
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
- References: <170402115156.ZM27355@torch.brasslantern.com>
On Sun, Apr 2, 2017 at 8:51 PM, Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> 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
Messages sorted by:
Reverse Date,
Date,
Thread,
Author