rfc:generator-delegation
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionNext revisionBoth sides next revision | ||
rfc:generator-delegation [2015/03/09 16:07] – rewording rdlowrey | rfc:generator-delegation [2015/03/30 04:34] – Close vote rdlowrey | ||
---|---|---|---|
Line 4: | Line 4: | ||
* Author: Daniel Lowrey < | * Author: Daniel Lowrey < | ||
* Contributors: | * Contributors: | ||
- | * Status: | + | * Status: |
* First Published at: http:// | * First Published at: http:// | ||
====== Abstract ====== | ====== Abstract ====== | ||
- | This RFC proposes new '' | + | This RFC proposes new '' |
====== Proposal ====== | ====== Proposal ====== | ||
Line 75: | Line 75: | ||
$send = false; | $send = false; | ||
} else { | } else { | ||
- | | + | throw $e; |
} | } | ||
} | } | ||
Line 146: | Line 146: | ||
The other reason return values are required stems from the previously discussed refactoring principle. | The other reason return values are required stems from the previously discussed refactoring principle. | ||
Specifically: | Specifically: | ||
- | like ordinary functions | + | like ordinary functions. |
Using the proposed syntax an ordinary function '' | Using the proposed syntax an ordinary function '' | ||
Line 164: | Line 164: | ||
simply by thinking of '' | simply by thinking of '' | ||
- | **NB:** The actual implementation of single-threaded concurrency | + | **NB:** The actual implementation of coroutine task schedulers is outside the scope of |
this document. This RFC focuses only on the language-level machinery needed to make such tools more | this document. This RFC focuses only on the language-level machinery needed to make such tools more | ||
feasible in userland. It should be obvious that simply moving code into a generator function will | feasible in userland. It should be obvious that simply moving code into a generator function will | ||
- | not instantly | + | not somehow |
Line 333: | Line 333: | ||
while($shared-> | while($shared-> | ||
$delegator = delegator($shared); | $delegator = delegator($shared); | ||
- | while($delegator-> | + | |
- | var_dump($delegator-> | + | foreach |
+ | var_dump($value); | ||
+ | } | ||
+ | var_dump($delegator-> | ||
+ | |||
+ | /* | ||
+ | int(42) | ||
+ | // This is our only output because no values are yielded | ||
+ | // from the already-completed shared subgenerator | ||
+ | */ | ||
</ | </ | ||
Line 374: | Line 383: | ||
==== Error States ==== | ==== Error States ==== | ||
- | There are two scenarios in which '' | + | There are two scenarios in which '' |
* Using '' | * Using '' | ||
Line 382: | Line 391: | ||
===== Rejected Ideas ===== | ===== Rejected Ideas ===== | ||
- | The original version of this RFC proposed a '' | + | The original version of this RFC proposed a '' |
- | '' | + | '' |
- | form was considered | + | form was considered less readable |
Line 406: | Line 415: | ||
**Python** | **Python** | ||
- | Python 3.3 generators support '' | + | Python 3.3 generators support |
<code python> | <code python> | ||
- | >>> | + | >>> |
- | ... yield from range(x, | + | ... tally = 0 |
- | ... | + | ... while 1: |
+ | ... next = yield | ||
+ | ... if next is None: | ||
+ | ... | ||
+ | ... tally += next | ||
... | ... | ||
- | >>> | + | >>> |
- | [5, 4, 3, 2, 1, 0, 1, 2, 3, 4] | + | ... while 1: |
+ | ... tally = yield from accumulate() | ||
+ | ... | ||
+ | ... | ||
+ | >>> | ||
+ | >>> | ||
+ | >>> | ||
+ | >>> | ||
+ | ... | ||
+ | ... | ||
+ | >>> | ||
+ | >>> | ||
+ | ... | ||
+ | ... | ||
+ | >>> | ||
+ | >>> | ||
+ | [6, 10] | ||
</ | </ | ||
**JavaScript** | **JavaScript** | ||
- | Javascript ES6 generators support the '' | + | Javascript ES6 generators support the '' |
<code javascript> | <code javascript> | ||
- | function* | + | function* |
- | yield 2; | + | yield* [1, 2, 3]; |
- | yield 3; | + | |
- | | + | |
} | } | ||
- | function* | + | var result; |
- | | + | |
- | | + | function* |
- | yield 5; | + | |
} | } | ||
- | var iterator = g2(); | + | var iterator = g5(); |
console.log(iterator.next()); | console.log(iterator.next()); | ||
console.log(iterator.next()); | console.log(iterator.next()); | ||
console.log(iterator.next()); | console.log(iterator.next()); | ||
- | console.log(iterator.next()); | + | console.log(iterator.next()); |
- | console.log(iterator.next()); // { value: | + | // g4() returned |
- | console.log(iterator.next()); // { value: undefined, done: true } | + | |
+ | console.log(result); // " | ||
</ | </ | ||
Line 457: | Line 486: | ||
- | ===== Proposed Voting Choices | + | ===== Vote ===== |
- | + | ||
- | Two voting choices are proposed†: | + | |
- | * **YES**, | + | A 2/3 " |
- | * **NO**, do not modify existing Generator behavior | + | <doodle title=" |
+ | * Yes | ||
+ | * No | ||
+ | </ | ||
- | A 2/3 " | + | . |
- | †: The success of this vote depends on the success of the accompanying [[rfc: | + | The success of this vote depends on the success of the accompanying [[rfc: |
- | Should Generator Return Expressions be rejected the voting outcome of this RFC will be rendered moot. | + | |
===== Patches and Tests ===== | ===== Patches and Tests ===== | ||
- | The current patch is approaching | + | The current patch is considered |
https:// | https:// |
rfc/generator-delegation.txt · Last modified: 2017/09/22 13:28 by 127.0.0.1