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

Easier way to cancel implicit return ? #91

Closed
mcfog opened this issue Sep 3, 2011 · 16 comments
Closed

Easier way to cancel implicit return ? #91

mcfog opened this issue Sep 3, 2011 · 16 comments

Comments

@mcfog
Copy link

mcfog commented Sep 3, 2011

I'm tired of writing void or return at end of functions
callbacks passed to jQuery.each or dom event or what often check if the return value is false, so I have to fill my code with void or return in case of the last expression happened to be false

maybe we can have sth. like

$.each ->>
    ...

instead of

$.each ->
    ...
    void
@satyr
Copy link
Owner

satyr commented Sep 3, 2011

jashkenas/coffeescript#899

Been pondering myself as well.

I'm willing to do this, yet to come up with syntaxes that feel right. It's even more challenging than Coffee because of backcall.

Sticking void is probably clearest, but barely elegant. Does it worth?

$.each void ->
<- void $.each

@ghost
Copy link

ghost commented Sep 3, 2011

Maybe something similar to this?

$.each *>
<* $.each

! may be clearer than *; I'm only using *for parity with the linked CoffeeScript proposal. Since the function keyword comprises two symbols, however, I'd suggest a syntax that replaces the - with a different symbol.

@satyr
Copy link
Owner

satyr commented Sep 3, 2011

Remember bound forms: ~>``<~

@ghost
Copy link

ghost commented Sep 3, 2011

Wouldn't !> or *> be consistent with those?

@satyr
Copy link
Owner

satyr commented Sep 3, 2011

How? Are you suggesting

  • -> : !>
  • ~> : *>

?

@ghost
Copy link

ghost commented Sep 3, 2011

Not quite...I was thinking of {*, !}> and {*, !}~>. Too verbose?

@satyr
Copy link
Owner

satyr commented Sep 3, 2011

  • -> : *>
  • ~> : *~>

Look inconsistent to me. Both should obey the same rule (add or change), e.g.:

  • -> : *->
  • ~> : *~>

or

  • -> : *>
  • ~> : &>

@satyr
Copy link
Owner

satyr commented Sep 3, 2011

Forgot to mention; we have one more syntax to consider: function

@ghost
Copy link

ghost commented Sep 3, 2011

*function parameters...
(parameters) *> ...

&function parameters...
(parameters) &> ...

@satyr
Copy link
Owner

satyr commented Sep 3, 2011

*function &function

Hardly elegant nor memorable, don't you think?

@ghost
Copy link

ghost commented Sep 3, 2011

I agree; it's not. *function is at least consistent with ~function, but &function isn't appealing at all. void function would be more explicit, but perhaps too reminiscent of Java (public void method(String[] parameters) ...), whereas void -> is awkward.

@dsc
Copy link

dsc commented Sep 8, 2011

Aesthetically, I'm partial to:

  • -> : !>
  • ~> : ~!>
  • function : !function
  • ~function : ~!function

...But that's simply because ! is a tall character, and >/function are both tall to begin with. Despite being an artist, I realize this is not the best reason for making the bang right-associative.

Further, using ! almost logically makes sense. You're negating the function result! But clearly the result here is the creation of the function. So whatever. It seems equally valid to argue that something else (imo, &) is better for the same reason, as you're denoting a different operation on the right-hand-side expression.

In any case, using both * and & is a wretched idea that has no merits. (One keystroke in exchange for all the mental energy of yet another syntax-form with concomitant error-potential? -1 -1 -1 -1 -1)

@blaise-io
Copy link

I really miss the option to cancel implicit returns, so any solution being implemented would be greatly appreciated.
The ! solution feels most natural to me. Other characters make less sense.

@satyr
Copy link
Owner

satyr commented Dec 8, 2011

For {now,test,desparate people}: https://gist.github.com/1446167

$ coco -r ./noret -bce 'x <-+ f; g +-> y'
f(function(x){
  g(function(){
    y;
  });
});

$ coco -bce 'x <- f; g -> y'
f(function(x){
  return g(function(){
    return y;
  });
});

@satyr
Copy link
Owner

satyr commented Dec 9, 2011

Gonna implement this using the same aproach as that gist unless anyone objects.

I choose ! (instead of +) because it:

  • requires least amount of code. (no changes to lexer/grammar)
  • has no compatibility issues. (ToNumbernegating a function is useless)
  • gets three votes at least. (@dsc, @BlaiseKal, and me)

@ghost
Copy link

ghost commented Dec 9, 2011

👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants