Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:85268 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 44661 invoked from network); 20 Mar 2015 09:26:24 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 20 Mar 2015 09:26:24 -0000 Authentication-Results: pb1.pair.com header.from=rowan.collins@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=rowan.collins@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.212.181 as permitted sender) X-PHP-List-Original-Sender: rowan.collins@gmail.com X-Host-Fingerprint: 209.85.212.181 mail-wi0-f181.google.com Received: from [209.85.212.181] ([209.85.212.181:37163] helo=mail-wi0-f181.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 65/AA-25408-FB7EB055 for ; Fri, 20 Mar 2015 04:26:23 -0500 Received: by wixw10 with SMTP id w10so14509247wix.0 for ; Fri, 20 Mar 2015 02:26:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=user-agent:in-reply-to:references:mime-version :content-transfer-encoding:content-type:subject:from:date:to:cc :message-id; bh=PE43vnj3ikp8wQfB9RLq9EGM2RIUgylh56KZqzb+h2g=; b=FxrP3dfv5eI5/yCtlM525R7pJpwqqrnVSkNRz2/SaGFfii7apa71zYDS/r3BocihM0 Lu+k+L0XEb703WGuGZ+Nt95KYQGUy/ddVmOQmxnqbyj37T2TcfkNtz0BKAJN1lz0ptvs JJoLR+4SfYk9k2lhBwQ0+imt3mjiiZG1EKjiZmz+nqQ2Xbk+uaAAtBwBo/Kbkpke8qYt iHd3QOQX9LqyWXAEKGQlSZ8hUti7OF1oJRZT2Jx9o6FaU/Xq2z9iSbDSJ9O9G8PFXXad QHPJGbzgPHSQarS/bIyDuNqccZz+VE1QAMuPpFdzhbIdFCrgbB803wEMhWOp3RVwtCov VUdA== X-Received: by 10.194.156.133 with SMTP id we5mr162964914wjb.37.1426843580798; Fri, 20 Mar 2015 02:26:20 -0700 (PDT) Received: from [192.168.0.2] (cpc68956-brig15-2-0-cust215.3-3.cable.virginm.net. [82.6.24.216]) by mx.google.com with ESMTPSA id d9sm2152424wib.20.2015.03.20.02.26.19 (version=TLSv1.2 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 20 Mar 2015 02:26:20 -0700 (PDT) User-Agent: K-9 Mail for Android In-Reply-To: References: <550B5A81.1090706@gmail.com> <550B7189.4040608@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Date: Fri, 20 Mar 2015 09:10:10 +0000 To: Alex Bowers CC: internals@lists.php.net Message-ID: <7486C296-7535-4633-AFE2-02E7BBC67BC5@gmail.com> Subject: Re: [PHP-DEV] RFC - Array slice syntactic sugar From: rowan.collins@gmail.com (Rowan Collins) On 20 March 2015 01:28:53 GMT, Alex Bowers wrote: >I'm not sure what you mean by "something that happens nowhere else" PHP >has >> syntax for all sorts of things, using all sorts of symbols. Your own >> suggestion uses the : symbol in a place where it currently can't >exist. > > >What I mean by 'symbol' here, is a prefix to tell it what the context >of >its use is; in this case, it is the declaration that we are requiring >the >index not the key. As far as I'm aware, and can think of at the moment, >PHP >has nothing like a hinter symbol. > >The only purpose of this symbol is to tell the user that it is indexes >not >keys. The @ symbol in my examples is not a special marker that is meaningful on its own; the parser wouldn't even see it as a separate token. The syntax for key access is $array[$key], the syntax for positional access would be $array[@$position]; chosen to look similar, but one is not a special case of the other. The syntax needn't be just an extra character, we could invent something else, like $array[[$position]], or $array@($position), though I can't think of anything I like. Similarly, your suggested slice syntax is chosen to look similar to key access, and to the same feature in other languages, but since it doesn't exist yet, we can make up whatever parser rules we want. >Maybe there should be a symbol to declare that, but i'm not sure. Will >appreciate more comments on this. > >If we go the direction of using a symbol, what should be the outcome of >the >symbol missing? fatal error, or to try to slice based on the keys? The symbol isn't something that can be missing, it's just part of the syntax, so this is like saying "what should we do if the closing ] is missing?" The answer is, nothing, it's undefined syntax, so it's a parse error. You could implement slicing on keys, and if you did so, [x:y] would be the obvious syntax to use, but as you've said of negative positions, let's keep to one feature at a time. Regards, -- Rowan Collins [IMSoP]