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
  • Comment on Re^4: 5.40 released- native boolean- convert to [01] without any warning|error
  • Download Code

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

    Perl doesn't work like any of those languages. In those, type determines operation. In Perl, operation determines type. So comparing how they handle types isn't fruitful. You're assuming that what's best in one framework is best in a different one. You need to start by establishing that this is the case. Your argument fails until then. (I'm not commenting on your conclusion. Maybe it's right; maybe it's wrong. I'm simply saying you failed to show that it's right.)

    Perl also has strong roots in C, yet you omit to mention C anywhere in your post. Note that in C, you do not get a warning from using true and false as numbers. (Again, not commenting on whether this is best or not. I'm saying it's something you should have addressed as it undermines your argument.)