On 2020-05-17 13:04, Peter Pentchev wrote:
On Sun, May 17, 2020 at 12:12:51PM -0700, ToddAndMargo via perl6-users wrote:
On 2020-05-17 03:36, Peter Pentchev wrote:
On Sun, May 17, 2020 at 03:01:34AM -0700, ToddAndMargo via perl6-users wrote:
On 2020-05-17 02:30, Peter Pentchev wrote:
You said that you would tack Bool at the end in "if" statements, too.

Hi Peter,

No wonder.  I do not remember saying that, but I could
have.  My `if` statements look like:

     if not  "%Options<Path>".IO.d.Bool  {
        say "Creating %Options<Path>";
        mkdir( %Options<Path>", 0o777 );
     }

I definitely do not tack .Bool onto the end
of my `if` statements.

Uh. That's exactly what you're doing. You do *not* need the .Bool
there at the end. The "not" makes Raku convert whatever is there
to a boolean, so the .Bool is implicit. And if you were to check
the other way, if you had "if $foo.IO.d { ... }", then the "if"
makes Raku convert whatever is there to a boolean, so the .Bool is
implicit. You do not need to put the .Bool in an "if" or a "while"
statement.

G'luck,
Peter


Hi Peter,

Brad asked me the same thing on another thread.  This is what I
told him:

Hi Brad,

I do this because it keeps me out of trouble.

I want back a yes or no answer, not True or Fail
(X::IO::DoesNotExist).

And I never remember which IO.<some_letter> will return
a True or Fail or which functions (`if` does) will
convert X::IO::DoesNotExist to a False for me.

OK, so I promise to the group that this is my last message on this
particular topic :)

Todd, you won't have to remember anything if you *only* use .IO.d and
.IO.e and all the rest the way the rest of the world uses them: *only*
in conditional statements. Your examples could have been written as:

     raku -e "say 'yes' if 'h:/'.IO.d"

...and you would not have to remember anything except that .IO.d, .e,
.f, and the rest of these predicates only need to be used in
conditionals. This covers 'if', 'while', and it also covers stuff like
"my $final-decision = $path.IO.d and $path.IO.w", since this is also
using the predicates in a sort of a conditional statement. Basically,
in any *real-world* situation where you'd want to use them, you don't
need the explicit conversion to boolean.

Hope that helps.

G'luck,
Peter


Hi Peter,

Very true.

Although

   "say 'yes' if 'h:/'.IO.d"

is obscure to me and

   "say 'h:/'.IO.d.Bool"

is very easy for me to understand.

And since I am the one who is going to have to
maintain this code in perpetuity, maintainability
comes before everything else.  EVEN IF I have to
tell Raku to do something explicitly that it will
do for me on the fly.  It is all about me being
able to go into the code 5 days or 5 years
from now and being able to figure out what I did.

I had to convert a Perl 5 sub over and oh my goodness
the hoops I had to jump thought in Perl 5 that and
so very simplified in Raku.

Perl 5 does have the bad reputation of being a write
only language. (It is, only if you let it be.)

I likes Perl 5.  I ADORE Perl 6

-T

p.s. you are a wonderful teacher.  Do you have a
teaching background?

Reply via email to