Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Can you loop in math mode?
- X-seq: zsh-users 24156
- From: Stephane Chazelas <stephane.chazelas@xxxxxxxxx>
- To: Sebastian Gniazdowski <sgniazdowski@xxxxxxxxx>
- Subject: Re: Can you loop in math mode?
- Date: Mon, 19 Aug 2019 07:20:28 +0100
- Cc: Zsh Users <zsh-users@xxxxxxx>
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:mail-followup-to:references :mime-version:content-disposition:in-reply-to:user-agent; bh=1oyq6jjHC1huLvkHpLnei4ADSGe8AsTxJ0FqDDDNiRQ=; b=dSeOmDmvULp9K1HhtnSDp9AgMaG10tLsAWHHgx7wYmJXMv/aQT59e+AXaTjQ+NZ7c8 dJeX862ufRqyHWAZHDBy3+aXHJKPF5O3bjM4UK8OH2IFRV8epr/iBITX30YQ/vcITtvN ov+E2IJTrysKp/vb7bdQzesEmjXjJw473u1IAeV9e7/A+nxFvy/2RVyJuaDGsvsGJUz2 hnL3wxHYdI1467Ujoue3F8/Z9m934vmYqZWCxBSxdL9aljJu9dKweQvuaQjz2xlwuuR2 t6lQgFgRD22wXqB6wij5uDsEznSwy8ZW4MIBmvkYInqdzLMGkGKhZ4vwFv3Q6X5v5O5j rTmQ==
- In-reply-to: <CAKc7PVDnSqZMpQz=8L5b+SijziN1aUYkm0C-Pv3FMSVy-mg_0Q__8285.33232431568$1566173873$gmane$org@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>
- List-unsubscribe: <mailto:zsh-users-unsubscribe@zsh.org>
- Mail-followup-to: Sebastian Gniazdowski <sgniazdowski@xxxxxxxxx>, Zsh Users <zsh-users@xxxxxxx>
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
- References: <CAKc7PVDnSqZMpQz=8L5b+SijziN1aUYkm0C-Pv3FMSVy-mg_0Q__8285.33232431568$1566173873$gmane$org@mail.gmail.com>
2019-08-19 02:16:20 +0200, Sebastian Gniazdowski:
[...]
> is some kind of a looping possible in math mode?
[...]
Can you maybe be more specific as to what you're trying to do?
You can use recursion:
$ n=6 a='(n-->1 ? a*(n+1) : 1)' zsh -c 'echo $((a))'
720
(6!)
Including via math functions, but within limits.
$ n=0 a='(++n <= 255 ? a+2 : 1)' zsh -c 'echo $((a))'
zsh:1: math recursion limit exceeded: (++n <= 255 ? a+2 : 1)
And you can of course have command substitutions inside an
arithmetic expression:
$ echo $(( 1 $(for i ({2..6}) print "*$i") ))
720
--
Stephane
Messages sorted by:
Reverse Date,
Date,
Thread,
Author