-
Notifications
You must be signed in to change notification settings - Fork 214
Support shorthand argument names for closures #712
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
Comments
Cf. similarities with #265. |
Or just write children: [for (var p in list) Thing(p)] and avoid the closure entirely. If we had constructor tear-offs, it would just be children: [...list.map(Thing)] |
@eernstg it is similar, but are you able to refer to multiple arguments? In Swift you can use |
No, #265 only supports 0 arguments or 1 argument, but maintains that a function literal can be recognized syntactically. If we use a mechanism that cannot be recognized as a function literal (because it's just a function body which could perfectly well parse as an expression) then we'd have to rely on the static typing before we could even make the choice of making it a function literal respectively an expression. But it's still tricky, e.g., would |
Swift uses square brackets for map (dictionary) literals, |
How would that disambiguate |
@eernstg i'm sorry, i think you lost me in that reasoning, i'm not that deep into language design ( or just not smart enough ), i just find that syntactic sugar helpful. please feel free to close this issue if you are a contributor and don't think this is relevant. |
@erf wrote:
Sorry about that, the problem I was referring to is simply that we don't know how big a given function literal is, and there could be lots of possibilities: list.map(Thing((x) => x)).toList()
list.map((x) =>Thing(x)).toList()
((x) => list.map(Thing(x))).toList()
(x) => list.map(Thing(x)).toList() We could easily have a situation where more than one of those is not a type error (and an expression could be a lot bigger, so we could have many more possible interpretations), and even if there is exactly one interpretation which is not an error it isn't very good for the readability of the source code if you need to know the details of sub-expression typing in order to know how much of an expression is implicitly turned into a function literal. @tatumizer wrote:
That would not be difficult. |
Ok, i'm closing now since it seem to be a duplicate of #265 |
Uh oh!
There was an error while loading. Please reload this page.
I'd like to propose Shorthand Argument Names, like in the Swift language, so you can omit to explicit name arguments, but rather refer to them by
$0, $1
etc. Which would result in less code and typing.So instead of:
You could write:
The text was updated successfully, but these errors were encountered: