Skip to content

propose a functional let grammar #4062

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

Closed
winterland1989 opened this issue Aug 18, 2015 · 6 comments
Closed

propose a functional let grammar #4062

winterland1989 opened this issue Aug 18, 2015 · 6 comments

Comments

@winterland1989
Copy link

Here is my little proposal to bring let into coffee:

  • let ... in statements
zipWith = (xs, ys, fn) ->
  result = []
  let xl = xs.length, yl = y.length in
    if xl >= yl
       ...
    else 
       ...
  result

will be compiled to

var zipWith = function(xs, ys, fn){
  var result = []
  {
    let xl = xs.length, yl = y.length;
    if(xl >= yl){
       ...
    }else{
       ...
    }
  }
  return result;
}
  • let ... in expressions

always turn them into a IIFE, just like a do notion.

  • special for let
for let i in [1..100]
  ...

will be compiled to

for(let i = 1; i<=100; i++){
  ...
}
@michaelficarra
Copy link
Collaborator

A few notes:

  • CoffeeScript will not be targeting ES2015 any time soon, so we will emit IIFEs for the foreseeable future

  • We used to automatically capture loop variables that were closed over. Now, users are expected to manually capture them using this syntax, which isn't far off from what you propose:

    for a in b then do a =>
      ...

A related tip: when making proposals like this, try to keep them limited to the basic functionality that you require. Adding on these semi-related concepts only confuses the message and distracts conversation, ultimately hurting your proposal's chances. The only thing I'd recommend including with your proposal next time is usage examples.

@vendethiel
Copy link
Collaborator

There's an issue about for(let: #2518

@michaelficarra
Copy link
Collaborator

Good, then we can safely ignore that part of this proposal. On the remaining let a = b in ... part, I prefer it to do (a = b) => ... syntactically, but I don't know if that is enough to warrant adding what is essentially sugar for something we already have.

@winterland1989
Copy link
Author

Sorry for not bringing such simple idea clearly, my original purpose is trying to bring es2015 feature let into language, after reading your suggestion, it looked like it's better to directly add let..in and for let and translate to let version, just like how we bring into yeild, use it or not is depended on user's own choice.

You can continue use for a in b then do a => to emit an IIFE if you want, this proposal is just a clean way to write let in coffee IMO.

BTW, i don't miss any other features in es2015 anyway, but let is a nice feature IMO, so let's do this : )

@winterland1989
Copy link
Author

Proposal updated, does it look ok to you?

@GeoffreyBooth
Copy link
Collaborator

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

No branches or pull requests

5 participants