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

which() warning about operator precedence #213

Closed
iynehz opened this issue Jan 28, 2018 · 4 comments
Closed

which() warning about operator precedence #213

iynehz opened this issue Jan 28, 2018 · 4 comments

Comments

@iynehz
Copy link

iynehz commented Jan 28, 2018

For example, below code gives warning Possible precedence problem on bitwise | operator

use strict;
use warnings;
use PDL::LiteF;
my $a = sequence(5);
which($a < 1 | $a > 3);

I know I can suppress it by no warnings 'precedence';, but is there any better ways?

@zmughal
Copy link
Member

zmughal commented Jan 28, 2018

The only way outside of disabling the warning is to add extra parentheses so that Perl knows that you meant to write the code that way:

which( ( $a < 1 ) | ( $a > 3 ) );

@mohawk2
Copy link
Member

mohawk2 commented Jan 28, 2018

Am I missing something? I see that warning as a good thing, and indeed that one should use parens. If one wants to suppress it, no warnings is how. @stphnlyd Thoughts?

@iynehz
Copy link
Author

iynehz commented Jan 29, 2018

Thanks @zmughal, @mohawk2 ! I am new to PDL, and I've not been using bitwise operator in Perl for long that the parentheses thing did not come to my mind. And you know R's which() method does not require parens in this case. I think this ticket can be closed now, but I wonder if it could be better to add an example to which() in PDL::Primitive, so that people like me can just figure it out.

@mohawk2
Copy link
Member

mohawk2 commented Jan 29, 2018

@stphnlyd You're probably right about the example. PRs welcome :-) I'll close this issue.

@mohawk2 mohawk2 closed this as completed Jan 29, 2018
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

3 participants