-
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
Nominal classes and methods #722
Conversation
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.
(Not actually done, just don't want to fail to mash "send". Made it up to "Access control".)
Co-authored-by: Chandler Carruth <[email protected]>
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.
(ok, now finished!)
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, probably just a TODO to add below.
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.
Co-authored-by: Chandler Carruth <[email protected]>
(LGTM and all the thumbs up arrived.) |
Add support for nominal (or "named") classes with encapsulation. Inheritance will be in a later proposal. Here is an example of the proposed syntax: ``` class Circle { fn Create(c: Point, r: f32) -> Self { return {.center = c, .radius = r}; } fn Diameter[me: Self]() -> f32 { return me.radius * 2; } fn Expand[addr me: Self*](distance: f32); private var center: Point; private var radius: f32; } fn Circle.Expand[addr me: Self*](distance: f32) { me->radius += distance; } ``` Co-authored-by: Chandler Carruth <[email protected]>
Carbon has been using a `me: Self` or `addr me: Self*` deduced parameter to mark a function as a method as decided in #494 and implemented in #722 . This does not match existing languages, and so this proposal switches `me` to `self` to match Python, Rust, and Swift. Co-authored-by: Richard Smith <[email protected]>
Add support for nominal (or "named") classes with encapsulation. Inheritance will be in a later proposal. Here is an example of the proposed syntax: