Hacker News new | ask | show | jobs
by ajuc 5211 days ago
If f g h x boils down to f(g(h(x))) and [1 2 3] boils down to [1, 2, 3]

Then what is the meaning of [f 1] ?

EDIT: I've tried on http://coffeescript.org/ and it seems a = [1 2 3] doesn't work? EDIT2: newlines instead of spaces works, my bad

2 comments

Right, array elements separated by new lines works, but CS requires commas between elements in 1-line arrays. I would like to see CS remove commas between array elements but most folks like commas there, it seems. And yes, I guess there's a syntax ambiguity with function arguments that is not easily resolved. I love omitting parens for calling a single function, but doing it more than once per line should be avoided I think.
Semi-related anecdote: Ruby enforces commas in arrays but the problem still exists for [f 1, 2]. Is it [(f 1), 2] or [f(1, 2)]?

Apparently as a consequence of this ambiguity, even [f 1] has become illegal in Ruby 1.9. One of those god-awful undocumented changes that broke my apps. :(