Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:85298 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 45029 invoked from network); 20 Mar 2015 15:10:23 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 20 Mar 2015 15:10:23 -0000 Authentication-Results: pb1.pair.com smtp.mail=leight@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=leight@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.160.178 as permitted sender) X-PHP-List-Original-Sender: leight@gmail.com X-Host-Fingerprint: 209.85.160.178 mail-yk0-f178.google.com Received: from [209.85.160.178] ([209.85.160.178:35390] helo=mail-yk0-f178.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 9F/4A-21731-D583C055 for ; Fri, 20 Mar 2015 10:10:22 -0500 Received: by ykfs63 with SMTP id s63so43889994ykf.2 for ; Fri, 20 Mar 2015 08:10:17 -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=ht6f8Vcg3SA6oYIhiV1wE4TdblnS/vGV4nXNS+x+h1I=; b=Ew5PJNMFz8INb2Ys1N6aQ0Va1fCOwZWZRTSdSCEBmF775t0PV53eJW6Y5GnNhVC46J 6GucAS32z7gM2dd0UPMrzQT6b2TJcXm8lQUGTTvJb1bQvDLeKKpPMYsbAAGJAPmiEeQ5 vgf4/LGS04FXoPNy2h6PGhvRaKAxUm9L8d48J+g2V11m2jeS8aTQ3cHDdDqVEP1PZLpG UGu7nuFMgDXZNjZrIPk3NoJfW7p15FLzU1QjDp8pObhhX4LivNApsqmWRt0o9QDVReIN 5ylX9SgTtqlz4YpkTFT1pvROmlntGsRSwc3DobaJi50SP5hsxzzw3spXHSR1C7tnvM/4 /GoQ== MIME-Version: 1.0 X-Received: by 10.52.61.137 with SMTP id p9mr55752897vdr.68.1426864217873; Fri, 20 Mar 2015 08:10:17 -0700 (PDT) Received: by 10.52.177.7 with HTTP; Fri, 20 Mar 2015 08:10:17 -0700 (PDT) Received: by 10.52.177.7 with HTTP; Fri, 20 Mar 2015 08:10:17 -0700 (PDT) In-Reply-To: References: <550B5A81.1090706@gmail.com> <550B7189.4040608@gmail.com> <7486C296-7535-4633-AFE2-02E7BBC67BC5@gmail.com> <550C1176.9050307@gmail.com> <550C1AE4.8090607@gmail.com> <550C1EC3.8000106@gmail.com> <550C317E.8020508@gmail.com> Date: Fri, 20 Mar 2015 15:10:17 +0000 Message-ID: To: Alex Bowers Cc: internals@lists.php.net, Rowan Collins Content-Type: multipart/alternative; boundary=001a1136b574d964240511b9b661 Subject: Re: [PHP-DEV] RFC - Array slice syntactic sugar From: leight@gmail.com (Leigh) --001a1136b574d964240511b9b661 Content-Type: text/plain; charset=UTF-8 On Mar 20, 2015 2:59 PM, "Alex Bowers" wrote: > > > > > So $dictionary['elephant':'snake'] returns all elements with keys which > > sort lexically between 'elephant' and 'snake', regardless of whether the > > array is sorted. > > > Makes sense to me. > > Alternatively, a key-based slice could look up the position in the array of > > the two keys, and then perform a positional slice between those positions, > > i.e. $array[$a:$b] == $array[ @ key_position($array, $a) : > > key_position($array, $b) ]. I'm not sure that's particularly intuitive or > > useful, but again, it has no problem with string keys. > > > I'd say no to that, since it is not an obvious use case, since if you are > defining associated arrays, going for the indexes of those fields feels > strange; since one of the major benefits to associated keys is that the > order doesn't matter anymore. Having this one feature order dependant > whilst using the associated keys isn't correct in my view. > > On 20 March 2015 at 14:41, Rowan Collins wrote: > > > Alex Bowers wrote on 20/03/2015 13:40: > > > >> Still not sure how we can implement a range of strings. But since thats > >> for a different feature, I'll leave that issue for now. > >> > > > > I can't resist a quick answer: if you can define a key-based slice at all, > > you can define it for both integer and string keys. Bear in mind the a:b > > here isn't a range, it's just a pair of values specifying which items to > > include in the slice. > > > > If the definition of a key-based slice is "all elements whose key > > satisfies $key >= $a && $key <= $b", then you're just doing comparisons > > between strings, which are defined as lexical order. So > > $dictionary['elephant':'snake'] returns all elements with keys which sort > > lexically between 'elephant' and 'snake', regardless of whether the array > > is sorted. > > > > Alternatively, a key-based slice could look up the position in the array > > of the two keys, and then perform a positional slice between those > > positions, i.e. $array[$a:$b] == $array[ @ key_position($array, $a) : > > key_position($array, $b) ]. I'm not sure that's particularly intuitive or > > useful, but again, it has no problem with string keys. > > > > Regards, > > -- > > Rowan Collins > > [IMSoP] > > IMHO, stick to offsets in the first instance, this is a slice notation, first order of business is to make it behave like array_slice (+on strings). Assoc key based slicing feels pretty wrong to me at this point. --001a1136b574d964240511b9b661--