Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:104813 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 75045 invoked from network); 20 Mar 2019 03:28:33 -0000 Received: from unknown (HELO out2-smtp.messagingengine.com) (66.111.4.26) by pb1.pair.com with SMTP; 20 Mar 2019 03:28:33 -0000 Received: from compute7.internal (compute7.nyi.internal [10.202.2.47]) by mailout.nyi.internal (Postfix) with ESMTP id 3FFA2221B0 for ; Tue, 19 Mar 2019 20:20:19 -0400 (EDT) Received: from imap26 ([10.202.2.76]) by compute7.internal (MEProxy); Tue, 19 Mar 2019 20:20:19 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm2; bh=7Qd5PD GiT3CzMGtC20/D2QUoelJc17lrlVNl71pyF6E=; b=E9HnYhAkII/C0oKtSS2ZS4 B3Gb5Ps6P9bz/sUDGr2nry6+qEM7PZkVaJjb9rlloWnuYmAft/JCtudVLmjOK8z3 m5CfP7hpiyU3GldV5ZvN8te9g2rtB+vdGANLrFK4e7Gecarcb5AqBlYbonHQswgq os91wL5mNCfJ6gTU+1fNe4Vbb07sXiyx3bYjly5aaE6CvMnjTDLYBDZTngi27iB+ 0RKxkfYW6yO+AFb0DDuOJD+W/LgDE5jA0Upw7ZYT+YipTxYo1fYO/ri3z0w0sfiJ +ew3Vrbd3R9ra66dYqJdlnk6GATXOwZW/1Kts2p9Tbyturc3hUEP+PflcqZ4IfOQ == X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedutddrieehgddvudcutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecunecujfgurhepofgfggfkjghffffhvffutgesthdtre dtreertdenucfhrhhomhepfdfnrghrrhihucfirghrfhhivghlugdfuceolhgrrhhrhies ghgrrhhfihgvlhguthgvtghhrdgtohhmqeenucfrrghrrghmpehmrghilhhfrhhomheplh grrhhrhiesghgrrhhfihgvlhguthgvtghhrdgtohhmnecuvehluhhsthgvrhfuihiivgep td X-ME-Proxy: Received: by mailuser.nyi.internal (Postfix, from userid 501) id 8D75DB432C; Tue, 19 Mar 2019 20:20:18 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.1.5-976-g376b1f3-fmstable-20190314v3 Mime-Version: 1.0 X-Me-Personality: 10727885 Message-ID: <0d34b3b1-866e-4bab-9a8f-3c70f1fc9721@www.fastmail.com> In-Reply-To: References: <85417a73-a391-c9ad-49aa-5b88c65b0900@gmail.com> <5c8ea43d.1c69fb81.e50f1.7d18SMTPIN_ADDED_MISSING@mx.google.com> Date: Tue, 19 Mar 2019 20:20:03 -0400 To: internals@lists.php.net Content-Type: text/plain Subject: Re: [PHP-DEV] RFC Draft: Comprehensions From: larry@garfieldtech.com ("Larry Garfield") On Tue, Mar 19, 2019, at 7:10 PM, Robert Hickman wrote: > > > Why not apply the same approach to PHP? There is iterator_to_array() to > > > convert a generator to an array, so we may not need both syntaxes. > > > However, I think using [] for something that is *not an array* is > > > counter-intuitive. > > > > No, I would definitely be for []-syntax producing an array. As I said, > > that's in my experience what people usually want. > > > > In python comprehensions on [] makes a list and comprehensions in {} > make a dictionary (list and dict comprehensions). As PHP only has one > 'array' type using [] makes sense. Along that train of thought, should > comprehensions also be possible in the old array() syntax? Honestly, I cannot think of any case where I'd use a comprehension where I would definitely want an array and not a generator. In the majority case both work equally well, cool, but I don't know when I would even use an array-dependent version. And converting from a generator to an array is trivial; the other way, very not so much. > Does the proposal include comprehensions which build associative > arrays? In python you can do {a['key'] : a for a in lst}, where lst is > a list of dicts. I often use this to create a dictionary whose keys > index a sub-element of a nested dictionary, as my example shows. The proposal as written, yes, you can produce values or keys-and-values. I would still love feedback on possible alternative syntaxes, per my earlier email. --Larry Garfield