<div dir="ltr">Rick: I understand. But it is always a trade-off.<div><br></div><div>If the reason to introduce a new construct is <span style="font-size:13px;font-family:arial,sans-serif">because there may already be code that defines a function called `yield`, it seems to me as a bad trade-off. (advantages vs disadvantages)</span></div>
<div><span style="font-family:arial,sans-serif;font-size:13px"><br></span></div><div><span style="font-family:arial,sans-serif;font-size:13px">In your example... </span></div><div><span style="font-family:arial,sans-serif;font-size:13px">function yield() {... <- will raise a parsing error.</span></div>
<div><br></div><div>Anyway, there are other ways to solve that.</div><div>You can put the asterisk in "yield" instead of the important "function". It's a lot less confusing.</div><div><br></div><div>
<pre style="white-space:pre-wrap;color:rgb(51,51,51);font-size:13px;font-family:Consolas,'Liberation Mono',Courier,monospace;margin-top:0px;margin-bottom:0px;background-color:rgb(248,248,248);border:1px solid rgb(221,221,221);line-height:19px;overflow:auto;padding:6px 10px;border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px">
<span style="font-weight:bold">function</span> fibonacci() {
    <span style="font-weight:bold">let</span> [prev, curr] <span style="font-weight:bold">=</span> [<span style="color:rgb(0,153,153)">0</span>, <span style="color:rgb(0,153,153)">1</span>];
    <span style="font-weight:bold">for</span> (;;) {
        [prev, curr] <span style="font-weight:bold">=</span> [curr, prev <span style="font-weight:bold">+</span> curr];
        yield*(curr);
    }
}</pre></div><div><br></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Sat, Oct 26, 2013 at 4:08 PM, Rick Waldron <span dir="ltr"><<a href="mailto:waldron.rick@gmail.com" target="_blank">waldron.rick@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><br><div class="gmail_extra"><br><br><div class="gmail_quote">On Sat, Oct 26, 2013 at 1:01 PM, Lucio Tato <span dir="ltr"><<a href="mailto:luciotato@gmail.com" target="_blank">luciotato@gmail.com</a>></span> wrote:<br>


<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><p style="margin-right:0px;margin-bottom:15px;margin-left:0px;color:rgb(51,51,51);font-family:Helvetica,arial,freesans,clean,sans-serif;font-size:13px;line-height:22px;background-color:rgb(251,251,251);margin-top:0px!important">



It's really needed to make js syntax more complex in order to implement generators? <br>It's function* really needed? <br></p></div></blockquote><div>Yes, because `yield` is only reserved in strict mode code, which means this is valid today: </div>


<div><br></div><div>  function g() { yield = 1; return yield; } </div><div><br></div><div>Since the starred generator function is a new syntactic form, there is no existing code that it can possibly break by making yield a keyword.</div>


<div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><p style="margin-right:0px;margin-bottom:15px;margin-left:0px;color:rgb(51,51,51);font-family:Helvetica,arial,freesans,clean,sans-serif;font-size:13px;line-height:22px;background-color:rgb(251,251,251);margin-top:0px!important">


can you just expose "Generator" as a core function? <br>can "yield" be a function-call-like-construct instead of a new language construction?</p></div></blockquote><div><br></div><div>No, because there may already be code that defines a function called `yield`, which would be broken if suddenly yield was a special language-owned function. Consider this: </div>


<div><br></div><div>  // your code defines this...</div><div>  function yield() { return Number.MAX_VALUE; }</div><div><br></div><div>  // you then include my library, which exposes this fibonacci():</div><div><br></div>

<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<div dir="ltr">
<div style="background-color:rgb(251,251,251);color:rgb(51,51,51);font-family:Helvetica,arial,freesans,clean,sans-serif;font-size:13px;line-height:22px"><pre style="font-family:Consolas,'Liberation Mono',Courier,monospace;margin-top:0px;margin-bottom:0px;background-color:rgb(248,248,248);border:1px solid rgb(221,221,221);line-height:19px;overflow:auto;padding:6px 10px;border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px">
<span style="font-weight:bold">function</span> <span>fibonacci</span><span>()</span> <span>{</span>
    <span style="font-weight:bold">let</span> <span>[</span><span>prev</span><span>,</span> <span>curr</span><span>]</span> <span style="font-weight:bold">=</span> <span>[</span><span style="color:rgb(0,153,153)">0</span><span>,</span> <span style="color:rgb(0,153,153)">1</span><span>];</span>
    <span style="font-weight:bold">for</span> <span>(;;)</span> <span>{</span>
        <span>[</span><span>prev</span><span>,</span> <span>curr</span><span>]</span> <span style="font-weight:bold">=</span> <span>[</span><span>curr</span><span>,</span> <span>prev</span> <span style="font-weight:bold">+</span> <span>curr</span><span>];</span>
        <span>yield</span><span>(</span><span>curr</span><span>);</span>
    <span>}</span>
<span>}</span>
</pre></div><p style="margin:15px 0px;color:rgb(51,51,51);font-family:Helvetica,arial,freesans,clean,sans-serif;font-size:13px;line-height:22px;background-color:rgb(251,251,251)"></p></div></blockquote><div><br></div><div>


What does yield() do? It returns Number.MAX_VALUE every time.</div><span class="HOEnZb"><font color="#888888"><div> </div><div><br></div><div>Rick</div></font></span></div></div></div>
</blockquote></div><br></div></div>