-
Notifications
You must be signed in to change notification settings - Fork 2k
Description
Coffeescript streamlines syntax: In most cases, closing symbols are not needed, and in most cases lists can be delimited with commas, newlines or both.
Coffeescript has two significant inconsistencies:
Inconsistency 1: array literals require start and end brackets
myArray = [
1
2
3
]
# -> myArray = [1, 2, 3];
Many solutions to the array problem have been discussed: #645, #1190, #1702, #1872, #2259, #2642, #3115
Inconsistency 2: multi-argument function invocations require at least one comma
myFun 1,
2
3
# -> myFun(1, 2, 3);
I did not find any discussion of this problem. Why isn't the following legal?
# ERROR ON LINE 2: UNEXPECTED INDENTATION
myFun
1
2
3
# should generate: myFun(1, 2, 3);
If that WAS legal, then @TrevorBurnham's suggestion in #1872 would be a reasonable solution to the array problem:
Use a function: arr = (args...) -> args
Then we can write bracket-less arrays like this:
myArray = arr
1
2
3
# -> myArray = [1, 2, 3];
The only problem I've found so far are ambiguities like:
if arr
1
2
3
# is it this: if (arr) {1; 2; 3;}
# or this: if (arr(1,2,3)) ...
It seems reasonable to disambiguate those scenarios by choosing the current, backward compatible interpretation. Anytime an indented block is legal, multi-line function invocations require explicit () or a comma after the first param - as it does currently.
Thoughts?
These two problems significantly limit both declarative programming styles and embedded DSLs. I'd really like to find some solution.