From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 10448 invoked by alias); 21 Oct 2016 16:20:36 -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: X-Seq: 22016 Received: (qmail 24691 invoked from network); 21 Oct 2016 16:20:36 -0000 X-Qmail-Scanner-Diagnostics: from mail-vk0-f49.google.com by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.99.2/21882. spamassassin: 3.4.1. Clear:RC:0(209.85.213.49):SA:0(0.0/5.0):. Processed in 0.925832 secs); 21 Oct 2016 16:20:36 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.1 X-Envelope-From: schaefer@brasslantern.com X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | Received-SPF: none (ns1.primenet.com.au: domain at brasslantern.com does not designate permitted sender hosts) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brasslantern-com.20150623.gappssmtp.com; s=20150623; h=from:message-id:date:in-reply-to:comments:references:to:subject :mime-version; bh=8esddEFLaWZMP/Z5KBmIBatnZfFFCXyM/ef/4ZujQ6Q=; b=QYjs8I9iDPLyV2ThZh9cdffIX3xWkbKCE0HZ+81ccPGJsm4YRGaWStHzbWdK6cv146 zNzwTo9owLbLRZxlZa26n6p8UlqCuiKpjqTwxDXd/Nvv0MLErlKUlFtfJdnhizqQHual f77doaSeEsb6UZRXgY9iivh3UjrFHUipBYG3Knam+mwfUzqs8yTuIakoW/6P+pkkTJQn 7jNp12nHinW9TCrEITbLMLRUPHHUh1F3koubWGERaD4UR70NymlImDN7irXkx7d/Qv3X i0i0noFu4MawP2Or/dKf7yaa80Lnr7mhbKYJ9rSR/TH/VBdi9VuD0tTr7L34LKVWg3Z0 oPZg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:message-id:date:in-reply-to:comments :references:to:subject:mime-version; bh=8esddEFLaWZMP/Z5KBmIBatnZfFFCXyM/ef/4ZujQ6Q=; b=b9cs7pd1Kl3DfpCAvE0fmq8VKxQbML+Gr3duyFiYzCfcWx28zaBw3IixdRMtILKjQ3 tM9O9ogduimovpD/WgPBnoZr+QUy/x0CoZXGgBset3dGhzyRCeWlvfhhCNB53d/390OO YUASilak1pB7bC4C/eB1FFMcEiAthJn6Hs1Iv1UR4A86mIvGi6cR3uZ68JQVXZLp4hrX EtSobBy2G/h7IKXiWo8QUE1z1XHvrJMVRSDub1dpDW8HZjH+YaKmNAfUJ3TdV8w14u7u duW0AP06+5YjoRZTARSTlS7uQiuSVC+fR/0mrvaMYEglhzd+HaXzdtyk6i2fVRJ8Y+L+ I2Rw== X-Gm-Message-State: ABUngvfmw0bTG6CO65agFLzObSuDxSjwjmfrN6KQ+GDjKvKP4Se91h/wgvyuWIvvAKjV8A== X-Received: by 10.31.226.66 with SMTP id z63mr1248086vkg.103.1477066824015; Fri, 21 Oct 2016 09:20:24 -0700 (PDT) From: Bart Schaefer Message-Id: <161021092027.ZM8789@torch.brasslantern.com> Date: Fri, 21 Oct 2016 09:20:27 -0700 In-Reply-To: <536851559.167591.1477040396961@mail.yahoo.com> Comments: In reply to "Tip of the day: (@)...[(R)...] is equal to (@M)...:#... and faster by 18-21%" (Oct 21, 8:59am) References: <536851559.167591.1477040396961.ref@mail.yahoo.com> <536851559.167591.1477040396961@mail.yahoo.com> X-Mailer: OpenZMail Classic (0.9.2 24April2005) To: "zsh-users@zsh.org" Subject: Re: Tip of the day: (@)...[(R)...] is equal to (@M)...:#... and faster by 18-21% MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii On Oct 21, 8:59am, wrote: } } found=( "${(@M)history:#(#i)*$~search_pattern*}" ) } } can be replaced by: } } found=( "${(@)history[(R)(#i)*$~search_pattern*]}" ) } } I wonder if there are there any pitfalls in such replacement? There are some differences in the way the pattern may be interpreted when it appears inside a subscript expression. There is an entire section of the documentation (15.2.4 in "info" or HTML docs) devoted to explaining this. One paragraph in particular applies here: A last detail must be considered when reverse subscripting is performed. Parameters appearing in the subscript expression are first expanded and then the complete expression is interpreted as a pattern. This has two effects: first, parameters behave as if GLOB_SUBST were on (and it cannot be turned off); second, backslashes are interpreted twice, once when parsing the array subscript and again when parsing the pattern. In a reverse subscript, it's necessary to use _four_ backslashes to cause a single backslash to match literally in the pattern. For complex patterns, it is often easiest to assign the desired pattern to a parameter and then refer to that parameter in the subscript, because then the backslashes, brackets, parentheses, etc., are seen only when the complete expression is converted to a pattern. To match the value of a parameter literally in a reverse subscript, rather than as a pattern, use `${(q)NAME}' to quote the expanded value. So in your example you don't need "$~search_pattern", the expansion is always interpreted as a pattern. I think the literal match advice in the final sentence could preferentially be ${(b)...} nowadays; there are a couple of things about the array subscripting doc that might need update.