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

Using tuples as arguments #17274

Closed
brain113 opened this issue Sep 15, 2014 · 5 comments
Closed

Using tuples as arguments #17274

brain113 opened this issue Sep 15, 2014 · 5 comments

Comments

@brain113
Copy link

In rust we have possibility to return several values in tuple. But we can't use it vice versa: to put several arguments to function in tuple. Like this:

fn main() {
    sum(prepare_args());
}

fn sum(x: int, y: int) -> int {
    x + y
}

fn prepare_args () -> (int, int) {
    (1, 2)
}

I think it will be very usefull.

@jdm
Copy link
Contributor

jdm commented Sep 15, 2014

This is already possible, just not automatically like your snippet suggests:

fn sum((x, y): (int, int)) -> int {

@jfager
Copy link
Contributor

jfager commented Sep 15, 2014

You could go the apply route a la lisp:

fn apply<A,B,C>(f: |A,B|->C, t: (A,B)) -> C {
    let (a,b) = t;
    f(a,b)
}

fn main() {
    apply(sum, prepare_args());
}

I believe you should be able to mimic Scala's tupled w/ unboxed closures, but I'm not sure if that's possible yet.

@ftxqxd
Copy link
Contributor

ftxqxd commented Sep 15, 2014

Variadic generics adds a similar feature to Rust, but with a more explicit syntax: foo(..(1, 2, 3)) == foo(1, 2, 3). Unfortunately, we’re probably not going to get variadic generics (at least not before 1.0).

@pcwalton
Copy link
Contributor

"Before 1.0" isn't relevant; Rust is on a rolling release model.

@thestinger
Copy link
Contributor

A language change like this should be proposed through the RFC process:

https://github.com/rust-lang/rfcs

An issue like this isn't actionable because a clear design and consensus to implement it are required before making language changes.

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