From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-1.1 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from primenet.com.au (ns1.primenet.com.au [203.24.36.2]) by inbox.vuxu.org (OpenSMTPD) with ESMTP id 16288a14 for ; Mon, 19 Aug 2019 06:42:14 +0000 (UTC) Received: (qmail 5968 invoked by alias); 19 Aug 2019 06:42:03 -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: List-Unsubscribe: X-Seq: 24157 Received: (qmail 4646 invoked by uid 1010); 19 Aug 2019 06:42:01 -0000 X-Qmail-Scanner-Diagnostics: from mail-vs1-f49.google.com by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.101.2/25545. spamassassin: 3.4.2. Clear:RC:0(209.85.217.49):SA:0(-0.1/5.0):. Processed in 3.789329 secs); 19 Aug 2019 06:42:01 -0000 X-Envelope-From: sgniazdowski@gmail.com 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.217.49 as permitted sender) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to; bh=iSGdCmls1Qmu96Rrr7ixR8edRMv51/Hih2ecZsSVidI=; b=uvudtj6Qio8YCt4rrJL2oURCJ+Xcf5KMTkPvpMsRpanmw1KZfOg2yhVQy16QAvTlb0 IxVXcOksjERvxrYqISeU20RYpnBRBvjCnErOzM0MNXVkEhwAJzLhU5YFjGQiFl2xRvjW rmXSrKAiny6dlGLf7/UnqJ2CGFyL5U1nCtBT2yDESZaDEcpVWRqPrEkYvJT1wNq+DIEU 6OfNXugQytPpm/TDO51B3SkvxtcS/jCzmyWbomgc/hghaQP1o4p4lrJyAd9PksihC3nc dsK+cegCTIp2H5XJqtzfcFcCSk6mZQLrPKDlRJfNCj3OAX52xnc6+pU5mRPWtxbwAa17 4AbQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to; bh=iSGdCmls1Qmu96Rrr7ixR8edRMv51/Hih2ecZsSVidI=; b=qjDbF5fLsaZgQkMltYpSnPDHLNtQHZp5+HA7saeZ2e4Mt+ssf5Fab5Fek982wWFrvz OxMeV6IKbK05IIgrlybzxq2Po/h/9hfmjr5R0BLC2wCyvyANGZILaPFAqvFpznn4ERA3 Cl0vdPyBn3npXsTn0Om8iFGxLD7H5kRbq+l4F2Rbs28VxW2lNQLzxro/0r+COJJ4l3dl 65K5zWqMQsaiSo7cOzKKGsD4fdMLoMeh1VYLuDuc/vGtzUNgUyz0WnncTuEJlaRAh0pR oOVJS2OOf6/M0RFiqh5nFOxnNYMkWivNZVGgyCtTbf1YjxjqXOAaDtPpjvQXW6yXKK9t ALcw== X-Gm-Message-State: APjAAAUhqg3ny48wtFexUBRY+gV1O7BXey8zuwfNeLNtunNXBgFnqZnP XEyvWoBHNPY8hpV2IBhLabGQxxZOwAH5MSS1346qrW07Rvs= X-Google-Smtp-Source: APXvYqy6lzpPLw1TYL/1kQoKCE7NaA+CtF9a7LGCt2G9GsNFkh0iSIz/vs4Pz4m4IR4b3RBsQ2Z3GIfRopF8euMv9n8= X-Received: by 2002:a67:ce8d:: with SMTP id c13mr12269838vse.77.1566196884410; Sun, 18 Aug 2019 23:41:24 -0700 (PDT) MIME-Version: 1.0 References: <20190819062028.dkewms2nxt37o4te@chaz.gmail.com> In-Reply-To: <20190819062028.dkewms2nxt37o4te@chaz.gmail.com> From: Sebastian Gniazdowski Date: Mon, 19 Aug 2019 08:41:12 +0200 Message-ID: Subject: Re: Can you loop in math mode? To: Sebastian Gniazdowski , Zsh Users Content-Type: text/plain; charset="UTF-8" I'm writing a function that computes lengths of the lines in BUFFER and builds up an array, where each element is a sum of the previous and the current line / element. So I have: integer idx sum lines_lengths=( ${lines_lengths[@]/(#m)*/$(( sum += ${#MATCH}+1 ))} ) However, I would also like to take into account screen lines, so i.e. gradually decline ${#MATCH} by COLUMNS bit by bit, assigning a new element also for each screen-line. Like the following function does: .zed-compute-llen() { len=${#1} while (( len > COLUMNS )) { sum+=COLUMNS lines_lengths[++idx]=( $sum ) len=len-COLUMNS } sum+=len+1 lines_lengths[++idx]=( $sum ) } So basically, I would want to do this in the // substitution, like so: : ${lines_lengths[@]/(#m)*/$(( append(${#MATCH}) ))} which now thus just resolved :] I don't even need the string-math function, append should add multiple lines_lengths elements if len > COLUMNS, that's all. But thanks for the answer, I think I could use recursion for this too. On Mon, 19 Aug 2019 at 08:20, Stephane Chazelas wrote: > > 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 -- Sebastian Gniazdowski News: https://twitter.com/ZdharmaI IRC: https://kiwiirc.com/client/chat.freenode.net:+6697/#zplugin Blog: http://zdharma.org