From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 28209 invoked by alias); 8 Jun 2018 05:54:53 -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: 42951 Received: (qmail 24189 invoked by uid 1010); 8 Jun 2018 05:54:53 -0000 X-Qmail-Scanner-Diagnostics: from au-smtp-delivery-203.mimecast.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(124.47.189.203):SA:0(-2.6/5.0):. Processed in 1.464587 secs); 08 Jun 2018 05:54:53 -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=-2.6 required=5.0 tests=BAYES_00,HTML_MESSAGE, RCVD_IN_DNSWL_LOW,SPF_PASS,T_DKIM_INVALID autolearn=ham autolearn_force=no version=3.4.1 X-Envelope-From: michael.milton@unimelb.edu.au X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=unimelb.edu.au; s=mimecast20161020; t=1528437291; h=from:subject:date:message-id:to:mime-version:content-type:in-reply-to:references; bh=iQgXNzbVpAIrMU/dhmlRn7Q++CoNgNOE3Um8+GLN8Oc=; b=ItNOzPbYowhULT0ULa8yI+XlEtlHQeOg+naBTd6suPtStOZrM3b+2GvB5/7Ky5NfHRbs8mz5BhpYcGP6Ydz4DVP511Tw7Vv1buamoqJ3jhiNJt6q8qR7v/mhl9ZrLq7VjkhbAItbiLbmqiuBIpergJlJAy3Y02QNYsuCfCxsNcY= From: Michael Milton To: dana , "zsh-workers@zsh.org" Subject: Re: Implement an "array index" subscript flag Thread-Topic: Implement an "array index" subscript flag Thread-Index: AQHT/sf3IjRl2ZJMuUibbx4ORws0bKRV0hsAgAABFq4= Date: Fri, 8 Jun 2018 05:46:27 +0000 Message-ID: References: ,<075A01C0-8DA7-4D1B-8553-1C1C2B66D0F2@dana.is> In-Reply-To: <075A01C0-8DA7-4D1B-8553-1C1C2B66D0F2@dana.is> Accept-Language: en-AU, en-US Content-Language: en-AU X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [128.250.103.218] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1;SYXPR01MB1293;7:Ai96+S52z1OyHgwK1oQWqMAb3B+DtQAn1CWQulIR0oHCIK+4Q4Tfifx0D5vyzc+d0FSzirwY3IPqZ4XQoEMvHR1FaL9W6p+UzKwkSahfqJwwoNqgaFwbRHqAk6i/AA+26OqhVZe7Nv6xCkYs8+tA8/6CuhBpf+tQ0BxFBnpe3+20NGKxuIoMNf5lI1lSXphFdeCaP+XM1eP+yafRxWtbzx0KxTV8SFeDjW7aTb5TYXkyLZ0ZtzB59WL2QBUHEiEr;20:vJEzY7v0ylT6l65+ZvTlwt/JSV/F0i8NPdWsk/aY26du3NmpOlNOx4tAriMysNY/QZN/YswqAeqCzgKjM5AGEz+Ml4cGrzuXYhhnilRVVoFK+dbuCWPqvmAFPBdfQLdIDxk0rhs2cFvtTZgaEm23XHpMCWje7j5iT+YCfzLNEEA= x-ms-exchange-antispam-srfa-diagnostics: SOS; x-microsoft-antispam: UriScan:(30117434726449)(38994716169672);BCL:0;PCL:0;RULEID:(7020095)(4652020)(8989080)(4534165)(4627221)(201703031133081)(201702281549075)(8990040)(5600026)(2017052603328)(7153060)(7193020);SRVR:SYXPR01MB1293; x-ms-traffictypediagnostic: SYXPR01MB1293: x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(30117434726449)(72303694245297)(38994716169672); x-ms-exchange-senderadcheck: 1 x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(8211001083)(6040522)(2401047)(8121501046)(5005006)(10201501046)(93006095)(93001095)(3002001)(3231254)(944501410)(52105095)(149027)(150027)(6041310)(201703131423095)(201702281529075)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123560045)(20161123562045)(20161123558120)(20161123564045)(6072148)(201708071742011)(7699016);SRVR:SYXPR01MB1293;BCL:0;PCL:0;RULEID:;SRVR:SYXPR01MB1293; x-forefront-prvs: 06973FFAD3 x-forefront-antispam-report: SFV:NSPM;SFS:(10009020)(396003)(39860400002)(346002)(376002)(366004)(39380400002)(189003)(199004)(2906002)(26005)(88552002)(110136005)(6436002)(76176011)(25786009)(102836004)(55016002)(486006)(106356001)(6606003)(6506007)(478600001)(229853002)(575784001)(7696005)(5250100002)(2900100001)(99286004)(316002)(786003)(476003)(86362001)(53546011)(81156014)(81166006)(186003)(66066001)(14454004)(236005)(6306002)(9686003)(54896002)(74316002)(53936002)(2501003)(5660300001)(105586002)(11346002)(8676002)(446003)(44832011)(966005)(3846002)(6116002)(7736002)(97736004)(3660700001)(6246003)(74482002)(3280700002)(8936002)(33656002)(68736007)(606006)(19627405001);DIR:OUT;SFP:1101;SCL:1;SRVR:SYXPR01MB1293;H:SYXPR01MB1069.ausprd01.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;MX:1;A:1; x-microsoft-antispam-message-info: i3jyRzXcoGReT9P4SMJQ3vbe8XpdyQUReReXGxeZ5buMrlncDQKN69rfYbaotil7QVjSxtHAKm3acmJzic3kepeY7YQKvZ4aXyrTtTf7AOxA27zzqmhzbOlCRmZ2K1i0VV4x5dAU8liX1EcqHyQktpq1jv7YVvSN+/PzujdjVzLSiM3mxCge3iV741xvt27N spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-MS-Office365-Filtering-Correlation-Id: ebd41da4-83bb-429c-2b0a-08d5cd032e11 X-OriginatorOrg: unimelb.edu.au X-MS-Exchange-CrossTenant-Network-Message-Id: ebd41da4-83bb-429c-2b0a-08d5cd032e11 X-MS-Exchange-CrossTenant-originalarrivaltime: 08 Jun 2018 05:46:27.9112 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 0e5bf3cf-1ff4-46b7-9176-52c538c22a4d X-MS-Exchange-Transport-CrossTenantHeadersStamped: SYXPR01MB1293 X-MC-Unique: RARdJCR0O32bVBE-O_VE4g-1 Content-Type: multipart/alternative; boundary="_000_SYXPR01MB1069C119157F5362DB60180CBA7B0SYXPR01MB1069ausp_" --_000_SYXPR01MB1069C119157F5362DB60180CBA7B0SYXPR01MB1069ausp_ Content-Type: text/plain; charset=WINDOWS-1252 Content-Transfer-Encoding: quoted-printable I like this solution. If we change (k) to work with arrays, then it sounds = like it would allow the bash ${!array[@]} syntax to work identically, which= is another benefit. Although incidentally, I don't have any success using (k) even with associa= tive arrays. Perhaps I'm misunderstanding? This produces no output: arr=3D([1]=3Da [2]=3Db) keys=3D${arr[(k)@]} echo $keys My only other concern is that it sounds like (k) actually does pattern matc= hing to look up the index of each value. Does this have performance implica= tions? Would it not be simpler to just return the underlying array position= s (depending on how arrays are implemented)? ________________________________ From: dana Sent: Friday, 8 June 2018 3:16 PM To: zsh-workers@zsh.org Cc: Michael Milton Subject: Re: Implement an "array index" subscript flag On 7 Jun 2018, at 20:37, Michael Milton wro= te: >A useful feature for zsh would be the ability to convert an array into an = array >of keys/indexes for that array.... Bash has a syntax for this, with the >${!array[@]} expansion zsh actually has the (k) flag for this, but it only works on associations. = zsh also supports the ! syntax (which bash 3 borrowed from ksh93) when in ksh- emulation mode, but since it's effectively an alias for (k) it *also* works= only on associations. To be clear, in both bash 4 and ksh93 it works as expected= on both. I feel like the intuitive thing would be for (k) and (v) to work on arrays equivalently to the way they work on associations. In other words... % arr=3D( foo bar baz ) % print ${(k)arr} 1 2 3 % print ${(kv)arr} 1 foo 2 bar 3 baz Looking at the manual, it seems to me that the current effect of those two = flags on arrays is actually undefined (except when used in conjunction with a subscript), so... would that not be a reasonable change to make, if someone= were inclined? Looks like Oliver was considering exactly that, once upon a time: http://www.zsh.org/mla/workers/2004/msg00226.html In the mean time, though, like the Stack Exchange link says =97 since zsh d= oesn't support sparse arrays, i think {1..$#arr} is almost exactly equivalent to (= the hypothetical) ${(k)arr}. dana --_000_SYXPR01MB1069C119157F5362DB60180CBA7B0SYXPR01MB1069ausp_--