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.0 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, 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 0f211481 for ; Thu, 12 Sep 2019 05:36:03 +0000 (UTC) Received: (qmail 11632 invoked by alias); 12 Sep 2019 05:35:54 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: List-Unsubscribe: X-Seq: 44757 Received: (qmail 5107 invoked by uid 1010); 12 Sep 2019 05:35:54 -0000 X-Qmail-Scanner-Diagnostics: from mail-lj1-f194.google.com by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.101.2/25566. spamassassin: 3.4.2. Clear:RC:0(209.85.208.194):SA:0(-1.9/5.0):. Processed in 3.754209 secs); 12 Sep 2019 05:35:54 -0000 X-Envelope-From: schaefer@brasslantern.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.208.194 as permitted sender) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brasslantern-com.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=fv62WYhJDOYFzlUCapKNw7g9XBZbFPDG6Z1F7zQcqsU=; b=PtfxQyX/tdU3f+U0xWAH0H8PzDvDK4gU0eZ4wBQ7iScUupJbo1Bfc/bUyY/qvel4u5 785vBG25YQbBo2dU0foAc8Yn77Q3YArj1IBoeCQ629HbBd4lCoYKdae1J7jdeRLtAtJZ hmYER1XXiV3g5n896iaVce4YJKGmUrE540wUUA0ZXXBMia10LFQwinjVB7Eaw2yDeNN7 NMl0eQtNP0nLzI0RGWixdJQh1FSlKrvfu0+4BUqOxleY18I9s9u1hSNZ3pLciTQa0hQT 29n9zBZa30zaGjNdXL5C2oAzjZqaBH6vdfstaDOA3ItWm9dmCgBfxQbtBnnQ700oI3AE 7XQA== 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:cc; bh=fv62WYhJDOYFzlUCapKNw7g9XBZbFPDG6Z1F7zQcqsU=; b=ekXZBmD1bNvRBcfm2ar26c9Aa6l5xXfh28x7Slon0jCmobjIgOsZXdFvfI8ZIaz2Gv fpFNu32FfwZ7u2pihbc01ycTnkkoK2q579PwL0W9LQbBo4wMFmduFHAFNcKZgMGYm91S /vsQLwRIWvglgpWarAIokFThNPAK7J+Zyqt1bysxBVQ6rOaZDyycW3q3d2viuvZskogg 0H6uZHdLqikRvl0YYYYmPa07etu4/lMncXPZFY0/b0GsmfK5IdeRI5c6w7x71BktOOVZ 6nrTY/0TVxr7webttodga8bKUury9eVXBOxPvAwaZWOWKp6peN3EzTzypkLabHqIy61e KeRw== X-Gm-Message-State: APjAAAWT5PX+Jz1O3GyaxMl8/UYAfTy5igOobnyJKR8QFqZSSe5PGNOR QRQqpkB5PT1zH6vPAeqM7cSRaWlVjDtDYJIgCXsjHw== X-Google-Smtp-Source: APXvYqycqSH5x1dn3n15Qptw7lv+b+bMdcLC/q/WWFYaT8I06WxzFSGiplqlAS065H8bJm6d9+pWEyLqucnd2UDAq9M= X-Received: by 2002:a2e:6e1a:: with SMTP id j26mr5053191ljc.172.1568266515406; Wed, 11 Sep 2019 22:35:15 -0700 (PDT) MIME-Version: 1.0 References: <20190907150741.jwztdoslrvk5j7nk@chaz.gmail.com> <20190907201954.dn2nve65wqk4muvc@chaz.gmail.com> In-Reply-To: From: Bart Schaefer Date: Wed, 11 Sep 2019 22:35:03 -0700 Message-ID: Subject: Re: [PATCH] Support the mksh's ${|func;} substitution To: Sebastian Gniazdowski Cc: Zsh hackers list Content-Type: text/plain; charset="UTF-8" On Wed, Sep 11, 2019 at 7:07 PM Sebastian Gniazdowski wrote: > > On Thu, 12 Sep 2019 at 03:03, Bart Schaefer wrote: > > > > In an (e) glob, REPLY is set to each possible file name in turn, but > > $reply can provide multiple names to the final result. > > array( "a" "b c" "d" ) > func() { reply=( ${=REPLY} ); } > array=( ${(x^func^)array} ) > > and it would result in FOUR array elements, not three. [...] > I think that in order to > allow contraction of the result, the (x) flag could use only reply, > without REPLY as opposed to the (e), unless we do that reply being > just set invalidates REPLY and allows the empty result. Hm, perhaps you're still confused about something. The value of $REPLY means nothing after the code has run -- it's strictly an input. $reply is the only output. So if we were to do as I'm suggesting, array( "a" "b c" "d" ) func() { if (( ${#${=REPLY}} > 1 )) then reply=() else reply=( $REPLY ) fi } array=( ${(x^func^)array} ) would result in two elements ("a" "d"). Oh, I've forgotten an important bit -- the return value of the code matters as well. The full semantics is: 1. on entry, REPLY is set to one element and reply is unset 2. If the code returns nonzero (false, failure) then the result is the empty array (so the corresponding element is removed from the input set) 3. else if reply has become set, that array is used (even if empty) (so the corresponding element may become zero, one, or more elements) 4. else if REPLY is set, the value of REPLY is used (so the corresponding element changes, possibly to an empty string) 5. else the original element is unchanged > > Whether the syntax ${(x+func)...} would call "func" once for each > > array element (again by analogy to glob (e+func)) > > Why only one + in the examples? (I've tried this syntax with (e), it > doesn't seem to support it). Oops, I've typo'd. as a glob flag, (+func) is (e:func:), you don't use (e+). I don't think we can get away with using a bare leading "+" like that in parameter flags. Here are examples globbing in my zsh source (gmail is probably going to line wrap some of this, sorry): % i=0; echo *(oNe:'REPLY=$((++i))':) 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 % echo *(e:'() return 1':) zsh: no matches found: *(e:() return 1:) % func() { if (( $#REPLY > 4 )); then REPLY=; fi } % echo *(oNP:,:+func) , Misc , , , , , Test , Util , , , , , , , , , Etc , , , , , , , , , , NEWS , , , , , , , , , Doc , , , zsh , , , , Src % func() { if (( $#REPLY > 4 )); then reply=(); fi } % echo *(+func) Doc Etc Misc NEWS Src Test Util zsh