Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:84904 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 24786 invoked from network); 15 Mar 2015 20:35:51 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 15 Mar 2015 20:35:51 -0000 Authentication-Results: pb1.pair.com header.from=rdlowrey@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=rdlowrey@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.213.178 as permitted sender) X-PHP-List-Original-Sender: rdlowrey@gmail.com X-Host-Fingerprint: 209.85.213.178 mail-ig0-f178.google.com Received: from [209.85.213.178] ([209.85.213.178:37817] helo=mail-ig0-f178.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id C6/C5-31306-52DE5055 for ; Sun, 15 Mar 2015 15:35:50 -0500 Received: by igcqo1 with SMTP id qo1so25090933igc.0 for ; Sun, 15 Mar 2015 13:35:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:date:message-id:subject :from:to:cc:content-type; bh=K+4IEggvKdANWl/QqfwJVXvrXi4pLeNRShtnQ7mX1C8=; b=00KsQIp0mv+fXtvTEdg83Gedrz0L2HsPQFU+IcQgBWQX1k6p3EXgSKRFjrgE+cdCSc hRoeyErmm7rHYjFRwwjYpy11Ur4KXAEFoD9328I69d+1+X4PwP1i48dGOXjA89vJuIpx TAoEENaxbKlbsFsPfidLGyzUiQbifixhUgQVfbO+HLXbr/0VkgF/pwgfSbD5s+ZW4OSR QQLsZJqjtbUTxu2W7fZb1bV9rXAg2dhMmaW53XM3+ALkGuXQ0eJbV61EDwAUhwD6OOW2 Vs7wT+VrC7MLYBv9EicOjSihP17Xyn+K6LdTeoNnh4bLXIch8iWJiuM17ynwV3Zqiz33 +qSg== MIME-Version: 1.0 X-Received: by 10.43.69.68 with SMTP id yb4mr60820428icb.96.1426451746277; Sun, 15 Mar 2015 13:35:46 -0700 (PDT) Sender: rdlowrey@gmail.com Received: by 10.50.156.198 with HTTP; Sun, 15 Mar 2015 13:35:46 -0700 (PDT) In-Reply-To: References: Date: Sun, 15 Mar 2015 16:35:46 -0400 X-Google-Sender-Auth: DymYUBS5NW4U_DftWiWj5iq407Y Message-ID: To: Damien Tournoud Cc: Daniel Lowrey , "internals@lists.php.net" Content-Type: multipart/alternative; boundary=bcaec51b1be9a04e9d051159ad1c Subject: Re: [PHP-DEV] [VOTE] Generator Delegation From: rdlowrey@php.net (Daniel Lowrey) --bcaec51b1be9a04e9d051159ad1c Content-Type: text/plain; charset=UTF-8 On Sun, Mar 15, 2015 at 4:13 PM, Damien Tournoud wrote: > > Hi Daniel, > > Would you mind clarifying the relationship between the "Generator Delegation" RFC and the "Generator Return Expressions" RFC? > Sure, thanks for the question. As mentioned in the RFC: "In short: generator delegation allows programmers to reason about the behaviour of the concurrent code simply by thinking of foo() as an ordinary function which can be suspended using a yield statement." Without return expressions in subgenerators you cannot do $baz = yield from foo($bar); because the return value $baz has to come from somewhere. The ability to write the above code is the singular goal of both RFCs; it allows factoring suspendable functionality into multiple generator functions. Now you could hack this kind of support together yourself in userland but there's no reason to do so as return expressions have applicable semantics, known characteristics and low cognitive overhead as described here: https://wiki.php.net/rfc/generator-return-expressions#use-casecoroutine_return_values > In evented system based on coroutine/generators (for example > Python greenlet/gevent) the ability to "return a value" is handled > higher up than the generator/coroutine itself, which has other > advantages (like the ability to yield until the value is available, > instead of simply throwing, etc...). This is actually a *vastly* inferior solution to language-level support for generator returns. greenlet/gevent does it this way because these libraries were created before Python supported generator delegation (and continue supporting Python 2.5). When you have generator returns you don't need any of that additional cruft. Instead, a language supporting generator returns can simply yield promises (or whatever concurrency primitive you prefer). Period. Handling results "higher up than the generator/coroutine" is the hack. Generator returns are the fix for that hack. --bcaec51b1be9a04e9d051159ad1c--