Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:62284 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 18025 invoked from network); 20 Aug 2012 13:12:34 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 20 Aug 2012 13:12:34 -0000 Authentication-Results: pb1.pair.com header.from=nikita.ppv@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=nikita.ppv@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.217.170 as permitted sender) X-PHP-List-Original-Sender: nikita.ppv@gmail.com X-Host-Fingerprint: 209.85.217.170 mail-lb0-f170.google.com Received: from [209.85.217.170] ([209.85.217.170:64835] helo=mail-lb0-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 7C/59-07742-0C732305 for ; Mon, 20 Aug 2012 09:12:33 -0400 Received: by lbbgp3 with SMTP id gp3so3380709lbb.29 for ; Mon, 20 Aug 2012 06:12:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; bh=nEvhh62EzAudG9uVNXyC2v35WNDmReax93XyshNQgyk=; b=IvcbdQ3uH+mZfgG/wE+Q4YR8s51/HqAZPOYFwnit/v9E3x1pHZU+kldy5Nk75IXDnL zaWPSW6tHHxBRfffqCxbDh/h9Z3EheBZI8bQaaJLoRnozCIRGiMUkqe4ntfYwwc0QCr9 G/r6ruLoRDyDtySbsDOrpYpDiBa2wcA2zZijeC6fVG/pfzGwfhsrSUeBMuvG/Ng7ykoa VNiJkPdG8Sm2WM3dq91AHmi1uSnUybKU4eKpJdnHxOr4gbnB65tyVyzEQ+nbo2Tx3FnS mGvZwbc6p9Ft+YqS9UcgT14Kwm4yhQlJ8li1bsrlCkeQTxne2+fC7avAN8SqW2YoALPh Ru0Q== MIME-Version: 1.0 Received: by 10.152.124.180 with SMTP id mj20mr14021907lab.43.1345468349442; Mon, 20 Aug 2012 06:12:29 -0700 (PDT) Received: by 10.152.122.51 with HTTP; Mon, 20 Aug 2012 06:12:29 -0700 (PDT) In-Reply-To: <503225D8.4040900@gmail.com> References: <503171CB.3090609@sugarcrm.com> <50317E51.4090305@lerdorf.com> <503225D8.4040900@gmail.com> Date: Mon, 20 Aug 2012 15:12:29 +0200 Message-ID: To: =?ISO-8859-1?Q?=C1ngel_Gonz=E1lez?= Cc: Rasmus Lerdorf , Stas Malyshev , Derick Rethans , PHP internals Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] [RFC] Generators From: nikita.ppv@gmail.com (Nikita Popov) On Mon, Aug 20, 2012 at 1:56 PM, =C1ngel Gonz=E1lez wro= te: > On 20/08/12 02:01, Rasmus Lerdorf wrote: >> I would still like to understand what this generator keyword would >> actually do. I don't see how it would work. Would a function marked >> generator somehow not be allowed to return normally or to finish and not >> return anything? How could this be enforced? I am completely against any >> keyword that is essentially documentation-only. >> >> -Rasmus > Given that such function could "return several times", seems a different > enough function type to have its keyword. The method signature defines the API, so the caller knows what to use. Can we agree on that? In this case it makes absolutely no difference to the caller whether the function is implemented using a generator, or whether it returns a custom Iterator object. The "generator" keyword wouldn't document the API, it would document an implementation-detail. What would *actually* make sense here are return value typehints. E.g. one could have something like `public Iterator getIterator() { ... }`. This would provide the caller with information on what the function returns, but would leave out the implementation detail that the Iterator was implemented using a generator. Or, if the generator implementation is actually important (because it is used as a coroutine) one could also explicitly typehint against it: `public Generator getCoroutine() { ... }`. But return-value type hints are not directly related to generators. They are a more general concept. If that's what all of you want, then I'd recommend opening up a new thread for it. > You could not decorate it and rely instead on the presence of the yield > keyword, but parsers will thank knowing about it from the start rather > than realising at mid-parsing that the function is a completely > different beast. No, parsers don't care about this. It's trivial to detect in both cases. Nikita