Replies: 3 comments 3 replies
-
That's an interesting point. We could indeed make the bitwise operations evaluate lazily. This has been implemented for example for the conditional operator. I think the bitwise operators also have a different precedence compared to math.parse('false and undefined < 1').toString({ parenthesis: 'all' })
// 'false and (undefined < 1)' I'm always open to reconsider the operator precedence if there is a good reason for it. |
Beta Was this translation helpful? Give feedback.
-
Shall we change the title of this issue to "Implement lazy evaluation for bitwise operators"? |
Beta Was this translation helpful? Give feedback.
-
@josdejong : I'm very keen for this feature, and would be happy to implement it. However, while I've prototyped making this work to prove that I could, I would like to do this in a way that is likely to be accepted before I spend too much time on it. I can see a few ways of doing this. The core barrier I observe is that, right now,
Whichever option, there is some additional logic to implement for when the arguments are matrices or arrays. We'd either need to (a) have a check on whether At any rate, I'd love to hear your thoughts, and I'm definitely keen to create a PR if an approach like one of the above sounds viable! |
Beta Was this translation helpful? Give feedback.
-
Version: mathjs-v5.2.3
I have found some inconsistency between MathJS and other programming languages, like JS or Java when using boolean operations and / or. Other programming languages only evaluate the right expression lazily (for example, see http://www.cafeaulait.org/course/week2/46.html).
Steps to reproduce (just an example):
console.error(math.eval('true or undefined < 1'));
console.error(math.eval('false and undefined < 1'));
Expected behaviour:
In the development tools, one can see the following lines printed:
true
false
Actual behaviour:
For both expressions an error is thrown:
Unexpected type of argument in function smaller (expected: Array or DenseMatrix or SparseMatrix or Matrix, actual: number, index: 1)
Beta Was this translation helpful? Give feedback.
All reactions