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

Postfix Block Expression #3

Closed
liamoc opened this issue Dec 26, 2009 · 6 comments
Closed

Postfix Block Expression #3

liamoc opened this issue Dec 26, 2009 · 6 comments

Comments

@liamoc
Copy link

liamoc commented Dec 26, 2009

So, I'd really like something along the lines of ruby, that let you pass an additional argument to a function as a block specified after the function call, i.e:

myFunc(1,2) x =>
   alert(x).

This would be semantically equivalent to either:

myFunc(1,2,x=>alert(x).)

or:
myFunc(1,2)(x=>alert(x).)

@jashkenas
Copy link
Owner

It should compile to the first case if we add it.

You prefer this style because the parenthesis doesn't need to wrap, right? It wouldn't be too hard to add to the grammar, but I think it could look a little funky on a single line, or for methods that don't take prior arguments. You're proposing:

list.each() x => x * x.

Versus the current compiler's:

list.each(x => x * x.)

Do you have any real examples where it helps make things clearer?

@liamoc
Copy link
Author

liamoc commented Dec 27, 2009

Partly i like it because it eliminates the need for specifying the end of a block twice. Typing ".)" is really awkward in my opinion, when I want to be able to define my own control structures.

Also, it drastically simplifies providing multi-line functions as parameters when you throw significant indentation into the mix.

@jashkenas
Copy link
Owner

It would be cool if CoffeeScript's lexer were smart enough to insert a period into the token stream for you, when you had an unclosed block within an outer parentheses. This may be do-able by counting parentheses. So:

list.each(x => x * x)

@liamoc
Copy link
Author

liamoc commented Dec 28, 2009

That would be nice, but significant indentation would also remove that problem.

@liamoc
Copy link
Author

liamoc commented Dec 28, 2009

My problem then is that I'm still specifying the end of the block twice - both with a paren and a dedent, or a paren and a period.. I'd rather get rid of the parens, but I guess it's just a pet peeve of mine.

@jashkenas
Copy link
Owner

Sorry, the block syntax is just too limited -- mentioned in the other issue. No multiple function arguments, and it has to be the last one. It wouldn't always be possible to call to with JS libraries with if they expected either. Closing as a "wontfix".

yyfearth pushed a commit to yyfearth/coffee-script that referenced this issue May 16, 2012
int3 pushed a commit to int3/coffee-script that referenced this issue Feb 14, 2013
bfab added a commit to bfab/coffeescript that referenced this issue Aug 8, 2014
This version is directly executable, and illustrates more directly the concept. One can comment out line jashkenas#3 and run again to see the difference.
alangpierce added a commit to alangpierce/coffeescript that referenced this issue Aug 11, 2016
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

2 participants