Rick Waldron (2013-10-26T19:08:31.000Z)
On Sat, Oct 26, 2013 at 1:01 PM, Lucio Tato <luciotato at gmail.com> wrote:

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

  function g() { yield = 1; return yield; }

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.



> can you just expose "Generator" as a core function?
> can "yield" be a function-call-like-construct instead of a new language
> construction?
>

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:

  // your code defines this...
  function yield() { return Number.MAX_VALUE; }

  // you then include my library, which exposes this fibonacci():

 function fibonacci() {
>     let [prev, curr] = [0, 1];
>     for (;;) {
>         [prev, curr] = [curr, prev + curr];
>         yield(curr);
>     }}
>
>
What does yield() do? It returns Number.MAX_VALUE every time.


Rick
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20131026/fbf6ec7b/attachment.html>
domenic at domenicdenicola.com (2013-11-02T19:02:40.969Z)
On Sat, Oct 26, 2013 at 1:01 PM, Lucio Tato <luciotato at gmail.com> wrote:

> It's really needed to make js syntax more complex in order to implement
> generators?
> It's function* really needed?
>

Yes, because `yield` is only reserved in strict mode code, which means this
is valid today:

```js
function g() { yield = 1; return yield; }
```

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.



> can you just expose "Generator" as a core function?
> can "yield" be a function-call-like-construct instead of a new language
> construction?
>

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:

```js
// your code defines this...
function yield() { return Number.MAX_VALUE; }

// you then include my library, which exposes this fibonacci():
```

> ```js
> function fibonacci() {
>     let [prev, curr] = [0, 1];
>     for (;;) {
>         [prev, curr] = [curr, prev + curr];
>         yield(curr);
>     }}
> ```

What does yield() do? It returns Number.MAX_VALUE every time.