Re: I need help with IO.e

2020-05-17 Thread Paul Procacci
Don't 'say' anything.  Just let the optimizer spit out the QAST that you
are interested in looking at.
The following spits out a diff after optimization:

# diff -u <(perl6 --target=optimize -e '"test".IO.e') <(perl6
--target=optimize -e '"test".IO.e.Bool')

>> Huh.  Not sure what I am looking at

You aren't specific.  Is it the error message you received because you used
'say' improperly or is it the QAST?
- How to use 'say' is in the documentation.
- A QAST is pretty close to an AST and I'd start there on wikipedia or
something.

On Mon, May 18, 2020 at 1:03 AM ToddAndMargo via perl6-users <
perl6-us...@perl.org> wrote:

> On 2020-05-17 21:48, Paul Procacci wrote:
> > You can check this yourself by looking at the QAST nodes after the
> > static analyzer has had its fill:
> >
> > # diff -u <(perl6 --target=optimize -e '"test".IO.e') <(perl6
> > --target=optimize -e '"test".IO.e.Bool')
>
> Huh.  Not sure what I am looking at
>
>
> $ diff -u <(perl6 --target=optimize -e 'say if "test".IO.d') <(perl6
> --target=optimize -e 'say "test".IO.d.Bool')
> ===SORRY!=== Error while compiling -e
> Unsupported use of bare "say"; in Raku please use .say if you meant to
> call it as a method on $_, or use an explicit invocant or argument, or
> use  to refer to the function as a noun
> at -e:1
> --> say⏏ if "test".IO.d
> --- /dev/fd/63  2020-05-17 22:01:37.947790677 -0700
> +++ /dev/fd/62  2020-05-17 22:01:37.948790659 -0700
> @@ -0,0 +1,98 @@
> +- QAST::CompUnit  :W :UNIT :CAN_LOWER_TOPIC
> +  [pre_deserialize]
> +- QAST::Stmt
> +  - QAST::Stmt
> +- QAST::Op(loadbytecode)
> +  - QAST::VM
> +[moar]
> +  - QAST::SVal(ModuleLoader.moarvm)
> +[jvm]
> +  - QAST::SVal(ModuleLoader.class)
> +[js]
> +  - QAST::SVal(ModuleLoader)
> +- QAST::Op(callmethod load_module)
> +  - QAST::Op(gethllsym)
> +- QAST::SVal(nqp)
> +- QAST::SVal(ModuleLoader)
> +  - QAST::SVal(Perl6::ModuleLoader)
> +  - QAST::Op(forceouterctx)
> +- QAST::BVal(2)
> +- QAST::Op(callmethod load_setting)
> +  - QAST::Op(getcurhllsym)
> +- QAST::SVal(ModuleLoader)
> +  - QAST::SVal(CORE.d)
> +  [post_deserialize]
> +- QAST::Stmts
> +  - QAST::Op(bind)
> +- QAST::Var(attribute $!do)
> +  - QAST::WVal(Block)
> +  - QAST::WVal(Code)
> +- QAST::BVal(1)
> +- QAST::Op(bindcurhllsym)
> +  - QAST::SVal(GLOBAL)
> +  - QAST::WVal(GLOBAL)
> +  [load]
> +- QAST::Op(call)
> +  - QAST::BVal(2)
> +  [children]
> +- QAST::Block(:cuid(2))  :in_stmt_mod say \"test\".IO.d.Bool
> +│ - QAST::Var(local __args__ :decl(param))
> +│ - QAST::Stmts  say \"test\".IO.d.Bool
> +│ - QAST::Op(call)
> +│   - QAST::Block(:cuid(1) :blocktype(declaration_static))
> :outer :in_stmt_mod :code_object :IN_DECL
> +│   │ - QAST::Stmts  say \"test\".IO.d.Bool
> +│   │   - QAST::Var(lexical $¢ :decl(contvar))
> +│   │   - QAST::Var(lexical $! :decl(contvar))
> +│   │   - QAST::Var(lexical $/ :decl(contvar))
> +│   │   - QAST::Op(null)
> +│   │   - QAST::Var(lexical GLOBALish :decl(static))
> +│   │   - QAST::Var(lexical EXPORT :decl(static))
> +│   │   - QAST::Var(lexical $?PACKAGE :decl(static))
> +│   │   - QAST::Var(lexical ::?PACKAGE :decl(static))
> +│   │   - QAST::Var(lexical $=finish :decl(static))
> +│   │   - QAST::Var(lexical $=pod :decl(static))
> +│   │ [value]
> +│   │   -
> +│   │   - QAST::Var(lexical !UNIT_MARKER :decl(static))
> +│   │ - QAST::Stmts
> +│   │   - QAST::Op(bind)
> +│   │ - QAST::Var(local ctxsave :decl(var))
> +│   │ - QAST::Var(contextual $*CTXSAVE)
> +│   │   - QAST::Op(unless)
> +│   │ - QAST::Op(isnull)
> +│   │   - QAST::Var(local ctxsave)
> +│   │ - QAST::Op(if)
> +│   │   - QAST::Op(can)
> +│   │ - QAST::Var(local ctxsave)
> +│   │ - QAST::SVal(ctxsave)
> +│   │   - QAST::Op(callmethod ctxsave)
> +│   │ - QAST::Var(local ctxsave)
> +│   │ - QAST::Stmts
> +│   │   - QAST::WVal(Array)
> +│   │   - QAST::Stmt  say \"test\".IO.d.Bool
> +│   │ - QAST::Want 
> +│   │   - QAST::Op(callstatic )  :statement_id<1> say
> \"test\".IO.d.Bool
> +│   │ - QAST::Op(hllize) 
> +│   │   - QAST::Op(callmethod Bool)  Bool
> +│   │ - QAST::Op(hllize) 
> +│   │   - QAST::Op(callmethod d)  d
> +│   │ - QAST::Op(hllize) 
> +│   │   - QAST::Op(callmethod IO)  IO
> +│   │ - QAST::Want  test
> +│   │   - QAST::WVal(Str)
> +│   │   - Ss
> +│   │   - QAST::SVal(test)
> +│   │   - v
> +│   │   - QAST::Op(p6sink)
> +│   │ 

Re: I need help with IO.e

2020-05-17 Thread ToddAndMargo via perl6-users

On 2020-05-17 21:48, Paul Procacci wrote:
You can check this yourself by looking at the QAST nodes after the 
static analyzer has had its fill:


# diff -u <(perl6 --target=optimize -e '"test".IO.e') <(perl6 
--target=optimize -e '"test".IO.e.Bool')


Huh.  Not sure what I am looking at


$ diff -u <(perl6 --target=optimize -e 'say if "test".IO.d') <(perl6 
--target=optimize -e 'say "test".IO.d.Bool')

===SORRY!=== Error while compiling -e
Unsupported use of bare "say"; in Raku please use .say if you meant to 
call it as a method on $_, or use an explicit invocant or argument, or 
use  to refer to the function as a noun

at -e:1
--> say⏏ if "test".IO.d
--- /dev/fd/63  2020-05-17 22:01:37.947790677 -0700
+++ /dev/fd/62  2020-05-17 22:01:37.948790659 -0700
@@ -0,0 +1,98 @@
+- QAST::CompUnit  :W :UNIT :CAN_LOWER_TOPIC
+  [pre_deserialize]
+- QAST::Stmt
+  - QAST::Stmt
+- QAST::Op(loadbytecode)
+  - QAST::VM
+[moar]
+  - QAST::SVal(ModuleLoader.moarvm)
+[jvm]
+  - QAST::SVal(ModuleLoader.class)
+[js]
+  - QAST::SVal(ModuleLoader)
+- QAST::Op(callmethod load_module)
+  - QAST::Op(gethllsym)
+- QAST::SVal(nqp)
+- QAST::SVal(ModuleLoader)
+  - QAST::SVal(Perl6::ModuleLoader)
+  - QAST::Op(forceouterctx)
+- QAST::BVal(2)
+- QAST::Op(callmethod load_setting)
+  - QAST::Op(getcurhllsym)
+- QAST::SVal(ModuleLoader)
+  - QAST::SVal(CORE.d)
+  [post_deserialize]
+- QAST::Stmts
+  - QAST::Op(bind)
+- QAST::Var(attribute $!do)
+  - QAST::WVal(Block)
+  - QAST::WVal(Code)
+- QAST::BVal(1)
+- QAST::Op(bindcurhllsym)
+  - QAST::SVal(GLOBAL)
+  - QAST::WVal(GLOBAL)
+  [load]
+- QAST::Op(call)
+  - QAST::BVal(2)
+  [children]
+- QAST::Block(:cuid(2))  :in_stmt_mod say \"test\".IO.d.Bool
+│ - QAST::Var(local __args__ :decl(param))
+│ - QAST::Stmts  say \"test\".IO.d.Bool
+│ - QAST::Op(call)
+│   - QAST::Block(:cuid(1) :blocktype(declaration_static)) 
:outer :in_stmt_mod :code_object :IN_DECL

+│   │ - QAST::Stmts  say \"test\".IO.d.Bool
+│   │   - QAST::Var(lexical $¢ :decl(contvar))
+│   │   - QAST::Var(lexical $! :decl(contvar))
+│   │   - QAST::Var(lexical $/ :decl(contvar))
+│   │   - QAST::Op(null)
+│   │   - QAST::Var(lexical GLOBALish :decl(static))
+│   │   - QAST::Var(lexical EXPORT :decl(static))
+│   │   - QAST::Var(lexical $?PACKAGE :decl(static))
+│   │   - QAST::Var(lexical ::?PACKAGE :decl(static))
+│   │   - QAST::Var(lexical $=finish :decl(static))
+│   │   - QAST::Var(lexical $=pod :decl(static))
+│   │ [value]
+│   │   -
+│   │   - QAST::Var(lexical !UNIT_MARKER :decl(static))
+│   │ - QAST::Stmts
+│   │   - QAST::Op(bind)
+│   │ - QAST::Var(local ctxsave :decl(var))
+│   │ - QAST::Var(contextual $*CTXSAVE)
+│   │   - QAST::Op(unless)
+│   │ - QAST::Op(isnull)
+│   │   - QAST::Var(local ctxsave)
+│   │ - QAST::Op(if)
+│   │   - QAST::Op(can)
+│   │ - QAST::Var(local ctxsave)
+│   │ - QAST::SVal(ctxsave)
+│   │   - QAST::Op(callmethod ctxsave)
+│   │ - QAST::Var(local ctxsave)
+│   │ - QAST::Stmts
+│   │   - QAST::WVal(Array)
+│   │   - QAST::Stmt  say \"test\".IO.d.Bool
+│   │ - QAST::Want 
+│   │   - QAST::Op(callstatic )  :statement_id<1> say 
\"test\".IO.d.Bool

+│   │ - QAST::Op(hllize) 
+│   │   - QAST::Op(callmethod Bool)  Bool
+│   │ - QAST::Op(hllize) 
+│   │   - QAST::Op(callmethod d)  d
+│   │ - QAST::Op(hllize) 
+│   │   - QAST::Op(callmethod IO)  IO
+│   │ - QAST::Want  test
+│   │   - QAST::WVal(Str)
+│   │   - Ss
+│   │   - QAST::SVal(test)
+│   │   - v
+│   │   - QAST::Op(p6sink)
+│   │ - QAST::Op(callstatic )  :statement_id<1> 
say \"test\".IO.d.Bool

+│   │   - QAST::Op(hllize) 
+│   │ - QAST::Op(callmethod Bool)  Bool
+│   │   - QAST::Op(hllize) 
+│   │ - QAST::Op(callmethod d)  d
+│   │   - QAST::Op(hllize) 
+│   │ - QAST::Op(callmethod IO)  IO
+│   │   - QAST::Want  test
+│   │ - QAST::WVal(Str)
+│   │ - Ss
+│   │ - QAST::SVal(test)
+│   │   - QAST::WVal(Nil)


Re: How to find if a drive letter exists?

2020-05-17 Thread ToddAndMargo via perl6-users

On 2020-05-17 21:56, ToddAndMargo via perl6-users wrote:

Follow up:


Thank you for all the help figuring all this out!


Re: How to find if a drive letter exists?

2020-05-17 Thread ToddAndMargo via perl6-users

Follow up:

When I go to maintain this thing in five days or five
years and I have one of those "what the h*** is IO.d.Bool
suppose to mean?" moments, I created the follow subs to make the code 
more readable/maintainable.


And mind you I can always look up what IO.d.Bool means
in my own IO documentation, but this makes it human readable.
Saving a lot of time.  Plus, since I program in Top Down,
I call all three of these all over the place in this program:


sub DirectoryExists( Str $DirPath --> Bool ) { return 
"$DirPath".IO.d.Bool; }  # $Full DirPath format is `H:\MyDocsBackup`


sub DriveExists( Str $DriveLetter --> Bool ) { return 
"$DriveLetter".IO.e.Bool; }  # $Drive Letter format is `A:\`


sub FileExists(  Str $FilePath--> Bool ) { return 
"$FilePath".IO.f.Bool; } # $File Path format is `H:\IAmBackup`



   if not  "%Options".IO.e.Bool {..}

versus

   if not  DriveExists( %Options ) {...}

And it is instantly understandable at a glance.  Put
a little extra effort up front and downstream is a
lot easier.

Also, I adore using `not` in place of False and not equal
as it is more human readable.

:-)

-T

We will let the optimizer take care of any of
my unneeded coercing.


Re: I need help with IO.e

2020-05-17 Thread Paul Procacci
You can check this yourself by looking at the QAST nodes after the static
analyzer has had its fill:

# diff -u <(perl6 --target=optimize -e '"test".IO.e') <(perl6
--target=optimize -e '"test".IO.e.Bool')

On Mon, May 18, 2020 at 12:25 AM ToddAndMargo via perl6-users <
perl6-us...@perl.org> wrote:

> On 2020-05-17 21:19, ToddAndMargo via perl6-users wrote:
> > On 2020-05-17 20:28, Paul Procacci wrote:
> >> So tack a .Bool at the end.
> >> You are coercing a bool to a bool by doing so and hopefully the
> >> optimizer is smart enough for people who like to be redundant.
> >>
> >> ;)
> >
> > Hi Paul,
> >
> > Especially when I can never remember when IO.someletter
> > will return a full True or False Boolean and when it
> > will return a True or a useless text message.
> >
> > The optimizer should have a lot of fun with me!  Works
> > darned well too!
> >
> > -T
>
> Speaking of optimizer, it would be interesting to see
> if my coercing a half a Bool and a useless text message
> to a True of False when analyzed takes  more of less
> optimizing than giving it a straight Boolean to start with.
>
> But now I are getting at some really deep trivia
>


-- 
__

:(){ :|:& };:


Re: I need help with IO.e

2020-05-17 Thread ToddAndMargo via perl6-users

On 2020-05-17 21:19, ToddAndMargo via perl6-users wrote:

On 2020-05-17 20:28, Paul Procacci wrote:

So tack a .Bool at the end.
You are coercing a bool to a bool by doing so and hopefully the 
optimizer is smart enough for people who like to be redundant.


;)


Hi Paul,

Especially when I can never remember when IO.someletter
will return a full True or False Boolean and when it
will return a True or a useless text message.

The optimizer should have a lot of fun with me!  Works
darned well too!

-T


Speaking of optimizer, it would be interesting to see
if my coercing a half a Bool and a useless text message
to a True of False when analyzed takes  more of less
optimizing than giving it a straight Boolean to start with.

But now I are getting at some really deep trivia


Re: I need help with IO.e

2020-05-17 Thread ToddAndMargo via perl6-users

On 2020-05-17 20:28, Paul Procacci wrote:

So tack a .Bool at the end.
You are coercing a bool to a bool by doing so and hopefully the 
optimizer is smart enough for people who like to be redundant.


;)


Hi Paul,

Especially when I can never remember when IO.someletter
will return a full True or False Boolean and when it
will return a True or a useless text message.

The optimizer should have a lot of fun with me!  Works
darned well too!

-T


Re: I need help with IO.e

2020-05-17 Thread Paul Procacci
So tack a .Bool at the end.
You are coercing a bool to a bool by doing so and hopefully the optimizer
is smart enough for people who like to be redundant.

;)

On Sun, May 17, 2020 at 6:10 PM ToddAndMargo via perl6-users <
perl6-us...@perl.org> wrote:

> On 2020-05-17 14:43, ToddAndMargo via perl6-users wrote:
> > Although
> >
> > "say 'yes' if 'h:/'.IO.d"
> >
> > is obscure to me and
> >
> > "say 'h:/'.IO.d.Bool"
> >
> > is very easy for me to understand.
>
>
> Hi Peter,
>
> I think it would help if you knew how my
> mind worked.
>
> `if` to me is a Boolean function.  If this
> expressions is true, do this, if not, do
> something else.
>
> This is what happens to me when I see expressions
> like
>
>  "say 'yes' if 'h:/'.IO.d"
>
> if the expression (h:/.IO.d) is true, then
> say the result of the expression test, not the
> result from the expression.  I have to figure
> out what the results from the expression are
> and why it is passing or failing the test.
>
> Two steps in my mind.  Not that I can't figure
> things like this out, I just don't like the effort,
> when it can be avoided.  The way I look at it, the
> time it takes me to write five extra letters (.Bool)
> will save me ten times that amount of time trying to
> figure out what I did 5 days or 5 years from now.
> Dr. Demming (Quality circles, Kaisen, etc.) makes
> a very strong point of this
>
> And `if` can actually be very helpful at times:
> if  $x ~~ s/ "abc" /def/ {...;}
> will tell you if the regex actually found "abc".
> This I adore because I know is a test.  Not
> in the least bit obscure.
>
> .d is suppose to return a Boolen, but does not.
> Some functions will convert the junk for you on
> the fly.  Raku is very friendly this way.  Five extra
> letters and I do not have to wonder who does what
> to whom.
>
> Yes, I am a bit weird.
>
> Thank you for all the wonderful explanations!  Very
> much appreciated.
>
> -T
>


-- 
__

:(){ :|:& };:


Re: I need help with IO.e

2020-05-17 Thread ToddAndMargo via perl6-users

On 2020-05-17 14:43, ToddAndMargo via perl6-users wrote:

Although

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

is obscure to me and

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

is very easy for me to understand.



Hi Peter,

I think it would help if you knew how my
mind worked.

`if` to me is a Boolean function.  If this
expressions is true, do this, if not, do
something else.

This is what happens to me when I see expressions
like

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

if the expression (h:/.IO.d) is true, then
say the result of the expression test, not the
result from the expression.  I have to figure
out what the results from the expression are
and why it is passing or failing the test.

Two steps in my mind.  Not that I can't figure
things like this out, I just don't like the effort,
when it can be avoided.  The way I look at it, the
time it takes me to write five extra letters (.Bool)
will save me ten times that amount of time trying to
figure out what I did 5 days or 5 years from now.
Dr. Demming (Quality circles, Kaisen, etc.) makes
a very strong point of this

And `if` can actually be very helpful at times:
   if  $x ~~ s/ "abc" /def/ {...;}
will tell you if the regex actually found "abc".
This I adore because I know is a test.  Not
in the least bit obscure.

.d is suppose to return a Boolen, but does not.
Some functions will convert the junk for you on
the fly.  Raku is very friendly this way.  Five extra
letters and I do not have to wonder who does what
to whom.

Yes, I am a bit weird.

Thank you for all the wonderful explanations!  Very
much appreciated.

-T


Re: I need help with IO.e

2020-05-17 Thread ToddAndMargo via perl6-users

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".IO.d.Bool  {
say "Creating %Options";
mkdir( %Options", 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. 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?


Re: I need help with IO.e

2020-05-17 Thread Peter Pentchev
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".IO.d.Bool  {
> > >say "Creating %Options";
> > >mkdir( %Options", 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. 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


signature.asc
Description: PGP signature


Re: I need help with IO.e

2020-05-17 Thread ToddAndMargo via perl6-users

On 2020-05-17 03:50, Elizabeth Mattijsen wrote:

[11:50:21]you don.t need the .Bool, .e already returns a Bool
[11:53:07]  sometimes IO.someletter returns True of Fail, not 
False.  Tacking .Bool on the end, means I don't have to remember which ones
[11:57:23]  True or Fail.  Typo
[11:58:21]A Failure is always false
[12:03:02]  A Fail is a lot more than that.  here is an example:  >raku -e 
"say Q[z:\].IO.d;"Failed to find 'Z:\' while trying to do '.d'  in block  at -e 
line 1
[12:04:16]  I use .bool at the end because I only want back a yes 
or no answer.  And I certainly don't want it to crash.  Always using .Bool keeps me 
out of trouble
[12:19:21]say "directory foo exists" if "foo".IO.d
[12:19:49]you don't have to worry about Failure then, which is 
the point of Failure to begin with
[12:23:33]  That is `if` converting the `X::IO::DoesNotExist` 
clutter into False for me.  I never know when that will happen and when it won't, so 
tacking .Bool at the end keeps me out of trouble.  I am not a purest here.  I do not 
mind seeing .Bool at the end.   It also tells me I will be seeing a Boolean.
[12:28:42]  bye bye for now. Thank you all for the tips!


Yup,  That is it.  Keep me from having to pull my hair out.


Re: I need help with IO.e

2020-05-17 Thread ToddAndMargo via perl6-users

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".IO.d.Bool  {
   say "Creating %Options";
   mkdir( %Options", 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. 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..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. 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


Re: How to find if a drive letter exists?

2020-05-17 Thread ToddAndMargo via perl6-users

On 2020-05-17 07:47, Brad Gilbert wrote:

Why do you have `.Bool` on all of the `.e` tests?


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. will return
a True or Fail or which function (`if` does) will
convert X::IO::DoesNotExist to a False for me.

Plus it makes it more readable for me.
   [something].IO..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. 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


Re: Matching subpatterns in any order, conjunctions, negated matches

2020-05-17 Thread Joseph Brenner
Peter Pentchev wrote:

> Actually, there is, and I conveniently did not mention it :) It's the
> case when the patterns may overlap: if you do the ' 'the' and 'entrance', you might match 'thentrance', which, depending on
> your use case, might not be ideal.

That's a good point, but it's true that that it's a matter of
your actual use case.   Using your technique to look for words
with a "qu", "ue" and a "en":

  my regex qu_th_not_ea_3b_pos
 { ^};

That matches an overlapping case like "queen", but that strikes me as
okay-- it might surprise someone, but it'd be a pretty minor surprise
(unless maybe if you were playing scrabble and trying to get rid
of all your letters...).

Also, things like my multipattern triple-grep approach would show
the same behavior.

The kind of edge case I was talking about was with things like my
conjunction approach, using a negated after to get a negative match:

  my regex qu_th_not_ea
{ ^ [ .* qu .* & .* th .* &  [ . ]* ] $ };

That works pretty well, but it would pass a string like "quothea"
in error, because that after is making sure that none of the
characters in the string follow a "ea", and when the "ea" is at
the end then there is nothing that follows.   Your idiom working
off of ^ is better, because every string has a beginning...

And of course, if you were matching for words in multiword text
then you'd just use that word boundary, so that's no problem.

(I was also worrying vaugely about some other things that don't
pan out, like what if there was an additional "qu" in front of
what you were trying to match and there was no way to subdivide
by lines or words or something-- but what could that possibly
mean?  In that case the "qu" is just part of the string and fair
game to match against, so...)



On 5/16/20, Peter Pentchev  wrote:
> On Sat, May 16, 2020 at 05:53:04PM -0700, Joseph Brenner wrote:
>>  Peter Pentchev  wrote:
>> > On Fri, May 15, 2020 at 07:32:50PM -0700, Joseph Brenner wrote:
>> >> Regex engines by their nature care a lot about order, but I
>> >> occasionally want to relax that to match for multiple
>> >> multicharacter subpatterns where the order of them doesn't
>> >> matter.
>> >>
>> >> Frequently the simplest thing to do is just to just do multiple
>> >> matches.   Let's say you're looking for words that have a "qu" a
>> >> "th" and also, say an "ea".  This works:
>> >>
>> >>   my $DICT  = "/usr/share/dict/american-english";
>> >>   my @hits = $DICT.IO.open( :r
>> >> ).lines.grep({/qu/}).grep({/th/}).grep({/ea/});
>> >>   say @hits;
>> >>   # [bequeath bequeathed bequeathing bequeaths earthquake earthquake's
>> >> earthquakes]
>> >
>> > Would something like this work for you?
>> >
>> >   /^/
>> >
>> >> Where things get interesting is when you want a negated match of
>> >> one of the subpatterns.  One of the things I like about the first
>> >> approach using multiple chained greps is that it's easy to do a
>> >> reverse match.  What if you want words with "qu" and "th" but
>> >> want to *skip* ones with an "ea"?
>> >>
>> >>   my @hits = $DICT.IO.open( :r
>> >> ).lines.grep({/qu/}).grep({/th/}).grep({!/ea/});
>> >>   # [Asquith discotheque discotheque's discotheques quoth]
>> >
>> > Maybe something like this? (note the "!" instead of "?")
>> >
>> >   /^/
>> >
>>
>> Yes, both of those work, and arguably they're a little cleaner
>> looking than my conjunction approach-- though it's not necessarily any
>> easier to think about.  It looks like a pattern that's matching
>> for three things in order, but the zero-widthness of the "before"
>> let's them all work on top of each other.
>>
>> I keep thinking there's an edge case in these before/after tricks that
>> might matter if we weren't matching the one-word-per-line format of
>> the unix dictionaries, but I need to think about that a little more...
>
> Actually, there is, and I conveniently did not mention it :) It's the
> case when the patterns may overlap: if you do the ' 'the' and 'entrance', you might match 'thentrance', which, depending on
> your use case, might not be ideal.
>
> I've thought a little about another method: splitting the string using
> one of the patterns as a separator, then splitting each of the resulting
> substrings using the next one and so on until you get to the last one,
> where you check whether any of the ministrings contains it, but it would
> have to be done carefully, it would have to somehow be done with
> a special split-like function that would find all of the occurrences of
> the pattern and return tuples "before" and "after" to avoid another kind
> of problems with overlaps: if you split "the father" on all of
> the ocurrences of "the" at the same time, you *will* miss "father" :)
> So you need a special sort of split function that will split
> "the father" first as ("", " father"), then as ("the fa", "r"), and return
> all of the non-empty results (" father", "the fa", "r")... I'm not sure
> this will be very efficient. OK, so as a 

Re: How to find if a drive letter exists?

2020-05-17 Thread Brad Gilbert
Why do you have `.Bool` on all of the `.e` tests?

A file or directory either exists or it doesn't. So `.e` always returns a
Bool.
So there is zero reason to try to coerce it to a Bool.

You can look at the return value of `.e`.

> say '.'.IO.can('e').head.signature
(IO::Path:D: *%_ --> Bool)

If you don't trust that, you can look at the source
https://github.com/rakudo/rakudo/blob/fc88b9c2d2e71ab7fa492a53f0f90847c945bfcd/src/core.c/IO/Path.pm6#L738-L740

method e(IO::Path:D: --> Bool:D) {
nqp::hllbool(Rakudo::Internals.FILETEST-E(self.absolute)) }

It says it returns a Bool. It even uses `nqp::hllbool` which coerces the
value to `Bool`.

One of the design ethos of Raku is to reduce busy-work.
That is work that you don't really need to do.

I really can't understand why you insist on doing that busy-work anyway.


On Sun, May 17, 2020 at 4:56 AM ToddAndMargo via perl6-users <
perl6-us...@perl.org> wrote:

> On 2020-05-17 00:52, ToddAndMargo via perl6-users wrote:
> > Hi All,
> >
> > Windows 7 & 10
> >
> > I want to know if a drive letter exists:
> >
> >
> > K:\Windows\NtUtil>df -kPT
> > Filesystem   Type  1024-blocks  Used Available Capacity
> > Mounted on
> > C:/Program Files/Git ntfs 40585620  15044068  25541552  38% /
> > D:   udf   5294394   5294394 0 100% /d
> > E:   ntfs 8188  3908  4280  48% /e
> > F:   ntfs10236  3908  6328  39% /f
> > J:   smbfs   951048868 514547660 436501208  55% /j
> > K:   smbfs   951048868 514547680 436501188  55% /k
> > L:   smbfs   951048868 514547700 436501168  55% /l
> >
> > K:\Windows\NtUtil>dir e:
> >   Volume in drive E is DRIVERS
> >   Volume Serial Number is 44EB-5181
> >
> >   Directory of E:\
> >
> > File Not Found
> >
> > This exists:
> > K:\Windows\NtUtil>raku -e "say 'H:'.IO.d.Bool;"
> > True
> >
> > This does not:
> > K:\Windows\NtUtil>raku -e "say 'Z:'.IO.d.Bool;"
> > True
> >
> >
> > Many thanks,
> > -T
> >
> >
>
> Follow up:
>
> Hi All,
>
> Prince213 on the chat line helped me figure this out.
>
> This is from my IO keeper:
>
> Drive (letter) exists (Windows only):
> use `IO.e.Bool`
>
> # forward slashes
> >raku -e "say 'X:/'.IO.e.Bool;"
> False
>
> >raku -e "say 'D:/'.IO.e.Bool;"
> True
>
> >raku -e "say 'd:/'.IO.e.Bool;"
> True
>
> >raku -e "say 'Z:/'.IO.e.Bool;"
> False
>
> # back slashes
> >raku -e "say 'd:\\'.IO.e.Bool;"
> True
>
> >raku -e "say Q[d:\].IO.e.Bool;"
> True
>
> >raku -e "say Q[z:\].IO.e.Bool;"
> False
>
>
> -T
>


Re: I need help with IO.e

2020-05-17 Thread Elizabeth Mattijsen
[11:50:21]  you don.t need the .Bool, .e already returns a Bool
[11:53:07]sometimes IO.someletter returns True of Fail, 
not False.  Tacking .Bool on the end, means I don't have to remember which ones
[11:57:23]True or Fail.  Typo
[11:58:21]  A Failure is always false
[12:03:02]A Fail is a lot more than that.  here is an 
example:  >raku -e "say Q[z:\].IO.d;"Failed to find 'Z:\' while trying to do 
'.d'  in block  at -e line 1
[12:04:16]I use .bool at the end because I only want back 
a yes or no answer.  And I certainly don't want it to crash.  Always using 
.Bool keeps me out of trouble
[12:19:21]  say "directory foo exists" if "foo".IO.d
[12:19:49]  you don't have to worry about Failure then, which is 
the point of Failure to begin with
[12:23:33]That is `if` converting the 
`X::IO::DoesNotExist` clutter into False for me.  I never know when that will 
happen and when it won't, so tacking .Bool at the end keeps me out of trouble.  
I am not a purest here.  I do not mind seeing .Bool at the end.   It also tells 
me I will be seeing a Boolean.
[12:28:42]bye bye for now. Thank you all for the tips!

> On 17 May 2020, at 12: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".IO.d.Bool  {
>>  say "Creating %Options";
>>  mkdir( %Options", 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
> 
> -- 
> 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


Re: I need help with IO.e

2020-05-17 Thread Peter Pentchev
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".IO.d.Bool  {
>   say "Creating %Options";
>   mkdir( %Options", 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

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


signature.asc
Description: PGP signature


Re: I need help with IO.e

2020-05-17 Thread ToddAndMargo via perl6-users

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".IO.d.Bool  {
  say "Creating %Options";
  mkdir( %Options", 0o777 );
   }

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

Thank you for your patience!

-T


Re: How to find if a drive letter exists?

2020-05-17 Thread ToddAndMargo via perl6-users

On 2020-05-17 00:52, ToddAndMargo via perl6-users wrote:

Hi All,

Windows 7 & 10

I want to know if a drive letter exists:


K:\Windows\NtUtil>df -kPT
Filesystem   Type  1024-blocks  Used Available Capacity 
Mounted on

C:/Program Files/Git ntfs 40585620  15044068  25541552  38% /
D:   udf   5294394   5294394 0 100% /d
E:   ntfs 8188  3908  4280  48% /e
F:   ntfs    10236  3908  6328  39% /f
J:   smbfs   951048868 514547660 436501208  55% /j
K:   smbfs   951048868 514547680 436501188  55% /k
L:   smbfs   951048868 514547700 436501168  55% /l

K:\Windows\NtUtil>dir e:
  Volume in drive E is DRIVERS
  Volume Serial Number is 44EB-5181

  Directory of E:\

File Not Found

This exists:
K:\Windows\NtUtil>raku -e "say 'H:'.IO.d.Bool;"
True

This does not:
K:\Windows\NtUtil>raku -e "say 'Z:'.IO.d.Bool;"
True


Many thanks,
-T




Follow up:

Hi All,

Prince213 on the chat line helped me figure this out.

This is from my IO keeper:

Drive (letter) exists (Windows only):
   use `IO.e.Bool`

   # forward slashes
   >raku -e "say 'X:/'.IO.e.Bool;"
   False

   >raku -e "say 'D:/'.IO.e.Bool;"
   True

   >raku -e "say 'd:/'.IO.e.Bool;"
   True

   >raku -e "say 'Z:/'.IO.e.Bool;"
   False

   # back slashes
   >raku -e "say 'd:\\'.IO.e.Bool;"
   True

   >raku -e "say Q[d:\].IO.e.Bool;"
   True

   >raku -e "say Q[z:\].IO.e.Bool;"
   False


-T


Re: I need help with IO.e

2020-05-17 Thread Peter Pentchev
On Sun, May 17, 2020 at 02:18:30AM -0700, ToddAndMargo via perl6-users wrote:
> On 2020-05-17 01:23, Peter Pentchev wrote:
> > On Sat, May 16, 2020 at 06:57:53PM -0700, ToddAndMargo via perl6-users 
> > wrote:
> > > 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.
> > 
> > So use .d in a boolean context (if, while, etc).
> > 
> > > 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).
> > 
> > That's *exactly* the opposite of what I thought I explained, but
> > you do you, I guess.
> > 
> > > Now I have to look up f.
> > > 
> > > Found it.  If you use the Bool, it returns a False
> > > for directories.   Cool.
> > 
> > It is documented to return true for files, so yes, it would return false
> > for directories.
> > 
> > > 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?
> > 
> > The definition does not list all the exceptions that a method or
> > function can throw, and for good reason - people have learned their
> > lessons from the Java world, where this, while it did have some very
> > limited use, very quickly drove programmers to just say "... raises
> > Exception" on everything, making it essentially useless.
> > 
> > OK, in more words for people who may not have any Java programming
> > experience: they tried to make programmers list any exceptions that may
> > be raised from their methods, with the expectation that programmers
> > would check the documentation for any exceptions raised by the functions
> > and methods that they call, decide which ones they want to handle and
> > which ones they want to propagate upwards, and then list the ones that
> > they propatage and the ones that they raise themselves. However, in some
> > cases, like when using several library functions from 

Re: I need help with IO.e

2020-05-17 Thread ToddAndMargo via perl6-users

On 2020-05-17 01:23, Peter Pentchev wrote:

On Sat, May 16, 2020 at 06:57:53PM -0700, ToddAndMargo via perl6-users wrote:

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.


So use .d in a boolean context (if, while, etc).


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


That's *exactly* the opposite of what I thought I explained, but
you do you, I guess.


Now I have to look up f.

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


It is documented to return true for files, so yes, it would return false
for directories.


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?


The definition does not list all the exceptions that a method or
function can throw, and for good reason - people have learned their
lessons from the Java world, where this, while it did have some very
limited use, very quickly drove programmers to just say "... raises
Exception" on everything, making it essentially useless.

OK, in more words for people who may not have any Java programming
experience: they tried to make programmers list any exceptions that may
be raised from their methods, with the expectation that programmers
would check the documentation for any exceptions raised by the functions
and methods that they call, decide which ones they want to handle and
which ones they want to propagate upwards, and then list the ones that
they propatage and the ones that they raise themselves. However, in some
cases, like when using several library functions from several
third-party libraries, it turned out that the programmer said "oh come
on, I can't keep up with all the changes they make to their libraries,
they keep adding more and more exceptions; nah, I'll just say that my
method can throw *any* kind of exception under the Sun and be done with
it!".

Now Rust and Go are trying almost the same thing, but in a better way,
although I've seen the "propagate it, I don't care what it is!"
mentality  in both Rust ("just do .unwrap(), who cares") and Go ("is the
returned value an error? if so, return/propagate it, I don't care!")
programs (not all of them, of course).

I think that proper documentation is a better way than forcing
declarations of the errors returned, and that's what Raku does.
It does not list the exception in the method, it talks about it in
the text description.  Of course, if the Raku development team has more
insights in why they 

Re: I need help with IO.e

2020-05-17 Thread Peter Pentchev
On Sat, May 16, 2020 at 06:57:53PM -0700, ToddAndMargo via perl6-users wrote:
> 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.

So use .d in a boolean context (if, while, etc).

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

That's *exactly* the opposite of what I thought I explained, but
you do you, I guess.

> Now I have to look up f.
> 
> Found it.  If you use the Bool, it returns a False
> for directories.   Cool.

It is documented to return true for files, so yes, it would return false
for directories.

> 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?

The definition does not list all the exceptions that a method or
function can throw, and for good reason - people have learned their
lessons from the Java world, where this, while it did have some very
limited use, very quickly drove programmers to just say "... raises
Exception" on everything, making it essentially useless.

OK, in more words for people who may not have any Java programming
experience: they tried to make programmers list any exceptions that may
be raised from their methods, with the expectation that programmers
would check the documentation for any exceptions raised by the functions
and methods that they call, decide which ones they want to handle and
which ones they want to propagate upwards, and then list the ones that
they propatage and the ones that they raise themselves. However, in some
cases, like when using several library functions from several
third-party libraries, it turned out that the programmer said "oh come
on, I can't keep up with all the changes they make to their libraries,
they keep adding more and more exceptions; nah, I'll just say that my
method can throw *any* kind of exception under the Sun and be done with
it!".

Now Rust and Go are trying almost the same thing, but in a better way,
although I've seen the "propagate it, I don't care what it is!"
mentality  in both Rust ("just do .unwrap(), who cares") and Go ("is the
returned value an error? if so, return/propagate it, I don't care!")
programs (not all of them, of course).

I 

How to find if a drive letter exists?

2020-05-17 Thread ToddAndMargo via perl6-users

Hi All,

Windows 7 & 10

I want to know if a drive letter exists:


K:\Windows\NtUtil>df -kPT
Filesystem   Type  1024-blocks  Used Available Capacity 
Mounted on

C:/Program Files/Git ntfs 40585620  15044068  25541552  38% /
D:   udf   5294394   5294394 0 100% /d
E:   ntfs 8188  3908  4280  48% /e
F:   ntfs10236  3908  6328  39% /f
J:   smbfs   951048868 514547660 436501208  55% /j
K:   smbfs   951048868 514547680 436501188  55% /k
L:   smbfs   951048868 514547700 436501168  55% /l

K:\Windows\NtUtil>dir e:
 Volume in drive E is DRIVERS
 Volume Serial Number is 44EB-5181

 Directory of E:\

File Not Found

This exists:
K:\Windows\NtUtil>raku -e "say 'H:'.IO.d.Bool;"
True

This does not:
K:\Windows\NtUtil>raku -e "say 'Z:'.IO.d.Bool;"
True


Many thanks,
-T


--
~~
Computers are like air conditioners.
They malfunction when you open windows
~~