in reply to Re: 5.40 released
in thread 5.40 released

On "native boolean" in v5.40 (don't have one yet to call my own), does this produce any error|warning ...

use v5.40; use strict; use warnings; my @some = ( 4, 5, 6 ); print $some[ true ], q[ ], $some[ false ];

... ?

💩Sadly, no ("5 4" are printed; tried on Perl Banjo).

Cross post: https://tech.lgbt/@parvXtl/112606032658432152

  • Comment on Re^2: 5.40 released- native boolean- convert to [01] without any warning|error
  • Download Code

Replies are listed 'Best First'.
Re^3: 5.40 released- native boolean- convert to [01] without any warning|error
by Danny (Chaplain) on Jun 12, 2024 at 22:34 UTC
    Why would you want it to issue a warning in that context? Seems consistent with
    print $some[ 1 > 0 ], q[ ], $some[ 1 < 0 ];

      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😐

        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.)