-
Notifications
You must be signed in to change notification settings - Fork 2k
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
do ->
as (->)()
#788
Comments
Isn't the meaning of the above example the same as
? I do like the idea, though. This would kill a lot of parentheses, and even cut my line count. +1. |
We no longer have the magical scoping within |
. +1. Since On that note, should |
Implementing it as a unary operator that simply represents
↓
Kinda similar to Haskell's |
Yes, |
This should just rescope existing variables, and automatically ensure |
Looking at that, it's no longer entirely clear what's going on if we just use the |
Probably. Then it becomes identical to the |
I think it's best for new scopes to always be indicated by |
I've implemented this with the test: |
Maybe:
|
Hard to imagine when |
True, but I'm concerned about the ambiguity. In all other cases, a use of Perhaps a different glyph could be used here, instead of |
Normally, the |
Fair enough. So we just prevent use of What about preserving |
I say we don't forward the |
What do you mean by 'fake out'? If we directly pass the |
Do you mean that |
Sorry for being unclear. What I meant by that, was that if we defined |
I believe that |
Done and done. Nothing fancy, and shadows existing variables as expected. For example: |
We can leave this on master for the time being, but I'd like to see an explanation of how/why you'd use it added to the documentation. Right now, looking at:
... doesn't make much immediate sense. Where does the |
Can we rename it to something like |
I think As to Jeremy's example, I do find it a little surprising that
compiles to
I would think it would be more useful for Here's a common use case: It's considered a best practice in jQuery plugins to look for the global named
Once the
|
I've removed the magic from |
I haven't seen this mentioned, but how about using object literal syntax to map formal to active parameters? For example, a jQuery plugin might do:
|
The
couldn't be replaced with
Here's one way to think about the
with the exception that |
|
Aren't the two functionally equivalent, satyr? Either way, |
They behave differently in the presence of
|
That's kind of a different issue--this issue is about removing parens.
or something with the same semantics. |
What if we defined |
I'd worry that it'd be needlessly comlicated:
with only small improvement from:
|
I like sethaurus approach because you can already do it in Coffee without adding new stuff to the core.
-1 |
Right. Core stuff should be simple. |
So is the consensus that you can do it with a helper function instead of the |
s/ consensus / Stan's view / We should support it--"How do you create a function and call it immediately?" is one of the most frequent questions, and I hate to say "You have to use parens." |
Alright, it's the same deal with function binding. We have an example of a custom |
While the using parens is a minor annoyance, most of the proposals discussed here seem even more convoluted, especially those doing odd wrangling of variables. So a -1 from me at the moment. |
I thought we had a near-consensus around adding
And of course I for one would find this to be a very useful feature. Even in the trivial examples given above, the |
Doesn't make sense with current syntax. |
Yes, I was going to resurrect default arguments as a separate issue after this one was resolved... but since you find the syntax jarring (since [Update: It's issue 802.] |
Now possible in combination of my defarg branch. |
OK something that's been bothering me -- if we killed splices/slices using |
|
I would add that there are significant performance gains to be had from using the mess of parentheses that http://jsperf.com/self-executing-closure-vs-run-function Though, there is a tradeoff in code size: Besides, |
< offtopic > Testing JavaScript performance and having reliable results is a myth... I can never get accurate results with JSPerf. I am on Chrome 9 and my tests are against everyone's expected results. 48 / 42 in favour of Run. Go figure. < /offtopic > As the discussion is moving along I am starting to like
Looks pretty. |
I'm pretty sure I am -1 on this.
is better written / more per-formant as
I'm not sure if the cases where |
Thanks for the bench, Tim. That brings us back to the magical rescoping issue; why it was bad, what we really need and how we can do for it. So how about this:
↓
And of course, the calling part is better written as |
@tim-smart While the usefulness of self-executing closures is debatable (they're mainly about keeping programmers from doing stupid things by keeping their variables isolated), they're common enough that people complain pretty often about the ugliness of having to wrap them in parentheses in CoffeeScript. Also, there was a lengthy issue before discussing implementing some alternative means of calling functions without arguments without using parentheses. There are cases where such a syntax could greatly increase readability (to non-Lispers). While
I find the reduction in nested parentheses to be a breath of fresh air. |
(function(){ return; })()
var __break={}; try{ (function(){ throw __break; })() }catch(__E){ if(__E===__break)break; else throw __E; }
var __return=function(__arg){this.value=__arg;}; try{ (function(){ throw new __return(val); })() }catch(__E){ if(__E instanceof __return)return __E.value; else throw __E; } |
Since discussion on this ticket has settled down, I'm closing it as a
|
Here's how it is more compact in my case. I like having the ability to close some variables without having to use the more verbose method, or naming a function I don't need named.
|
Ah, I was just bitten by this. Since we removed the magic from generated closures on master I had to go back and change my code in quite a few places. This is jut ugly:
I mostly agree with Jeremy, apart from:
I like my code to be linear. If I define functions before I use them this breaks my rule. |
I've implemented the hack proposed in my last post on my branch. |
FYI -- the magic to generate closures inside of loops is back on master. |
FYI, again -- the magic to generate closures is back off master, for once and for all, and I've added |
We all know the usefulness of this idiom, but the ugliness of the parens is intolerable.
new ->
works sometimes, but is flawed.Would be really nice if we could find a way to pass arguments as well.
The text was updated successfully, but these errors were encountered: