Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:60753 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 84420 invoked from network); 6 Jun 2012 08:55:35 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 6 Jun 2012 08:55:35 -0000 Authentication-Results: pb1.pair.com header.from=glopes@nebm.ist.utl.pt; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=glopes@nebm.ist.utl.pt; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain nebm.ist.utl.pt from 193.136.128.21 cause and error) X-PHP-List-Original-Sender: glopes@nebm.ist.utl.pt X-Host-Fingerprint: 193.136.128.21 smtp1.ist.utl.pt Linux 2.6 Received: from [193.136.128.21] ([193.136.128.21:58493] helo=smtp1.ist.utl.pt) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 5F/B1-08677-40B1FCF4 for ; Wed, 06 Jun 2012 04:55:33 -0400 Received: from localhost (localhost.localdomain [127.0.0.1]) by smtp1.ist.utl.pt (Postfix) with ESMTP id 0AE1A7000427; Wed, 6 Jun 2012 09:55:29 +0100 (WEST) X-Virus-Scanned: by amavisd-new-2.6.4 (20090625) (Debian) at ist.utl.pt Received: from smtp1.ist.utl.pt ([127.0.0.1]) by localhost (smtp1.ist.utl.pt [127.0.0.1]) (amavisd-new, port 10025) with LMTP id 14Q2cWGQftvL; Wed, 6 Jun 2012 09:55:28 +0100 (WEST) Received: from nebm.ist.utl.pt (unknown [IPv6:2001:690:2100:4::58:1]) by smtp1.ist.utl.pt (Postfix) with ESMTP id 4E0C6700042B; Wed, 6 Jun 2012 09:55:28 +0100 (WEST) Received: from localhost ([127.0.0.1] helo=nebm.ist.utl.pt) by nebm.ist.utl.pt with esmtp (Exim 4.72) (envelope-from ) id 1ScC1Y-00025R-26; Wed, 06 Jun 2012 09:55:28 +0100 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Date: Wed, 06 Jun 2012 10:55:28 +0200 To: Nikita Popov , internals PHP Organization: =?UTF-8?Q?N=C3=BAcleo_de_Engenharia_Biom=C3=A9dica_do_Insti?= =?UTF-8?Q?tuto_Superior_T=C3=A9cnico?= In-Reply-To: References: Message-ID: <5361275d0179dd0f3061ceabf7bde9af@nebm.ist.utl.pt> X-Sender: glopes@nebm.ist.utl.pt User-Agent: RoundCube Webmail/0.5.3 Subject: Re: [PHP-DEV] Generators in PHP From: glopes@nebm.ist.utl.pt (Gustavo Lopes) On Tue, 5 Jun 2012 19:35:14 +0200, Nikita Popov wrote: > > Before going any further I'd like to get some comments about what you > think of adding generator support to PHP. > I approve. A few comments on the current RFC: * The RFC is too vague. * You're violating the contract of Iterator left and right. current() and key() should return false when !valid(). next() is underspecified. valid() refers to a section that doesn't exist. And if you cannot implement rewind(), doing nothing is not an option. In fact, if you can't implement Iterator in full, you should implement Traversable instead. RewindableGenerator could perhaps implement Iterator though -- but I find the nature of RewindableGenerator very strange. Whether an iterator is rewindable or not seems to be related to the nature of the generator (e.g., is it reading packets from the network). It's not something you can wrap a non-rewindable generator and expect it to work. So it's a sort of unsafe operation, like a cast in C. * Overall, the RFC is very underspecified. We never have a formal description of what a generator is and exact semantics of it. There is no reference to exceptions. What to do if the generator returns function. If the generator can be a function method. * There are missing sections I suppose this is a work in progress and that you just want to gauge the general interest, and I hope you take these considerations into account. -- Gustavo Lopes