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

Assigning from tuples #2

Open
mklingen opened this issue Aug 26, 2015 · 2 comments
Open

Assigning from tuples #2

mklingen opened this issue Aug 26, 2015 · 2 comments

Comments

@mklingen
Copy link

The following expression does not work:

function f(a, b)
{
    return (a + b, a * b);
}

print f(1, 2);

It gives the error:

line 3:17 mismatched input u',' expecting ')'
line 3:21 no viable alternative at input u'*'
line 3:24 extraneous input u')' expecting ';'

Similarly, this:

x = (1, 2);

gives the error:

line 1:6 missing ')' at u','
line 1:8 no viable alternative at input u'2'

What's the proper way of dealing with tuples in cpy?

@ideawu
Copy link
Owner

ideawu commented Aug 27, 2015

Hi, cpy does not support tuples grammar, you can use the tuple function to convert list to tuple:

c = 2;
d = 3;
a = tuple([1+c, 2+d]);
print a;

@mklingen
Copy link
Author

That's too bad, because it prevents cpy from being able to interface with libraries that return multiple values. Consider a library that returns a tuple. In python, it would be as easy as:

(return_1, return_2) = library.function()

In cpy, would we have to do this?

return_tuple = library.function();
return_1 = return_tuple[0];
return_2 = return_tuple[1];

If so, that's fine, but maybe it should be in the documentation.

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

2 participants