Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:85273 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 59830 invoked from network); 20 Mar 2015 11:38:39 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 20 Mar 2015 11:38:39 -0000 Authentication-Results: pb1.pair.com smtp.mail=bowersbros@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=bowersbros@gmail.com; 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: bowersbros@gmail.com X-Host-Fingerprint: 209.85.212.181 mail-wi0-f181.google.com Received: from [209.85.212.181] ([209.85.212.181:33038] helo=mail-wi0-f181.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id CA/DC-25408-EB60C055 for ; Fri, 20 Mar 2015 06:38:39 -0500 Received: by wixw10 with SMTP id w10so25239157wix.0 for ; Fri, 20 Mar 2015 04:38:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=1kuOikUs+qXARerAgbJ2Rp27WDqy1l1AbKDjtU1efSE=; b=MZpNRId8Ka9kidy1Y+eB8YihrIteHPtpF0IuXNUKlkw5BAkOOLbSE3ICPTBe4QzJEL IABoXFSFtQr7plWEGlHm4GnvrcSuWmy00N1cByyxqqRq8cI4JuukbRjb9BUost/rp0YJ Bkdl29ZngyEOeaun+hxtMs6I/VeGlYGD69y1rb6pZMuc9SzFLgJs6WHebEN+N66f4AiR CYzcQyTcpoDA6lGSsO+ZqddMXl8a4QyQIYYYvly7gDuXdRk08o+/YVBZf49qc88i4vKK C8fupRUEOoh5ugUpWgna2oE18Ut7n8lgv/+U/GaBdpI5ePIb8RHZ0Cu/EXuiF7onhP/p E28w== MIME-Version: 1.0 X-Received: by 10.194.221.100 with SMTP id qd4mr157187882wjc.113.1426851515424; Fri, 20 Mar 2015 04:38:35 -0700 (PDT) Received: by 10.28.62.84 with HTTP; Fri, 20 Mar 2015 04:38:35 -0700 (PDT) In-Reply-To: <7486C296-7535-4633-AFE2-02E7BBC67BC5@gmail.com> References: <550B5A81.1090706@gmail.com> <550B7189.4040608@gmail.com> <7486C296-7535-4633-AFE2-02E7BBC67BC5@gmail.com> Date: Fri, 20 Mar 2015 11:38:35 +0000 Message-ID: To: Rowan Collins Cc: internals@lists.php.net Content-Type: multipart/alternative; boundary=001a11c3aa74b966240511b6c1b5 Subject: Re: [PHP-DEV] RFC - Array slice syntactic sugar From: bowersbros@gmail.com (Alex Bowers) --001a11c3aa74b966240511b6c1b5 Content-Type: text/plain; charset=UTF-8 > > 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. Ah, I understand you now. Yes I agree that this would be useful then. It allows us the future possibility of a separate RFC looking into slicing on keys as mentioned at the bottom of your post. 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. I think for simplicity, we should keep it as $array[], and have a symbol within it that shows that it is an internal index rather than the key. An Asterisk (*) is my preference at the moment, though caret also looks promising. Here are some examples of how various characters could look $array[*1:3], $array[*:], $array[*:1], $array[*1:] $array[@1:3], $array[@:], $array[@:1], $array[@1:] $array[^1:3], $array[^:], $array[^:1], $array[^1:] $array[&1:3], $array[&:], $array[&:1], $array[&1:] 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. So a parse error currently, and a future RFC can define the terms of using this normally? If we go down the route of adding a symbol for by index rather than by key, then this RFC should also include the normal getting array by key style, without the colon range operator. For example: $array[*1] to get the item that is the second in the list, rather than at key 1. --001a11c3aa74b966240511b6c1b5--