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

-- 
Peter Pentchev  r...@ringlet.net r...@debian.org p...@storpool.com
PGP key:        http://people.FreeBSD.org/~roam/roam.key.asc
Key fingerprint 2EE7 A7A5 17FC 124C F115  C354 651E EFB0 2527 DF13

Attachment: signature.asc
Description: PGP signature

Reply via email to