Closed Kaiser1989 closed 2 years ago
This is by design.
Comparison operators (i.e. ==
, !=
, <
, <=
, >
, >=
), when applied to different types, will always return false
(!=
returns true
), unless that specific operator has been defined with a custom function.
https://rhai.rs/book/language/logic.html#comparing-different-types-defaults-to-false
This is to simplify a lot of code, for example:
let x = get_some_value();
if x == 42 { ... } // defaults to false for all non-numeric values of x, e.g. ()
Perfect, Thanks for your fast answer!
This means i have to add some comparators now ;)
If it is just for printing you can do:
print(`1.0 ${|x| x + 1}`);
I noticed some strange comparison behaviours:
output:
where comparing any number with booleans or closures returns false (would expect an error, function not found).