Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:61715 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 72315 invoked from network); 24 Jul 2012 18:09:07 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 24 Jul 2012 18:09:07 -0000 Authentication-Results: pb1.pair.com smtp.mail=ajf@ajf.me; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=ajf@ajf.me; sender-id=pass Received-SPF: pass (pb1.pair.com: domain ajf.me designates 64.22.89.133 as permitted sender) X-PHP-List-Original-Sender: ajf@ajf.me X-Host-Fingerprint: 64.22.89.133 oxmail.registrar-servers.com Linux 2.6 Received: from [64.22.89.133] ([64.22.89.133:57802] helo=oxmail.registrar-servers.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 26/41-01267-2C4EE005 for ; Tue, 24 Jul 2012 14:09:07 -0400 Received: from [192.168.0.200] (5ad32874.bb.sky.com [90.211.40.116]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by oxmail.registrar-servers.com (Postfix) with ESMTPSA id 0DF28C30072 for ; Tue, 24 Jul 2012 14:09:02 -0400 (EDT) Message-ID: <500EE4AA.2050303@ajf.me> Date: Tue, 24 Jul 2012 19:08:42 +0100 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: <500EDCC7.1020402@ajf.me> <224BD95C-B652-42CA-B397-846E7544680B@gmail.com> In-Reply-To: <224BD95C-B652-42CA-B397-846E7544680B@gmail.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Subject: Re: [PHP-DEV] Re: Generators in PHP From: ajf@ajf.me (Andrew Faulds) On 24/07/12 19:06, Yahav Gindi Bar wrote: > You could introduce new keyword for generator... even call it "generator" but why (its kind of "design" issue...)? if the syntax that one should use in order to implement the generator is just like a function, but using yield keyword in order to return the items to store? > > As long as I know, most programming languages that uses generators wrap it up in a function, so why shall we introduce new keyword that can confuse programmers? > > I think using function and returning the value using yield is great... although I'm open to any new nicely-written generator syntax. > > On 24 ביול 2012, at 20:56, Alex Aulbach wrote: > >> 2012/7/24 Andrew Faulds : >>> Much easier to make an iterator with a function than as a class. >> 2012/7/24 Yahav Gindi Bar : >>> I agree, implementing a class only for iterator may be pain sometimes, and functions is much better - especially when 5.3 got the anonymous functions, so we can even use the generators for iterator functions in class methods which can be great. >> Ok, why not call it "iterator" or "generator" or "huffpuff" instead of >> "function"? It's just the naming, which disturbs me, because a >> function is something which is, when called once finished once. I >> don't like mathematics, but that is one of the definition of a >> function: >> >> http://en.wikipedia.org/wiki/Function_%28mathematics%29 >> "each input is related to exactly one output" >> >> Couldn't be so complicated to introduce a new name for that, or? >> >> -- >> Alex Aulbach > And anyway it just depends on your perspective. It's still a function IMO, it doesn't return, it yields. To me it's kinda like having a function in another thread that passes several messages back over its lifetime, and then finally returns. -- Andrew Faulds http://ajf.me/