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

How to deal with multiline code in loops #10

Closed
weepy opened this issue Dec 27, 2009 · 3 comments
Closed

How to deal with multiline code in loops #10

weepy opened this issue Dec 27, 2009 · 3 comments

Comments

@weepy
Copy link

weepy commented Dec 27, 2009

How should I covert something like the following?

for(var i in list) {
  .. multiple 
  .. lines of code
}

The only way I could figure with the array comprehensions was to pull out the multilines into a function, like so:

fn: i =>
    .. multiple 
    .. lines of code
  .

fn(i) for i in list.
@liamoc
Copy link

liamoc commented Dec 28, 2009

Indeed I think this is an oversight as well. I was thinking adding a pre-fix comprehension system like this:

for i in list
   multiple()
   things().

@jashkenas
Copy link
Owner

Yes, great suggestion -- mirrors the multiline vs single-line whiles and ifs. I'll give it a shot.

@jashkenas
Copy link
Owner

Alright, multiline block form is now on master for array and object comprehensions. Here's the (contrived) example from the tests.

evens: for num in [1, 2, 3, 4, 5, 6] when num % 2 is 0
           num *= -1
           num -= 2
           num * -1

print(evens.join(', ') is '4, 6, 8')

Closing the ticket...

alangpierce added a commit to alangpierce/coffeescript that referenced this issue Oct 31, 2016
…ons (jashkenas#10)

Closes decaffeinate/decaffeinate#458
Closes decaffeinate/decaffeinate#461
Closes decaffeinate/decaffeinate#504

Just like OUTDENT and CALL_END tokens, close-curly-brace tokens can be generated
without having a real location, and if that position overlaps with a later
token, it can cause the AST to have bad location data. Just like the other two
token types, we now give `}` tokens the position of the previous real token,
which makes all AST nodes have reasonable locations.
This issue was closed.
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

3 participants