{"action":"created","issue":{"url":"https://api.github.com/repos/jashkenas/coffeescript/issues/4151","labels_url":"https://api.github.com/repos/jashkenas/coffeescript/issues/4151/labels{/name}","comments_url":"https://api.github.com/repos/jashkenas/coffeescript/issues/4151/comments","events_url":"https://api.github.com/repos/jashkenas/coffeescript/issues/4151/events","html_url":"https://github.com/jashkenas/coffeescript/issues/4151","id":119036426,"number":4151,"title":"Inconsistent array comprehension?","user":{"login":"loveencounterflow","id":1170565,"avatar_url":"https://avatars.githubusercontent.com/u/1170565?v=3","gravatar_id":"","url":"https://api.github.com/users/loveencounterflow","html_url":"https://github.com/loveencounterflow","followers_url":"https://api.github.com/users/loveencounterflow/followers","following_url":"https://api.github.com/users/loveencounterflow/following{/other_user}","gists_url":"https://api.github.com/users/loveencounterflow/gists{/gist_id}","starred_url":"https://api.github.com/users/loveencounterflow/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/loveencounterflow/subscriptions","organizations_url":"https://api.github.com/users/loveencounterflow/orgs","repos_url":"https://api.github.com/users/loveencounterflow/repos","events_url":"https://api.github.com/users/loveencounterflow/events{/privacy}","received_events_url":"https://api.github.com/users/loveencounterflow/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/jashkenas/coffeescript/labels/invalid","name":"invalid","color":"ededed"}],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2015-11-26T12:33:28Z","updated_at":"2015-11-26T15:19:35Z","closed_at":"2015-11-26T14:53:19Z","body":"Consider these two snippets:\r\n\r\n```coffee\r\n( x for x in y )\r\n```\r\n\r\n```coffee\r\ndo => ( x for x in y )\r\n```\r\n\r\nShouldn't one expect them to compile and evaluate to the exact same result?\r\n\r\nYet the first is equivalent to `x for x in y`, i.e. the parentheses are treated as redundant (as if I had written `a + ( b * c )`), which means the result is the last element of `y`. The second one evaluates to a copy of `y`.\r\n\r\nMy use case is that I'm compiling MarkDown documents that allow insertion of CS and JS code whose results will be interpolated into the document. The other day I tried (CS code fenced by `<<(:>>`...`<<)>>` here):\r\n\r\n```\r\nYadda yadda <<(:>>( name for name of mkts )<<)>> yadda.\r\n```\r\n\r\nwhich to my surprise didn't quite work. Sure you *can* write \r\n\r\n```\r\nYadda yadda <<(:>>do => ( name for name of mkts )<<)>> yadda.\r\n```\r\n\r\nbut that slightly changes the semantics of the snippet and is hard\r\nto explain.\r\n\r\n\r\n* Is this the expected behavior?\r\n* In case this is expected, what is the reasoning?\r\n* Are there more expression forms that show like behavior?\r\n* Is there a generic way to reformat all such code snippets (which may contain several lines of code / several statements), i.e. by wrapping them into functions or some such so I always get the list comprehension interpretation from `( x for x in y )`, short of parsing the source myself?\r\n\r\nFor reference (slightly shortened):\r\n\r\n```bash\r\ncoffee -cpeb \"( x for x in y )\"\r\nvar i, len, x;\r\nfor (i = 0, len = y.length; i < len; i++) {\r\n  x = y[i];\r\n  x;\r\n}\r\n```\r\n\r\n```bash\r\n$ coffee -cpeb \"do => ( x for x in y )\"\r\n(function(_this) {\r\n  return (function() {\r\n    var i, len, results, x;\r\n    results = [];\r\n    for (i = 0, len = y.length; i < len; i++) {\r\n      x = y[i];\r\n      results.push(x);\r\n    }\r\n    return results;\r\n  });\r\n})(this)();\r\n```"},"comment":{"url":"https://api.github.com/repos/jashkenas/coffeescript/issues/comments/159936636","html_url":"https://github.com/jashkenas/coffeescript/issues/4151#issuecomment-159936636","issue_url":"https://api.github.com/repos/jashkenas/coffeescript/issues/4151","id":159936636,"user":{"login":"lydell","id":2142817,"avatar_url":"https://avatars.githubusercontent.com/u/2142817?v=3","gravatar_id":"","url":"https://api.github.com/users/lydell","html_url":"https://github.com/lydell","followers_url":"https://api.github.com/users/lydell/followers","following_url":"https://api.github.com/users/lydell/following{/other_user}","gists_url":"https://api.github.com/users/lydell/gists{/gist_id}","starred_url":"https://api.github.com/users/lydell/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lydell/subscriptions","organizations_url":"https://api.github.com/users/lydell/orgs","repos_url":"https://api.github.com/users/lydell/repos","events_url":"https://api.github.com/users/lydell/events{/privacy}","received_events_url":"https://api.github.com/users/lydell/received_events","type":"User","site_admin":false},"created_at":"2015-11-26T15:19:35Z","updated_at":"2015-11-26T15:19:35Z","body":"It is _very_ common to have a `for` loop that is _not_ used as an expression. While there are many things CoffeeScript _could_ optimize, that one is one that really makes sense."}}