On 2020-05-16 17:44, Peter Pentchev wrote:
On Sat, May 16, 2020 at 03:19:05PM -0700, ToddAndMargo via perl6-users wrote:
On 2020-05-16 06:38, Peter Pentchev wrote:
$ raku *-e* "your one-liner script here"
And also you might want to put some quotes around the paths to let Raku
know that those are strings and not some identifiers or something.

G'luck,
Peter


Hi Peter,

This is what goofed me up:

$ alias p5
alias p5='perl -E'

$ alias p6
alias p6='perl6 -e'

I have no such feature on the Windows side and had
forgot about it.

Also, if you tack a .Bool on the end of IO.d, you
get back True or False, instead of the useless True
or Crash.  I updates my perl6.IO.txt keeper file.

And IO.e also works for directories

What you're doing with "tacking .Bool at the end" is usually not
necessary to do explicitly, because most people do not "say" the result
of .d or .e, but use it in an if, for, while or some such conditional
statement, in which case Raku automatically converts the expression to
a boolean, i.e. tacks a .Bool at the end.

The reason .d and .e return a failure otherwise is that in some cases
they may be used not in a conditional statement, but as a kind of
assertion - "I really, really think that at this point this variable
should contain a valid path to an existing directory, but if something
went wrong in my program and the variable does not contain that, I do
not want the program to go on, it would be useless, I *want* it to raise
an exception when the value is used". At least that's what I think;
I *know* that the people who rewrote .IO in v6.d are on this list, so
please correct me if I'm wrong :)

But the most common use of .d, .e, .f and similar, the most common by
a very large margin, is in conditionals, where Raku does the conversion
to a boolean value automatically.

G'luck,
Peter


Hi Peter,

My big issues is that  want to check to see if something
is there, then take appropriate measures based on what
I am doing.  Crashing is not what I want.  If I should
exit based on what I find, I want the control over it.

In my "if" statements, I will use Bool anyway as it
will force the issue. And will alert me that there
is something else going on that I should be aware of
(fail).

Now I have to look up f.

Found it.  If you use the Bool, it returns a False
for directories.   Cool.

Thank you for the detailed explanation.  Very useful
and helpful!


Just out of curiosity

     https://docs.raku.org/routine/d
     (IO::Path) method d
     Defined as:

     method d(--> Bool:D)

     Returns True if the invocant is a path that
     exists and is a directory. The method will
     fail with X::IO::DoesNotExist if the path points to
     a non-existent filesystem entity.

Where in the definition
    method d(--> Bool:D)
does it state True or Fail?  It states "Bool".  Is
something missing?

-T

Reply via email to