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

Lambdas #3848

Merged
merged 12 commits into from
Sep 20, 2024
Merged

Lambdas #3848

merged 12 commits into from
Sep 20, 2024

Conversation

CJ-Johnson
Copy link
Contributor

@CJ-Johnson CJ-Johnson commented Apr 3, 2024

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:

@CJ-Johnson CJ-Johnson added the proposal rfc Proposal with request-for-comment sent out label Apr 3, 2024
@github-actions github-actions bot added the proposal A proposal label Apr 3, 2024
@CJ-Johnson CJ-Johnson added proposal draft Proposal in draft, not ready for review proposal rfc Proposal with request-for-comment sent out and removed proposal rfc Proposal with request-for-comment sent out proposal draft Proposal in draft, not ready for review labels Apr 4, 2024
@CJ-Johnson CJ-Johnson marked this pull request as ready for review April 4, 2024 17:56
@github-actions github-actions bot requested a review from chandlerc April 4, 2024 17:56
proposals/p3848.md Show resolved Hide resolved
proposals/p3848.md Outdated Show resolved Hide resolved
proposals/p3848.md Outdated Show resolved Hide resolved
proposals/p3848.md Outdated Show resolved Hide resolved
proposals/p3848.md Outdated Show resolved Hide resolved
proposals/p3848.md Outdated Show resolved Hide resolved
proposals/p3848.md Outdated Show resolved Hide resolved
proposals/p3848.md Outdated Show resolved Hide resolved
proposals/p3848.md Outdated Show resolved Hide resolved
proposals/p3848.md Outdated Show resolved Hide resolved
proposals/p3848.md Outdated Show resolved Hide resolved
proposals/p3848.md Show resolved Hide resolved
proposals/p3848.md Outdated Show resolved Hide resolved
proposals/p3848.md Outdated Show resolved Hide resolved
proposals/p3848.md Outdated Show resolved Hide resolved
proposals/p3848.md Outdated Show resolved Hide resolved
proposals/p3848.md Outdated Show resolved Hide resolved
proposals/p3848.md Outdated Show resolved Hide resolved
proposals/p3848.md Outdated Show resolved Hide resolved
proposals/p3848.md Outdated Show resolved Hide resolved
proposals/p3848.md Show resolved Hide resolved
proposals/p3848.md Show resolved Hide resolved
github-merge-queue bot pushed a commit that referenced this pull request May 29, 2024
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>
proposals/p3848.md Outdated Show resolved Hide resolved
Copy link
Contributor

@zygoloid zygoloid left a 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!

proposals/p3848.md Outdated Show resolved Hide resolved
Copy link
Contributor

@chandlerc chandlerc left a 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.

proposals/p3848.md Outdated Show resolved Hide resolved
proposals/p3848.md Outdated Show resolved Hide resolved
proposals/p3848.md Outdated Show resolved Hide resolved
proposals/p3848.md Outdated Show resolved Hide resolved
proposals/p3848.md Outdated Show resolved Hide resolved
proposals/p3848.md Outdated Show resolved Hide resolved
proposals/p3848.md Outdated Show resolved Hide resolved
proposals/p3848.md Show resolved Hide resolved
proposals/p3848.md Show resolved Hide resolved
proposals/p3848.md Outdated Show resolved Hide resolved
@chandlerc
Copy link
Contributor

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.

@KateGregory
Copy link
Contributor

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.

@CJ-Johnson
Copy link
Contributor Author

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 // In a variable: and // In a function call: variants to the top level examples. Hopefully this will clarify things :)

Copy link
Contributor

@chandlerc chandlerc left a 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.

Copy link
Contributor

@zygoloid zygoloid left a 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.

proposals/p3848.md Outdated Show resolved Hide resolved
proposals/p3848.md Outdated Show resolved Hide resolved
proposals/p3848.md Outdated Show resolved Hide resolved
@chandlerc
Copy link
Contributor

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.

@chandlerc
Copy link
Contributor

Accepting the suggestions as requested and merging!

chandlerc and others added 2 commits September 19, 2024 19:02
Co-authored-by: Richard Smith <richard@metafoo.co.uk>
Co-authored-by: Richard Smith <richard@metafoo.co.uk>
@chandlerc chandlerc added this pull request to the merge queue Sep 20, 2024
Merged via the queue into carbon-language:trunk with commit 864c832 Sep 20, 2024
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
proposal rfc Proposal with request-for-comment sent out proposal A proposal
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants