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

Unified function / method call syntax #6974

Closed
tj opened this issue Jun 6, 2013 · 8 comments
Closed

Unified function / method call syntax #6974

tj opened this issue Jun 6, 2013 · 8 comments

Comments

@tj
Copy link

tj commented Jun 6, 2013

I'm not sure how this would play out with internals or if it wouldn't provide enough information to the compiler, but instead of something like:

impl Shape for Circle {
    fn draw(&self, s: Surface) { do_draw_circle(s, *self); }
}

If possible it would be great to just do something like:

fn draw(self: Circle, s: Surface) {
  // ...
}

Where circle.draw(surface) is just sugar for draw(circle, surface).

@bstrie
Copy link
Contributor

bstrie commented Jun 6, 2013

Oh hai there visionmedia...

I believe we've discussed something like this in the past, but I don't think we've ever actually opened a ticket for it. See http://thread.gmane.org/gmane.comp.lang.rust.devel/2622/ for the most recent discussion (which is still pretty ancient, at six months old). @pcwalton was the one spearheading this effort, he might have more to say.

@tj
Copy link
Author

tj commented Jun 18, 2013

Another cool reason if possible beyond removing some nesting is function composition. I was going to implement it in Luna as | so it would mirror the pipes we're all used to:

cat('contacts.txt') | grep('Tobi') | print

becomes a more readable form of:

print(grep(cat('contacts.txt'), 'Tobi'))

but then I realized the method syntax sugar I wanted was effectively the same thing haha, but either way I think cat('contacts.txt').grep('Tobi').print() is nicer in a lot of cases

@brson
Copy link
Contributor

brson commented Jun 27, 2013

Making this the issue for 'unified function calls'. Changing title.

@brson
Copy link
Contributor

brson commented Jun 27, 2013

nominating

@bstrie
Copy link
Contributor

bstrie commented Jul 15, 2013

This is nominated, but for which milestone? I know we've been talking about this for a very long time, it would be nice to know if we expect this to be a 1.0 feature.

@catamorphism
Copy link
Contributor

If this is deferred past 1.0, we won't consider it a tragedy. Removing nomination.

@steveklabnik
Copy link
Member

This RFC has been accepted, and #16293 was created to track it.

@rust-highfive
Copy link
Collaborator

This issue has been moved to the RFCs repo: rust-lang/rfcs#289

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants