From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.3 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 29870 invoked from network); 27 Mar 2021 20:28:19 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 27 Mar 2021 20:28:19 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20200801; t=1616876899; b=1Mjm/QHt5CDni6kTb5V3vqs/PayqH0xyEvk/rlZO2gefHxlpejozsAVosSdbwX3ojk4lELsD9n 4plXNqrEP+pEfQlKYhLyaVDV4BRn2cnFdw8umw3CT1L1IWvzO0GubDCKZXBvJCe6f9o3ZfM/x/ Xzwqq5qSJEYHqmM628LeKJaRlsQaEpmkV+oA3teflHoBKAhBixA3zlAWMRwfaiV1ebB58f8Yog kM34ir14ZdzzBVn2rcufpcyE7MUWvbybG0yk9Fh5qpZJEP83yBODTi6Ve5zhw04VtH7R2Ugclp bW4wUKycP/vmPfsRpBlvfUf1hdZCoIDzOXbn8Dis4ZbbGg==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (mail-ot1-f43.google.com) smtp.remote-ip=209.85.210.43; dkim=pass header.d=brasslantern-com.20150623.gappssmtp.com header.s=20150623 header.a=rsa-sha256; dmarc=none header.from=brasslantern.com; arc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed; d=zsh.org; s=rsa-20200801; t=1616876899; bh=ybk/uFP2Wd7jcsaxKUazvkFYgYnP4R2ElkKyJBaAsuA=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:Content-Type:To:Subject:Message-ID:Date:From:In-Reply-To: References:MIME-Version:DKIM-Signature:DKIM-Signature; b=ODiO/yax0sGSjMQKifYJ5Mfm03lq3wkSEy+2qZgnvQm092VzJVNhS/tUB2y5G/dzk/rCQNuBZT XsLvPhkDBv0NWkYTcl92kltAa4AH6hQEHJu3rGm5nWlPHB/VRcsJkNd887tKZhcdKOHcs2US/4 F+gK+fmjj7uKAtcRCScq6fxKCatPDr+pKsXg04FGLR7wFdItNcbqHVgim5uP/5PcikoouBiO/d UeBCrMapYsWAXSNEXnQ0wEzqhXPP58NjWYcFrn2RlefeNEytrmk58Pg3xnV/26ijUu7rB6L2bu AgvzjH35CK8+RXu/89Ch9EOytwsplkBQh+tC/LX6+eabPQ==; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=zsh.org; s=rsa-20200801; h=List-Archive:List-Owner:List-Post:List-Unsubscribe: List-Subscribe:List-Help:List-Id:Sender:Content-Type:To:Subject:Message-ID: Date:From:In-Reply-To:References:MIME-Version:Reply-To:Cc: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=PHJNYEQ0QSB/RN1IR+v2Px+A4wHKajE5/weWDQWLp4Q=; b=r3ckrJSGiU+AYDS4yO+EmupTN+ WN5h7PpqT+2kNa3llJdL4e98Vfj1TA3/sY8V0INyeb/3aCS8CDE1Oh+5WBARr27kdZwVBxApBEAVk 1l6lIb7T0A331YQdU++ZuVLJS0DY9ryuWpWgxuLSusDMj0bcuc04g/YdYsAiQlfMWguLYWvJMTU5E Dq+mKCJpIcywh+tf88bKzbXwOguMAyd+/BYQx+E8rT7ArJS7UTAPWIIREoy6BpBj1LMBlpeKzxj7P sbJNXMN+KPfD+H9KZ60hHUa0GzdRRmkF+uEGiE+AdIkBU5Z54KbiBSg2W8HvcgslkjUd59rM03/WR 7RDW4RrA==; Received: from authenticated user by zero.zsh.org with local id 1lQFXY-00054l-S7; Sat, 27 Mar 2021 20:28:12 +0000 Authentication-Results: zsh.org; iprev=pass (mail-ot1-f43.google.com) smtp.remote-ip=209.85.210.43; dkim=pass header.d=brasslantern-com.20150623.gappssmtp.com header.s=20150623 header.a=rsa-sha256; dmarc=none header.from=brasslantern.com; arc=none Received: from mail-ot1-f43.google.com ([209.85.210.43]:33680) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_128_GCM_SHA256:128) id 1lQFXI-0004vO-K6; Sat, 27 Mar 2021 20:27:58 +0000 Received: by mail-ot1-f43.google.com with SMTP id s11-20020a056830124bb029021bb3524ebeso8591639otp.0 for ; Sat, 27 Mar 2021 13:27:56 -0700 (PDT) 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; bh=PHJNYEQ0QSB/RN1IR+v2Px+A4wHKajE5/weWDQWLp4Q=; b=pqoXcHazW773hM5RezSWH7ES+HBTDrqJU6QCZGqF1PXx/iHFXLqglmyI0GYNFavXcV wUiZ0I1+TQlz9h6llOSaBd1TXI8T5rnQVKrl9hmx0ATwqBgpM8g9UTHNIH/TOnPzF+dr by1AHtXviLpHEpKeLoYGvgjtNfX68awSri1K2UpXHE0Mt5fVgqWLUpglNSv2EfgpUcmL rknqpMQtj2dlAcVTeWZLyFE3n1apWX4wt8JxCaFzK4SjBoLkrvRIyqdqER+14ZXdWd5q qt9c70u2yDrrPrHm7qbV6fOGy0kDzSDTpVJNjYzFkm3e1gcwXCtIikD2Y2+EB+4BDfia 7EwQ== 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=PHJNYEQ0QSB/RN1IR+v2Px+A4wHKajE5/weWDQWLp4Q=; b=RH9ahvkB88+XcmBLpGGLk3iKfa0arCCKhYA+z48TxIwhNriGr4EFNCOjcCB11l0i6b bXv0GVs/Q75WAIc/sAwtctuwIgO4lEwuod8NcOgYAcQ1MJ/47VJs3CeBRiAcJphyyEN6 SUnrWW8c8KLj2yoGvAdwEIPaDgyx0gbrNCsOEWGRIwE3R9CCxCFZxm1Ef93Vus+p7iLH kBJFCdLep/gEjTTq6LPKAJtXHRK3tHRLUK7vszharzwqaKTTqpjy3XdMdbchRxAL4Bms pUmNxkcvmJ6XaRzBjMdfZo4XsOs7d/ZQIr3glOsR9StIU8uqPMldTNdJXn8W/VcX9UjQ gazA== X-Gm-Message-State: AOAM533aD0FlIC3W566ieoZ0o1AZkoReHqdwb+3fU+D56ZmQFtKJAFff /7CrzYF1hBOaZ1+5ZDEvLo85/32v7sBwXCi7Jx2paOILKnSJug== X-Google-Smtp-Source: ABdhPJzS0lsS2xuGKASdKSq1M/Uoa6e3d3CNaSoePyuiNh+fCnhcKqKRjvxcEBR3geDR2Lk6OrsjKD3VR5dGmXn646M= X-Received: by 2002:a05:6830:20d2:: with SMTP id z18mr16701834otq.260.1616876875218; Sat, 27 Mar 2021 13:27:55 -0700 (PDT) MIME-Version: 1.0 References: <20201218131815.25999-1-mikachu@gmail.com> <20201219091314.dxslsscyiqffa3il@chazelas.org> In-Reply-To: <20201219091314.dxslsscyiqffa3il@chazelas.org> From: Bart Schaefer Date: Sat, 27 Mar 2021 13:27:44 -0700 Message-ID: Subject: Re: RFC PATCH: Sketch at :@ subscripting To: Mikael Magnusson , Zsh hackers list Content-Type: text/plain; charset="UTF-8" X-Seq: 48272 Archived-At: X-Loop: zsh-workers@zsh.org Errors-To: zsh-workers-owner@zsh.org Precedence: list Precedence: bulk Sender: zsh-workers-request@zsh.org X-no-archive: yes List-Id: List-Help: List-Subscribe: List-Unsubscribe: List-Post: List-Owner: List-Archive: Archived-At: On Sat, Dec 19, 2020 at 1:13 AM Stephane Chazelas wrote: > > 2020-12-18 14:18:15 +0100, Mikael Magnusson: > [...] > > The idea is that you can do this: > > % typeset -a somearray=( 'data here' 'some words' etc etc 1 2 3 4 ) idx=(1 3 5) > > % echo ${somearray:@idx} > > data here etc 1 > [...] > > Hi Mikael, > > I can't help but think that allowing to specify the indexes > directly as perl does for instance in: > > print @list[1, 4, 2, 7..10, @idx, -1]; The way to do this (syntactically speaking) would be with a subscript flag. E.g.: print $array[(^)1,3,7] would change the interpretation of the commas to select a set of elements instead of a range. I chose (^) because of symmetry with $^array and to avoid confusion with for example $array[@]. I haven't looked into how difficult that might be to implement, particularly in assignment context. Another possibility is to handle $array[{1,3,7}] specially since "{" is already a syntax error in math context. Both of those options could apply to associative arrays, although keys would need to respect quoting to avoid troubles with an embedded ",". > $ i=1,3 > $ echo ${a[i]} > c Here [i] is interpreted in math context so the comma becomes an operator (the collision you already noted) so this becomes $a[3] > $ echo ${a[$i]} > a This one is confusing and a bug ... it should be the same as ${a[$[$i]]} but instead it's ${a[,3]}. I haven't tracked down exactly what's skipping everything up to but not including the first comma (it is not, for example, just dropping one character).