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
Implicit argument #739
Comments
What identifier do you suggest using? I believe |
I think
It'll become available only when you omit arguments and use Just see: http://github.com/satyr/coffee-script/compare/master...it |
Wouldn't it change the functionality here: |
Same deal as Groovy: |
I'm not a fan of this syntax sugar in these other languages. I think it makes up for the lack of the right syntax sugars. As an example, I particularly dislike the Scala example in the OP because it shows that operators are not first-class values in Scala in the same way that a function or the number |
So, basically the proposal is to have a keyword that works as shorthand for What kind of DSLs were you thinking of? |
@TrevorBurnham: It's not just
becomes
or if we wanted to skip the array accesses
|
Wait, wasn't satyr proposing that
could compile to
Wouldn't that be clearer than using the same symbol to reference multiple arguments? |
Actually, I like the scheme syntax:
And it may also lend itself to an
But I'm not sure yet if that would cause syntactic problems with the less-than and greater-than operators. |
Great idea. Ruby doesn't have one, but with Syntax Tree metaprogramming, you can hook it into the langauge (I am writting such extension, which can be plugged in runtime) |
At the risk of scope creep, I really like the idea of an |
I reckon there is enough magic in the language as it is and there is no need for another keyword, special character or what not for the extra convenience, no ? It just doesn't bring enough on the table. |
I'm with Stan and Trevor on this one. This is a great ticket, and there are a large number of proposals in it, but in the end the most-coffee-ish one is this:
And looking at our current definition:
It really doesn't seem like a good idea. It's not flexible, in that naming anything other than the first argument would be an ugly hack; and is not readable, in that it encourages all arguments to be named "it", instead of something descriptive. Closing as a |
Too bad. With RubyUnderscore, now even ruby has it. Guess the workaround for coffeescript will be the same: injected into coffeescrip by manipulating AST(--nodes can be of great help here). |
For the record, Coco ended up doing both. |
nice! |
Many modern/popular languages adopt syntax sugars for simpler functions. Could we as well?
Arc
(= squared [* _ ])
Clojure
(def squared #(* % %))
Groovy
squared = {it * it}
Perl6
$mul = {$^a * $^b}
Scala
var sixty = List(3, 4, 5).reduceLeft( * _)
Scheme
(define mul (cut * <> <>))
Behaviors vary, but the basic idea is same: to DRY.
Among above, Arc/Groovy's is the simplest and easy to implement:
$ bin/coffee --no-wrap -pe 'compact = -> it.filter -> it?'
var compact;
compact = function(it) {
return it.filter(function(it) {
return (it != null);
});
};
See also: #111 #330
The text was updated successfully, but these errors were encountered: