Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:62091 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 64834 invoked from network); 9 Aug 2012 02:25:53 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 9 Aug 2012 02:25:53 -0000 Authentication-Results: pb1.pair.com header.from=larry@garfieldtech.com; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=larry@garfieldtech.com; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain garfieldtech.com from 66.111.4.29 cause and error) X-PHP-List-Original-Sender: larry@garfieldtech.com X-Host-Fingerprint: 66.111.4.29 out5-smtp.messagingengine.com Received: from [66.111.4.29] ([66.111.4.29:53468] helo=out5-smtp.messagingengine.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id F9/44-41247-0BF13205 for ; Wed, 08 Aug 2012 22:25:52 -0400 Received: from compute5.internal (compute5.nyi.mail.srv.osa [10.202.2.45]) by gateway1.nyi.mail.srv.osa (Postfix) with ESMTP id 2645320A91 for ; Wed, 8 Aug 2012 22:25:50 -0400 (EDT) Received: from frontend2.nyi.mail.srv.osa ([10.202.2.161]) by compute5.internal (MEProxy); Wed, 08 Aug 2012 22:25:50 -0400 DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d= messagingengine.com; h=message-id:date:from:mime-version:to :subject:references:in-reply-to:content-type :content-transfer-encoding; s=smtpout; bh=AFWIBIBWRnxvSGBYHLxsND mNr1U=; b=IiGbhuWOqMvAhwmagS/xabxt1ScF9AaR6PxJJeVaRH69/DNY0czXOB VMdRBwUctElPOwwiDBi5e1akTO4covHWwsz8zAcFeJJplvJN23MMhjnKAK9X730U O75XuiFvmXRLbN94I3plN2gcFEbqxl5ejDCsMi86FrAogBU75YRS0= X-Sasl-enc: 5gqbZG6UqKGOuXIMXVVrUzmUuAtcchvQhskrcdNH6epJ 1344479149 Received: from [192.168.42.21] (unknown [98.220.238.115]) by mail.messagingengine.com (Postfix) with ESMTPA id D5C12482620 for ; Wed, 8 Aug 2012 22:25:49 -0400 (EDT) Message-ID: <50231FAD.40104@garfieldtech.com> Date: Wed, 08 Aug 2012 21:25:49 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:14.0) Gecko/20120714 Thunderbird/14.0 MIME-Version: 1.0 To: internals@lists.php.net References: <500EE3B9.8010902@ajf.me> <500EEA76.1030407@ajf.me> <5010138D.5050804@ajf.me> <501015B9.6050704@ajf.me> <501058B9.5050004@lsces.co.uk> <501249B6.5070507@lsces.co.uk> <50128825.4020902@lsces.co.uk> In-Reply-To: <50128825.4020902@lsces.co.uk> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] Re: Generators in PHP From: larry@garfieldtech.com (Larry Garfield) On 07/27/2012 07:23 AM, Lester Caine wrote: > Nikita Popov wrote: >>> I'll ask again since no one has answered ... >>> > >>> >In a different way ... >>> >Is the only thing that changes the 'function' into a 'generator' >>> replacing >>> >the call to process the data with 'yield'? ( That would be >>> 'SUSPEND' in an >>> >SQL procedure ) ... >>> > >>> >So how DOES an IDE work out the flow in order to correctly check that >>> >variables are defined? >>> > >>> >As always, my IDE provides a lot of 'sexy' stuff so that I don't >>> need to >>> >have it built in to the language, and I still can't see how a lot >>> of what is >>> >being loaded in helps with performance which is the only thing that >>> I am >>> >interested in. Performance wise why is yield better than just directly >>> >calling a function to handle the data? >> Lester Caine and Alex Aulbach, >> >> may I ask you to continue this discussion in a separate thread? I am >> really interested in constructive responses about the generator RFC, >> but your discussion is generating a lot of noise, which makes it very >> hard for me to pick out the few mails that are of interest to me. >> >> If you could open a new thread (like "Generator keyword") it would >> help a lot. > > Nikita - I am looking for a well reasoned argument as to why generator > has to be added at all! 'Just because it can be' is not a valid > argument, but perhaps you could add to the RFC the performance > implication or advantage of what is being proposed. That would at > least be some comparison with the current methods of doing the same > thing? > Anthony had a very good writeup on generators and how they compare to iterators last week: http://blog.ircmaxell.com/2012/07/what-generators-can-do-for-you.html I think that does a good job of laying out the case for generators as "low-effort iterators". I still think the syntax feels clunky to me, but that's probably because I'm not used to it from other languages. One question, though: It looks based on the voting like finally {} blocks are going in. So... what should happen in the following situation: function stuff() { try { foreach (range(1, 100) as $i) { yield $i; } } finally { print "All done"; } } Does "All done" get printed once, or 101 times? Similarly: function things() { $i = 1; try { while (true) { yield $i++; } } finally { print "All done"; } } That will run indefinitely. So will "All done" ever print, or does that finally become unreachable? (I have no clue what the behavior "should" be in these cases, just that it should be sorted out sooner rather than later.) --Larry Garfield