Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:104834 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 58605 invoked from network); 20 Mar 2019 23:47:53 -0000 Received: from unknown (HELO mail-pf1-f179.google.com) (209.85.210.179) by pb1.pair.com with SMTP; 20 Mar 2019 23:47:53 -0000 Received: by mail-pf1-f179.google.com with SMTP id 10so2762269pfo.5 for ; Wed, 20 Mar 2019 13:39:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:references:from:openpgp:autocrypt:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=xgrx8G9n77cQtoIVqEhchV35cgQSWqtZvnm84zbSX9A=; b=BHGLfL7rVPXhekUrBHpqUy2Se8ZhaLt+fpwj1VvwYR+fG6z/Bi9QmnZ/gA7Ll/2+DW 5bnPOrlsahV1B5Tpsuz64+VDxMuqR8zCJ78b877Wph35nj7ZqnlCYzRck/Sv7qQvzStw TwFdYgnraNczgr7UtqUXAslZggGLHfSRR1zXDZ17+LMy6/rdJYEX8esXbuIoB3VMM+7M rpz+qT/hhDwqrAadAborCPsB47syzox+cwevMQGr6RjgFIrieIQBejMoxiYbexlKJ4S+ vAzdjmKq9DNdCzbL88dDtAOsb9nIFg6OQXzeQtTOMCA73EqWiJHN8W5LtxiY9nTXrvAb RhHg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:openpgp:autocrypt :message-id:date:user-agent:mime-version:in-reply-to :content-language:content-transfer-encoding; bh=xgrx8G9n77cQtoIVqEhchV35cgQSWqtZvnm84zbSX9A=; b=Du93mYztoHKQKZ5wyNhgZs8y1JX5eDPqq6vFy0QeBTr11CNIBTyDNcbTXgrKryBxuY Xt/EVOSA0dwEXLg+q3z1dbBL2dJrncV1+hkhzIk1p7yVPEBI89g4ki2Mf2VDwciB4p+G M5x99SCKKEokVP03Rsxf+wD8Zhv5AYcai0cWu+51ag3FlGrGDN1RcpvwPT75RRNHFOt7 zNjFJfoSpcDhZq+uYgAS7/boeAHsIguCDlVEu1+DS9SiLFttMd8xa+9FIepKDLZYQ6wC euffvfuoGZpCjvq9Mw3vrxGt+Fz73mrRdlUtQkVbFH817bt3LsjK2GVsyQC9HeNA+TT7 6MPQ== X-Gm-Message-State: APjAAAWB6cXy2R8erykpK01QOVJdnLRmcTmeSF81WOm7oTZS/w8Xv1wW HW9AsCgRsZhgRBZ8FruxCbC8HVI= X-Google-Smtp-Source: APXvYqylmkeQFmJfKcztQ3Mhotiww3EJSLi9UnlgmWmxOLZ+sV2BgAw0wWpYI4zyhzovpuTsNgtyrg== X-Received: by 2002:a63:4144:: with SMTP id o65mr2457377pga.241.1553114390268; Wed, 20 Mar 2019 13:39:50 -0700 (PDT) Received: from Stas-Pro-2016.local ([2601:646:8d01:8ee0:2dae:53ab:8516:7a5a]) by smtp.gmail.com with ESMTPSA id n9sm1624086pff.43.2019.03.20.13.39.48 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 20 Mar 2019 13:39:49 -0700 (PDT) To: Rowan Collins , PHP internals References: <85417a73-a391-c9ad-49aa-5b88c65b0900@gmail.com> <5c8ea43d.1c69fb81.e50f1.7d18SMTPIN_ADDED_MISSING@mx.google.com> <0d34b3b1-866e-4bab-9a8f-3c70f1fc9721@www.fastmail.com> Openpgp: preference=signencrypt Autocrypt: addr=smalyshev@gmail.com; prefer-encrypt=mutual; keydata= mQMuBE9mqaARCACFSqcGmNunkjQQu3X+yXnTmFeEkvM4JXZTOBdR8aEevNGmmFEfyvjaDjWi 9hcwp4E/lYtC+P7VsVjM1OSX9eq0jC/lGL0ZyRXek+mNy0n5H1NSuTpf9Y18LMqhc4G+RU+L cNiZ9K0DJuOOvNLPxW7OHZguxb3wdKPXNVa2jyRfJAKm2uaJJMT1mTmFT9a0Q8SKr+mUrrJk uG0H2o6Szr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h+iD5648YMwfTFCij+uQINBE9mqaAQCADfZPMpjZkkGZj3BY/7ApoLq4mwqzbh +CpLXwNn20tFNvSXfb8RdeXvVEb7Scx+W9qYpiaun2iXJgCVH8fgpZpR856ulT1q6uCG++CX ubEvip/eJkZl93/84h04KQJwsgOrAh0Om3OePRn8Pr+++0LNS0EL8uX/YHeTOGOnnmTqYTey SBVFdov6L4mepddfjekicKQqhL7mZh/xuq29JijT0uNNX8v4vDWQDu5dlAcdd+uB3gcXMD/P ginD11zp+6wtrWCm/+yBqpvDwXQX5PGUnwvbRfl7Ay3MmwmoXiecZMg0dwTSc7e0lhB4HGRH ZdBMJB4rHUVGdzqujK/ctOvrAAMFB/0Utb76Qe6sCMlHxVAmeE/fbo7Pi05btZ/x01r67dHf aMSP0riCKJ7M0OW+jAXtu9+z/BVnYisW67WWfxl2cS5tZDgiHgJARXWUOO72+sScHP8KQmTl 1z16gyKbwY3SmyBkwcpOL35nhUWNLy93syPoY6sZUTikr2bZYukHDQ33XBPs4e6MbWKfsa9q aVmnlOF3k5UqChjutfHaEa4Q7VP4wBIpphHBi9MI16oJIzzBPbGl2uoedjwiZ6QeQZnSuOVY ZxU2d3lRA8PrtfFN1VSlpEm/VcAvtieHUYWHN0wOu+cp3Slr5XJVNjTjJhl28SlinMME54mK AGf2Ldr/dRwXiGEEGBEIAAkFAk9mqaACGwwACgkQL3lWvF2gS126EQD/VVd3FgjLKglClRQP zdfU847tqDK4zJjbmRv5vLLwoE0A+wbrQs7jVGU3NrS0AIl5vUmewpp2BKzSkepy23nWmejw Message-ID: <752c83ab-0e6f-d8f5-ff15-e1f75b5d04b5@gmail.com> Date: Wed, 20 Mar 2019 13:39:48 -0700 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:60.0) Gecko/20100101 Thunderbird/60.5.3 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] RFC Draft: Comprehensions From: smalyshev@gmail.com (Stanislav Malyshev) Hi! > It's not that you can't make an array into a generator, but you can't make > an eagerly-evaluated expression into a lazily-evaluated one. Not sure what you mean here. If you already have the data, of course you can't un-evaluate it in order to lazily-evaluate it again. But why would you, that would be just a waste of time! If you don't yet have the data, then you usually can easily rewrite the code that produces it as a generator if you wanted, but in most cases you don't need it as it would be more complex and won't give you any advantage (exceptions of course exist like processing enormous files or processing infinite streams continuously). So I am not seeing the point of mentioning "eager to lazy" case as it is usually does not happen in practice. > $hugeCSVFileIterator = new CSVFileLazyLoader($filename); > $filteredCSVFileIterator = [ foreach $hugeCSVFileIterator as $line if > $line['type'] == 'foo' yield $line['value'] ]; In this particular case, when you're working with an iterator over a large file, you probably want a generator. Which is very easy to write using a functional syntax, and the only thing comprehension syntax does is switching the parts around a bit and saving you writing a "function" keyword. I don't think it's a very common case though. > Similarly, an array-only syntax is useless for infinite iterators, whereas > an iterator version lets you write a filtered version that's still infinite. Of course, when you need to filter iterators, then you need a different approach. I do not doubt that. I doubt that filtering iterators is the most common case in PHP to make the comprehension syntax only support it - I think the case of array transformation is much more common. > But if we only have one, it should be the iterator version, with a > short-hand for iterator_to_array as a separate language improvement. I think this would significantly reduce the usability of such construct - to the point that it's easier to use the existing syntax, thus making new syntax sugar useless. The whole point of syntax sugar is making common case easy, and doing what you are suggesting is to make a corner case (existing, but IMHO much less common) easy and make the user work to achieve the common case. -- Stas Malyshev smalyshev@gmail.com