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.
Plus it makes it more readable for me.
[something].IO.<someletter>.Bool
tells me instantly I will be getting back a yes
or no answer.
So if you want to be a purist, you can experiment with
which IO.<some_letter> are going to give you a yes
or no answer or which functions will convert X::IO::DoesNotExist for
you. OR you can just tack .Bool
at the end and forgo the hair pulling.
Also the cryptograms in the documentation are not
correct. For instance:
https://docs.raku.org/routine/d
method d(--> Bool:D)
Says it return a "Bool" not a "True" or "X::IO::DoesNotExist".
The modification to Bool is stated at the bottom of the page.
So, basically, it is to keeps me out of trouble. And if
I am going to get `X::IO::DoesNotExist` back instead of
a Boolean, .Bool automatically converts it for me and
with no hair pulling.
So, basically, my LONG WINDED answer is that I do it for me.
-T