Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Questionable semantics: list comprehension in yield expression #764

Open
summivox opened this issue Aug 8, 2015 · 1 comment
Open

Questionable semantics: list comprehension in yield expression #764

summivox opened this issue Aug 8, 2015 · 1 comment
Labels

Comments

@summivox
Copy link
Contributor

summivox commented Aug 8, 2015

Closest issue I can find is #667


->* yield [x for x in arr]

compiles to:

(function*(){
  var x;
  return (yield (yield* (function*(){
    var i$, ref$, len$, results$ = [];
    for (i$ = 0, len$ = (ref$ = arr).length; i$ < len$; ++i$) {
      x = ref$[i$];
      results$.push(x);
    }
    return results$;
  }())));
});

->* yield alert [x for x in arr]

compiles to:

(function*(){
  var x;
  return (yield alert((yield* (function*(){
    var i$, ref$, len$, results$ = [];
    for (i$ = 0, len$ = (ref$ = arr).length; i$ < len$; ++i$) {
      x = ref$[i$];
      results$.push(x);
    }
    return results$;
  }()))));
});

While in all cases the behavior is as expected, the compilation is surprising and undocumented. Clearly the yield* is extraneous in both cases. I suspect there must have been use cases where the yield* makes sense, but could we at least document this, and clarify when this rule is applicable?

@gkovacs
Copy link
Contributor

gkovacs commented Mar 30, 2017

This bug appears with switch statements as well:

(name) ->*
  x = switch name
  | 'a' => 0
  | 'b' => 1
  return x

compiles to

// Generated by LiveScript 1.5.0
(function(){
  (function*(name){
    var x;
    x = (yield* (function*(){
      switch (name) {
      case 'a':
        return 0;
      case 'b':
        return 1;
      }
    }()));
    return x;
  });
}).call(this);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants