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

The *= operator ought to act on the left #5

Closed
charlesstaats opened this issue Nov 21, 2015 · 2 comments
Closed

The *= operator ought to act on the left #5

charlesstaats opened this issue Nov 21, 2015 · 2 comments

Comments

@charlesstaats
Copy link
Contributor

Currently, operators followed by an equals sign always act on the right. For instance, a /= b; is equivalent to a = a / b;, with the b on the right. This is essential for some operators (-, /, %) and fine for others (+, ^), but it's the wrong thing to do for the * operator because when * is noncommutative, the action is generally on the left. For instance, the following line ought to work but currently doesn't:

currentpicture *= shift((-5,0));
@johncbowman
Copy link
Member

Since Asymptote is a C-like language, we follow the usual convention that self operators apply the right operand on the
right: see for example this link. Self operators are just a syntactical convenience. If you want to shift currentpicture by (-5,0) then it is best to be explicit:
currentpicture=shift((-5,0))*currentpicture;
Anything else would cause confusion. For example, most users would expect

real[][] A={{1,0},{1,0}};
real[][] B={{1,1},{0,0}};
A *= B;

to produce

1       1
1       1

not

2       0
0       0

@charlesstaats
Copy link
Contributor Author

For the * operator, the vast majority of users will never have used it in a C-like language for an asymmetric operation like translation or matrix multiplication. And I think the sort of users who would want to use *= for matrix-matrix multiplication will not assume confidently that it acts on the right. And I still think acting on the right is the wrong convention here since it makes it less compact to e.g. apply a matrix to a vector.

That having been said, the C++ eigen library choose the same convention you do:

compound operator *= as in a*=b (this multiplies on the right: a*=b is equivalent to a = a*b)

Since they feel the need to explicitly document this, they presumably foresaw that at least some users would not find this obvious. But if the goal is to respect existing conventions, what evidence there is seems to be on your side.

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

No branches or pull requests

2 participants