in reply to Re^3: 5.40 released- native boolean- convert to [01] without any warning|error
in thread 5.40 released
Because not to confuse|treat a boolean as integer as it happens in Lua, Ruby (someone else mentioned), Java, & Rust (code+compiler error for last 2 is below).
A C++ compiler will not complain on implicit conversion (per casual search; a Clang linter warning exists: readability-implicit-bool-conversion).
In context of Perl, was hoping that "native boolean" -- as mentioned earlier -- would actually be so and no more, to, perhaps, slowly (very) update Perl😐
# Java. class TruthySome { public static void main() { int[] some = { 4, 5, 6 }; System.out.println( some[ true ] + " " + some[ false ] ); } } truth.java:6: error: incompatible types: boolean cannot be converted t +o int System.out.println( some[ true ] + " " + some[ false ] ); ^ truth.java:6: error: incompatible types: boolean cannot be converted t +o int System.out.println( some[ true ] + " " + some[ false ] ); ^ 2 errors # Rust. fn main() { let some = [ 4, 5, 6 ]; println!( "{} {}", some[ true ], some[ false ] ); } Compiling truth v0.1.0 (/tmp/rust/truth) error[E0277]: the type `[{integer}]` cannot be indexed by `bool` --> src/main.rs:3:29 | 3 | println!( "{} {}", some[ true ], some[ false ] ); | ^^^^ slice indices are of type `usize` + or ranges of `usize` | = help: the trait `SliceIndex<[{integer}]>` is not implemented for ` +bool`, which is required by `[{integer}; 3]: Index<_>` = note: required for `[{integer}]` to implement `Index<bool>` = note: 1 redundant requirement hidden = note: required for `[{integer}; 3]` to implement `Index<bool>` error[E0277]: the type `[{integer}]` cannot be indexed by `bool` --> src/main.rs:3:43 | 3 | println!( "{} {}", some[ true ], some[ false ] ); | ^^^^^ slice indices are +of type `usize` or ranges of `usize` | = help: the trait `SliceIndex<[{integer}]>` is not implemented for ` +bool`, which is required by `[{integer}; 3]: Index<_>` = note: required for `[{integer}]` to implement `Index<bool>` = note: 1 redundant requirement hidden = note: required for `[{integer}; 3]` to implement `Index<bool>` For more information about this error, try `rustc --explain E0277`. error: could not compile `truth` (bin "truth") due to 2 previous error +s
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^5: 5.40 released- native boolean- convert to [01] without any warning|error
by ikegami (Patriarch) on Jun 15, 2024 at 12:53 UTC |