-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Lambdas #3848
Lambdas #3848
Conversation
e119bcb
to
4b408a2
Compare
Parse the name of a declaration as a sequence of `NameQualifier`s -- which have a name, possibly parameters, and a trailing period -- followed by a name and possibly parameters. This prepares us for parsing declarations of members of generic classes and similar cases, but actually supporting such member redeclarations is left to a future change. We previously required functions to have parameters, but no longer do, following the direction of #3848. Cases like namespaces that can't actually have parameters are now diagnosed in check instead of in parse. --------- Co-authored-by: Jon Ross-Perkins <jperkins@google.com>
ca4be05
to
b523652
Compare
b523652
to
2460c5f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me, thanks, and sorry for the slow review cycle!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very happy with the direction here. A bunch of comments, but they're all focused on the proposal write up, not the specific proposed feature.
Another suggestion for the proposal -- I think it'd be nice to add some comparison for how the Carbon lambdas would look in C++. This doesn't need to get into features that C++ lambdas have and Carbon's don't, just showing how analogous C++ lambdas would look so that folks can compare. |
I'm really liking this. A few small comments. More calling examples, ideally right after the first syntax example. "This would be invoked like this:" kind of thing. I see just one (though I may have missed others) example of a lambda not being put into a variable but being used right away, the comparator in the sort example. This is terrific but may be missed by someone less interested in positional parameters, so some other examples of unnamed lambdas just being used would be great. I would hate for a reader to think that the #1 use of lambdas is to put them into a named variable or value. |
Thanks for the feedback, Kate! I tried to address it by adding both |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this LGTM, checking with leads before approving.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Some extremely minor nit-picking with equivalent versions of some of the examples in C++ here, but I'm happy with this either way; I don't think these affect the understandability of the proposal and certainly don't affect the proposed approach.
Just confirming that @KateGregory gave a thumbs up offline here -- this is good to go. @CJ-Johnson - wanted to give you a chance to merge the suggestions from @zygoloid, but also happy to merge them for you and merge the PR whenever. |
Accepting the suggestions as requested and merging! |
Co-authored-by: Richard Smith <richard@metafoo.co.uk>
Co-authored-by: Richard Smith <richard@metafoo.co.uk>
This document proposes a path forward to add lambdas to Carbon. It further proposes augmenting function declarations to create a more continuous syntax between the two categories of functions. In short, both lambdas and function declarations will be introduced with the
fn
keyword. The presence of a name distinguishes a function declaration from a lambda expression, and the rest of the syntax applies to both kinds. By providing a valid lambda syntax in Carbon, migration from from C++ to Carbon will be made easier and more idiomatic. In C++, lambdas are defined at their point of use and are often anonymous, meaning replacing them solely with function declarations would create an ergonomic burden compounded by the need for the migration tool to select a name.Associated discussion docs: