Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:61720 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 79491 invoked from network); 24 Jul 2012 18:37:46 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 24 Jul 2012 18:37:46 -0000 Authentication-Results: pb1.pair.com smtp.mail=glopes@nebm.ist.utl.pt; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=glopes@nebm.ist.utl.pt; sender-id=unknown Received-SPF: error (pb1.pair.com: domain nebm.ist.utl.pt from 193.136.128.22 cause and error) X-PHP-List-Original-Sender: glopes@nebm.ist.utl.pt X-Host-Fingerprint: 193.136.128.22 smtp2.ist.utl.pt Linux 2.6 Received: from [193.136.128.22] ([193.136.128.22:55495] helo=smtp2.ist.utl.pt) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 57/E2-01267-77BEE005 for ; Tue, 24 Jul 2012 14:37:44 -0400 Received: from localhost (localhost.localdomain [127.0.0.1]) by smtp2.ist.utl.pt (Postfix) with ESMTP id 973B570003CE; Tue, 24 Jul 2012 19:37:40 +0100 (WEST) X-Virus-Scanned: by amavisd-new-2.6.4 (20090625) (Debian) at ist.utl.pt Received: from smtp2.ist.utl.pt ([127.0.0.1]) by localhost (smtp2.ist.utl.pt [127.0.0.1]) (amavisd-new, port 10025) with LMTP id cpKBROLmMcc5; Tue, 24 Jul 2012 19:37:40 +0100 (WEST) Received: from mail2.ist.utl.pt (mail.ist.utl.pt [IPv6:2001:690:2100:1::8]) by smtp2.ist.utl.pt (Postfix) with ESMTP id 553EA70003C5; Tue, 24 Jul 2012 19:37:40 +0100 (WEST) Received: from damnation (unknown [IPv6:2001:470:94a2:4:6539:7241:387:14d]) (Authenticated sender: ist155741) by mail2.ist.utl.pt (Postfix) with ESMTPSA id 387D0200BB99; Tue, 24 Jul 2012 19:37:38 +0100 (WEST) Content-Type: text/plain; charset=utf-8; format=flowed; delsp=yes To: "Yahav Gindi Bar" , "Alex Aulbach" Cc: internals@lists.php.net References: <500EDCC7.1020402@ajf.me> Date: Tue, 24 Jul 2012 20:37:33 +0200 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Organization: =?utf-8?Q?N=C3=BAcleo_de_Eng=2E_Biom=C3=A9di?= =?utf-8?Q?ca_do_I=2ES=2ET=2E?= Message-ID: In-Reply-To: User-Agent: Opera Mail/12.50 (Linux) Subject: Re: [PHP-DEV] Re: Generators in PHP From: glopes@nebm.ist.utl.pt ("Gustavo Lopes") Em Tue, 24 Jul 2012 19:56:46 +0200, Alex Aulbach escreveu: > 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" > Other have already explained that PHP functions are not strictly mathematical functions, but generators nevertheless somewhat fit that description. When you have function foo() { ... yield /* ... */; ... } and you call foo(), you get the same thing every time: a Generator object. It so happens that the implementation of that object is inside the body of the function. Maybe this helps you reason about the feature. -- Gustavo Lopes