Re: -c question

2024-02-06 Thread ToddAndMargo via perl6-users

On 2/6/24 09:03, Bruce Gray wrote:




On Feb 6, 2024, at 10:52, ToddAndMargo via perl6-users  
wrote:


On 6 Feb 2024, at 00:39, ToddAndMargo via perl6-users  
wrote:

Hi All,

Is there a way to syntax a module?  Sort of like the "-c"
option on main programs?

Many thanks,
-T


On 2/6/24 01:34, Elizabeth Mattijsen wrote:

$ raku -c foo.rakumod
Syntax OK



$ raku -c WinMessageBox.pm6
===SORRY!=== Error while compiling /home/CDs/Windows/NtUtil/WinMessageBox.pm6
Could not find NativeConvert in:
/home/tony/.raku
/opt/rakudo-pkg/share/perl6/site
/opt/rakudo-pkg/share/perl6/vendor
/opt/rakudo-pkg/share/perl6/core
CompUnit::Repository::AbsolutePath<4639587332824>
CompUnit::Repository::NQP<4639586267208>
CompUnit::Repository::Perl5<4639586267248>
at /home/CDs/Windows/NtUtil/WinMessageBox.pm6:50

$ which NativeConvert.pm6
./NativeConvert.pm6
and three other pm.6's WinMessageBox imports.

I can only compile check my modules if I
import them to a program and -c the program.

For example, the following program uses
the above module:
$ raku -c CobianWrapper.pl6
Syntax OK

I just want to do a syntax check on my modules
at time without the program.

:'(


The wrapper program can be a `-e` one-liner, like:
 raku -c -e 'use NativeCall;'
 Syntax OK
 
Does this work for you?

 raku -c -e 'use WinMessageBox;'
 


Rats!

$ raku -c -e 'use WinMessageBox;'
===SORRY!=== Error while compiling -e
Could not find WinMessageBox in:
/home/tony/.raku
/opt/rakudo-pkg/share/perl6/site
/opt/rakudo-pkg/share/perl6/vendor
/opt/rakudo-pkg/share/perl6/core
CompUnit::Repository::AbsolutePath<2965876076768>
CompUnit::Repository::NQP<2965910068576>
CompUnit::Repository::Perl5<2965910068616>
at -e:1

$ raku -I./ -c WinMessageBox.pm6
Syntax OK


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



Re: -c question

2024-02-06 Thread ToddAndMargo via perl6-users




On 6 Feb 2024, at 17:52, ToddAndMargo via perl6-users  
wrote:


On 6 Feb 2024, at 00:39, ToddAndMargo via perl6-users  
wrote:

Hi All,

Is there a way to syntax a module?  Sort of like the "-c"
option on main programs?

Many thanks,
-T


On 2/6/24 01:34, Elizabeth Mattijsen wrote:

$ raku -c foo.rakumod
Syntax OK



$ raku -c WinMessageBox.pm6
===SORRY!=== Error while compiling /home/CDs/Windows/NtUtil/WinMessageBox.pm6
Could not find NativeConvert in:
/home/tony/.raku
/opt/rakudo-pkg/share/perl6/site
/opt/rakudo-pkg/share/perl6/vendor
/opt/rakudo-pkg/share/perl6/core
CompUnit::Repository::AbsolutePath<4639587332824>
CompUnit::Repository::NQP<4639586267208>
CompUnit::Repository::Perl5<4639586267248>
at /home/CDs/Windows/NtUtil/WinMessageBox.pm6:50

$ which NativeConvert.pm6
./NativeConvert.pm6
and three other pm.6's WinMessageBox imports.

I can only compile check my modules if I
import them to a program and -c the program.

For example, the following program uses
the above module:
$ raku -c CobianWrapper.pl6
Syntax OK

I just want to do a syntax check on my modules
at time without the program.

:'(


On 2/6/24 08:57, Elizabeth Mattijsen wrote:
> Do you have some "use lib 'foo'" setting in your program?
>
> If so, use that on the command-line, e.g.:
>
>  $ raku -Ifoo -c bar.rakumod
>

Indeed I do.  Will the above command check those
modules too, or just verify that they are there?





Re: -c question

2024-02-06 Thread Bruce Gray



> On Feb 6, 2024, at 10:52, ToddAndMargo via perl6-users  
> wrote:
> 
>>> On 6 Feb 2024, at 00:39, ToddAndMargo via perl6-users 
>>>  wrote:
>>> 
>>> Hi All,
>>> 
>>> Is there a way to syntax a module?  Sort of like the "-c"
>>> option on main programs?
>>> 
>>> Many thanks,
>>> -T
> 
> On 2/6/24 01:34, Elizabeth Mattijsen wrote:
> > $ raku -c foo.rakumod
> > Syntax OK
> >
> 
> $ raku -c WinMessageBox.pm6
> ===SORRY!=== Error while compiling /home/CDs/Windows/NtUtil/WinMessageBox.pm6
> Could not find NativeConvert in:
>/home/tony/.raku
>/opt/rakudo-pkg/share/perl6/site
>/opt/rakudo-pkg/share/perl6/vendor
>/opt/rakudo-pkg/share/perl6/core
>CompUnit::Repository::AbsolutePath<4639587332824>
>CompUnit::Repository::NQP<4639586267208>
>CompUnit::Repository::Perl5<4639586267248>
> at /home/CDs/Windows/NtUtil/WinMessageBox.pm6:50
> 
> $ which NativeConvert.pm6
> ./NativeConvert.pm6
> and three other pm.6's WinMessageBox imports.
> 
> I can only compile check my modules if I
> import them to a program and -c the program.
> 
> For example, the following program uses
> the above module:
>$ raku -c CobianWrapper.pl6
>Syntax OK
> 
> I just want to do a syntax check on my modules
> at time without the program.
> 
> :'(

The wrapper program can be a `-e` one-liner, like:
raku -c -e 'use NativeCall;'
Syntax OK

Does this work for you?
raku -c -e 'use WinMessageBox;'

-- 
Hope this helps,
Bruce Gray (Util of PerlMonks)



Re: -c question

2024-02-06 Thread Elizabeth Mattijsen
Do you have some "use lib 'foo'" setting in your program?

If so, use that on the command-line, e.g.:

$ raku -Ifoo -c bar.rakumod

> On 6 Feb 2024, at 17:52, ToddAndMargo via perl6-users  
> wrote:
> 
>>> On 6 Feb 2024, at 00:39, ToddAndMargo via perl6-users 
>>>  wrote:
>>> 
>>> Hi All,
>>> 
>>> Is there a way to syntax a module?  Sort of like the "-c"
>>> option on main programs?
>>> 
>>> Many thanks,
>>> -T
> 
> On 2/6/24 01:34, Elizabeth Mattijsen wrote:
> > $ raku -c foo.rakumod
> > Syntax OK
> >
> 
> $ raku -c WinMessageBox.pm6
> ===SORRY!=== Error while compiling /home/CDs/Windows/NtUtil/WinMessageBox.pm6
> Could not find NativeConvert in:
>/home/tony/.raku
>/opt/rakudo-pkg/share/perl6/site
>/opt/rakudo-pkg/share/perl6/vendor
>/opt/rakudo-pkg/share/perl6/core
>CompUnit::Repository::AbsolutePath<4639587332824>
>CompUnit::Repository::NQP<4639586267208>
>CompUnit::Repository::Perl5<4639586267248>
> at /home/CDs/Windows/NtUtil/WinMessageBox.pm6:50
> 
> $ which NativeConvert.pm6
> ./NativeConvert.pm6
> and three other pm.6's WinMessageBox imports.
> 
> I can only compile check my modules if I
> import them to a program and -c the program.
> 
> For example, the following program uses
> the above module:
>$ raku -c CobianWrapper.pl6
>Syntax OK
> 
> I just want to do a syntax check on my modules
> at time without the program.
> 
> :'(



Re: -c question

2024-02-06 Thread ToddAndMargo via perl6-users

On 6 Feb 2024, at 00:39, ToddAndMargo via perl6-users  
wrote:

Hi All,

Is there a way to syntax a module?  Sort of like the "-c"
option on main programs?

Many thanks,
-T


On 2/6/24 01:34, Elizabeth Mattijsen wrote:
> $ raku -c foo.rakumod
> Syntax OK
>

$ raku -c WinMessageBox.pm6
===SORRY!=== Error while compiling 
/home/CDs/Windows/NtUtil/WinMessageBox.pm6

Could not find NativeConvert in:
/home/tony/.raku
/opt/rakudo-pkg/share/perl6/site
/opt/rakudo-pkg/share/perl6/vendor
/opt/rakudo-pkg/share/perl6/core
CompUnit::Repository::AbsolutePath<4639587332824>
CompUnit::Repository::NQP<4639586267208>
CompUnit::Repository::Perl5<4639586267248>
at /home/CDs/Windows/NtUtil/WinMessageBox.pm6:50

$ which NativeConvert.pm6
./NativeConvert.pm6
and three other pm.6's WinMessageBox imports.

I can only compile check my modules if I
import them to a program and -c the program.

For example, the following program uses
the above module:
$ raku -c CobianWrapper.pl6
Syntax OK

I just want to do a syntax check on my modules
at time without the program.

:'(


Re: -c question

2024-02-06 Thread Elizabeth Mattijsen
$ raku -c foo.rakumod
Syntax OK

> On 6 Feb 2024, at 00:39, ToddAndMargo via perl6-users  
> wrote:
> 
> Hi All,
> 
> Is there a way to syntax a module?  Sort of like the "-c"
> option on main programs?
> 
> Many thanks,
> -T
> 
> 
> 
> -- 
> ~~
> Computers are like air conditioners.
> They malfunction when you open windows
> ~~



Re: .contains question

2023-12-11 Thread ToddAndMargo via perl6-users

On 12/11/23 14:47, Andy Bach wrote:

 I have found that when using `say` for debugging, it has been known to print 
out the
previous value of a variable and not the current value.  `print` does not do 
this.


That would certainly be a surprise to me. I'd think I was 
misunderstanding my program, rather than a bug in say.


Hi Andy,

1) I can not duplicate the issue in a small program

2) I did a `say ($x)` on top of a `print "$x\n"`
and got two different answers.  The `say` was the
previous value of the variable.  (It about drove
me crazy trying to figure out what was going on.)

I have had this happen several times in my large programs.
This makes me think it is an issue in the code optimizer.
And it may very well be fixed now.

In my Modula 2 days, I had to turn off the code optimizer
as these issues were crazy making.  So I did recognize the
problem.  So far, the only instance of  optimizer
problems I have found in Raku has been with `say`.  And
it is easily worked around.  Raku itself is very well done
and is fun to program in.

If you have read any of my code, you know I have written
print modules to write out in color and to write out to
the STDERR: black, blue, green, red.  I have been thinking
of writing a `println`, but it would not be all that useful
as I am always up to something at the end of the line.

-T


Re: .contains question

2023-12-11 Thread Andy Bach
>  I have found that when using `say` for debugging, it has been known to print 
> out the
> previous value of a variable and not the current value.  `print` does not do 
> this.

That would certainly be a surprise to me. I'd think I was misunderstanding my 
program, rather than a bug in say.

From: ToddAndMargo via perl6-users 
Sent: Monday, December 11, 2023 3:24 PM
To: perl6-us...@perl.org 
Subject: Re: .contains question

CAUTION - EXTERNAL:


> "so" will collapse the junction into a Bool.
> "say" will append a \n for you, so you don't have to.
>
>> On 11 Dec 2023, at 01:52, ToddAndMargo via perl6-users 
>>  wrote:
>>
>>>> On 10 Dec 2023, at 21:36, ToddAndMargo via perl6-users 
>>>>  wrote:
>>>>
>>>> Hi All,
>>>>
>>>> my Str $x="abc3defg"; if $x.contains( "a" || "b" || "3" )  { print 
>>>> "True\n"; } else { print "False\n" };
>>>> True
>>>>
>>>> Is there a way to tell .contains that you want to know
>>>> if any of a sequence characters is in a string other that
>>>> repeating || over and over.  Any [a..z] or [0..9] option?
>>>>
>>>> Many thanks,
>>>> -T
>>
>> On 12/10/23 15:24, Elizabeth Mattijsen wrote:
>>> my @letters = ;
>>> if $x.contains(any @letters) {
>>
>>
>> Hi Elizabeth,
>>
>> Very interesting.  Problem: I was looking for one answer, not many
>>
>>> my $x="abc45def";my @y=; print 
>>> $x.contains(any @y) ~ "\n";
>> True
>> True
>> True
>> True
>> True
>> True
>> False
>> False
>> False
>> False
>> False
>> False
>> False
>> True
>> True

On 12/11/23 01:11, Elizabeth Mattijsen wrote:
 > my $x="abc45def";
 > my @y=; say so $x.contains(any @y);

Hi Elizabeth,

Awesome!  Thank you!

I usually stay away from `say` as in my longer programs, I have found
that when using `say` for debugging, it has been known to print out the
previous value of a variable and not the current value.  `print` does
not do this.  This is why you see me using `print` so often.  And
I can type, so the extra finger motions do not bother me.  Capitol
letter also do not for the same reason.

Some tests!

my $x="abc45def"; my @y=; say so
$x.contains(any @y);
True

my $x="abc45def"; my @y=; say so $x.contains(any @y);
False

my $x="abc45def"; my @y=; say so $x.contains(any @y);
True

my $x="abc45def"; my @y=; say so $x.contains(any @y);
False


Oh now I am really pushing it with these (note the `all` in the
second one)!


my $x="abc45def"; say so $x.contains(any );

my $x="abc45def"; say so $x.contains(all );
False

my $x="abc45def"; say so $x.contains(any );
True


-T




CAUTION - EXTERNAL EMAIL: This email originated outside the Judiciary. Exercise 
caution when opening attachments or clicking on links.



Re: .contains question

2023-12-11 Thread ToddAndMargo via perl6-users




"so" will collapse the junction into a Bool.
"say" will append a \n for you, so you don't have to.


On 11 Dec 2023, at 01:52, ToddAndMargo via perl6-users  
wrote:


On 10 Dec 2023, at 21:36, ToddAndMargo via perl6-users  
wrote:

Hi All,

my Str $x="abc3defg"; if $x.contains( "a" || "b" || "3" )  { print "True\n"; } else { 
print "False\n" };
True

Is there a way to tell .contains that you want to know
if any of a sequence characters is in a string other that
repeating || over and over.  Any [a..z] or [0..9] option?

Many thanks,
-T


On 12/10/23 15:24, Elizabeth Mattijsen wrote:

my @letters = ;
if $x.contains(any @letters) {



Hi Elizabeth,

Very interesting.  Problem: I was looking for one answer, not many


my $x="abc45def";my @y=; print $x.contains(any @y) ~ 
"\n";

True
True
True
True
True
True
False
False
False
False
False
False
False
True
True


On 12/11/23 01:11, Elizabeth Mattijsen wrote:
> my $x="abc45def";
> my @y=; say so $x.contains(any @y);

Hi Elizabeth,

Awesome!  Thank you!

I usually stay away from `say` as in my longer programs, I have found 
that when using `say` for debugging, it has been known to print out the 
previous value of a variable and not the current value.  `print` does 
not do this.  This is why you see me using `print` so often.  And
I can type, so the extra finger motions do not bother me.  Capitol 
letter also do not for the same reason.


Some tests!

my $x="abc45def"; my @y=; say so 
$x.contains(any @y);

True

my $x="abc45def"; my @y=; say so $x.contains(any @y);
False

my $x="abc45def"; my @y=; say so $x.contains(any @y);
True

my $x="abc45def"; my @y=; say so $x.contains(any @y);
False


Oh now I am really pushing it with these (note the `all` in the
second one)!


my $x="abc45def"; say so $x.contains(any );

my $x="abc45def"; say so $x.contains(all );
False

my $x="abc45def"; say so $x.contains(any );
True


-T






Re: .contains question

2023-12-11 Thread Elizabeth Mattijsen
my $x="abc45def";
my @y=; say so $x.contains(any @y);

"so" will collapse the junction into a Bool.
"say" will append a \n for you, so you don't have to.

> On 11 Dec 2023, at 01:52, ToddAndMargo via perl6-users  
> wrote:
> 
>>> On 10 Dec 2023, at 21:36, ToddAndMargo via perl6-users 
>>>  wrote:
>>> 
>>> Hi All,
>>> 
>>> my Str $x="abc3defg"; if $x.contains( "a" || "b" || "3" )  { print 
>>> "True\n"; } else { print "False\n" };
>>> True
>>> 
>>> Is there a way to tell .contains that you want to know
>>> if any of a sequence characters is in a string other that
>>> repeating || over and over.  Any [a..z] or [0..9] option?
>>> 
>>> Many thanks,
>>> -T
> 
> On 12/10/23 15:24, Elizabeth Mattijsen wrote:
> > my @letters = ;
> > if $x.contains(any @letters) {
> 
> 
> Hi Elizabeth,
> 
> Very interesting.  Problem: I was looking for one answer, not many
> 
> > my $x="abc45def";my @y=; print 
> > $x.contains(any @y) ~ "\n";
> True
> True
> True
> True
> True
> True
> False
> False
> False
> False
> False
> False
> False
> True
> True
> 
> 
> Many thanks,
> -T
> 
> -- 
> ~~
> Computers are like air conditioners.
> They malfunction when you open windows
> ~~
> 



Re: .contains question

2023-12-10 Thread ToddAndMargo via perl6-users

On 10 Dec 2023, at 21:36, ToddAndMargo via perl6-users  
wrote:

Hi All,

my Str $x="abc3defg"; if $x.contains( "a" || "b" || "3" )  { print "True\n"; } else { 
print "False\n" };
True

Is there a way to tell .contains that you want to know
if any of a sequence characters is in a string other that
repeating || over and over.  Any [a..z] or [0..9] option?

Many thanks,
-T




On 12/10/23 15:24, Elizabeth Mattijsen wrote:
> my @letters = ;
> if $x.contains(any @letters) {


Hi Elizabeth,

Very interesting.  Problem: I was looking for one answer, not many

> my $x="abc45def";my @y=; print 
$x.contains(any @y) ~ "\n";

True
True
True
True
True
True
False
False
False
False
False
False
False
True
True


Many thanks,
-T

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



Re: .contains question

2023-12-10 Thread Elizabeth Mattijsen
my @letters = ;
if $x.contains(any @letters) {
...


> On 10 Dec 2023, at 21:36, ToddAndMargo via perl6-users  
> wrote:
> 
> Hi All,
> 
> my Str $x="abc3defg"; if $x.contains( "a" || "b" || "3" )  { print "True\n"; 
> } else { print "False\n" };
> True
> 
> Is there a way to tell .contains that you want to know
> if any of a sequence characters is in a string other that
> repeating || over and over.  Any [a..z] or [0..9] option?
> 
> Many thanks,
> -T



Re: A question on AND

2023-07-01 Thread ToddAndMargo via perl6-users

> On 30/06/2023 06:06, ToddAndMargo via perl6-users wrote:
>> if @*ARGS.elems > 0  &&  "@*ARGS[0]".lc eq "debug"  {...}

On 6/30/23 02:40, Richard Hainsworth wrote:

I tried this and it worked without any problem.


And today is is working for me as well without
a problem. I must have had something else wrong
taht I did not recognize.  So false alarm.



Here's the whole program:

use v6.d;
say @*ARGS.raku;
if @*ARGS.elems > 0 && "@*ARGS[0]".lc eq "debug" {
 say 'got' }
and at the terminal:

$ raku todd-test.raku debug --debug=50
["debug", "--debug=50"]
got


FWIW
why are you quoting ARGS? The .lc coerces to string anyway.


It is a habit from programming in bash.  I did not even
realize I had done it.  And I dp prefer Raku's
way of doing it.


why are you using && and not 'and'


See Yary's response.


why are you not using a sub MAIN with an optional --debug
eg. sub MAIN( @args, Bool :$debug=False) {
#stuff
if $debug { ... }


Because it is less complicated for what I am doing.

Thank you for the help!

-T



Re: A question on AND

2023-06-30 Thread Andy Bach
my $answer = $choice_1 or $choice_2; # this is  wrong it turns into
(my $answer = $choice_1) # or $choice_2

> there $choice_2 is only evaluated if the $answer got assigned a false
value, and then it gets evaluated in void context, discarding its value.
> Try this in Raku - what does it say? Do you still prefer "or" over "||" ?
my $answer = 0 or 5;

Well, if I were ever to write code like that, I'd not use "or" but ... I
can't recall this coming up.  I was just commenting on Perl having the same
difference in usage of those operators.

On Fri, Jun 30, 2023 at 10:14 AM yary  wrote:

> @a = @b || @c;  # this is wrong
> @a = scalar(@b) || @c;  # really meant this
>
> "or" doesn't help with this either
>
> @a = @b or @c;  # this is wrong
> (@a = scalar(@b)) or @c;  # really meant this - @c never is
> assigned to @Helen Block 
>
> the low precedence and/or is was introduced in Perl 5 for this construction
>
> open my $fh '<', $input_filename or die "Could not open $input_filename:
> $!";
>
> At $work I see bugs where people are using "or" "and" in expressions, and
> the part after the expression never gets into the variable they meant it to.
>
> my $answer = $choice_1 or $choice_2; # this is  wrong it turns into
> (my $answer = $choice_1) # or $choice_2
>
> there $choice_2 is only evaluated if the $answer got assigned a false
> value, and then it gets evaluated in void context, discarding its value.
>
> Try this in Raku - what does it say? Do you still prefer "or" over "||" ?
>
> my $answer = 0 or 5;
>
> say $answer;
>
>
> -y
>
>
> On Fri, Jun 30, 2023 at 10:53 AM Andy Bach 
> wrote:
>
>> I  always took [1]
>>  As alternatives to "&&" and "||" when used for control flow, Perl
>> provides
>> the "and" and "or" operators (see below). The short-circuit behavior
>> is
>> identical. The precedence of "and" and "or" is much lower, however, so
>> that you can safely use them after a list operator without the need
>> for
>> parentheses
>>
>> to suggest that and and or are the better ones to use and && or || should
>> be used only if they're specifically needed.  Which has always been "never"
>> for me.
>>
>> a
>>
>> [1]
>> perldoc perlop
>>The "||", "//" and "&&" operators return the last value evaluated
>> (unlike
>> C's "||" and "&&", which return 0 or 1). Thus, a reasonably portable
>> way
>> to find out the home directory might be:
>>
>> $home =  $ENV{HOME}
>>   // $ENV{LOGDIR}
>>   // (getpwuid($<))[7]
>>   // die "You're homeless!\n";
>>
>> In particular, this means that you shouldn't use this for selecting
>> between two aggregates for assignment:
>>
>> @a = @b || @c;  # this is wrong
>> @a = scalar(@b) || @c;  # really meant this
>> @a = @b ? @b : @c;  # this works fine, though
>>
>> As alternatives to "&&" and "||" when used for control flow, Perl
>> provides
>> the "and" and "or" operators (see below). The short-circuit behavior
>> is
>> identical. The precedence of "and" and "or" is much lower, however, so
>> that you can safely use them after a list operator without the need
>> for
>> parentheses:
>>
>> unlink "alpha", "beta", "gamma"
>> or gripe(), next LINE;
>>
>> With the C-style operators that would have been written like this:
>>
>> unlink("alpha", "beta", "gamma")
>> || (gripe(), next LINE);
>>
>> It would be even more readable to write that this way:
>>
>> unless(unlink("alpha", "beta", "gamma")) {
>> gripe();
>> next LINE;
>> }
>>
>> Using "or" for assignment is unlikely to do what you want; see below.
>>
>> --
>> *From:* yary 
>> *Sent:* Friday, June 30, 2023 8:45 AM
>> *To:* Richard Hainsworth 
>> *Cc:* perl6-us...@perl.org 
>> *Subject:* Re: A question on AND
>>
>>
>> *CAUTION - EXTERNAL: *
>> Most of Rich

Re: A question on AND

2023-06-30 Thread yary
@a = @b || @c;  # this is wrong
@a = scalar(@b) || @c;  # really meant this

"or" doesn't help with this either

@a = @b or @c;  # this is wrong
(@a = scalar(@b)) or @c;  # really meant this - @c never is
assigned to @Helen Block 

the low precedence and/or is was introduced in Perl 5 for this construction

open my $fh '<', $input_filename or die "Could not open $input_filename:
$!";

At $work I see bugs where people are using "or" "and" in expressions, and
the part after the expression never gets into the variable they meant it to.

my $answer = $choice_1 or $choice_2; # this is  wrong it turns into
(my $answer = $choice_1) # or $choice_2

there $choice_2 is only evaluated if the $answer got assigned a false
value, and then it gets evaluated in void context, discarding its value.

Try this in Raku - what does it say? Do you still prefer "or" over "||" ?

my $answer = 0 or 5;

say $answer;


-y


On Fri, Jun 30, 2023 at 10:53 AM Andy Bach 
wrote:

> I  always took [1]
>  As alternatives to "&&" and "||" when used for control flow, Perl
> provides
> the "and" and "or" operators (see below). The short-circuit behavior is
> identical. The precedence of "and" and "or" is much lower, however, so
> that you can safely use them after a list operator without the need for
> parentheses
>
> to suggest that and and or are the better ones to use and && or || should
> be used only if they're specifically needed.  Which has always been "never"
> for me.
>
> a
>
> [1]
> perldoc perlop
>The "||", "//" and "&&" operators return the last value evaluated
> (unlike
> C's "||" and "&&", which return 0 or 1). Thus, a reasonably portable
> way
> to find out the home directory might be:
>
> $home =  $ENV{HOME}
>   // $ENV{LOGDIR}
>   // (getpwuid($<))[7]
>   // die "You're homeless!\n";
>
> In particular, this means that you shouldn't use this for selecting
> between two aggregates for assignment:
>
> @a = @b || @c;  # this is wrong
> @a = scalar(@b) || @c;  # really meant this
> @a = @b ? @b : @c;  # this works fine, though
>
> As alternatives to "&&" and "||" when used for control flow, Perl
> provides
> the "and" and "or" operators (see below). The short-circuit behavior is
> identical. The precedence of "and" and "or" is much lower, however, so
> that you can safely use them after a list operator without the need for
> parentheses:
>
> unlink "alpha", "beta", "gamma"
> or gripe(), next LINE;
>
> With the C-style operators that would have been written like this:
>
> unlink("alpha", "beta", "gamma")
> || (gripe(), next LINE);
>
> It would be even more readable to write that this way:
>
> unless(unlink("alpha", "beta", "gamma")) {
> gripe();
> next LINE;
> }
>
> Using "or" for assignment is unlikely to do what you want; see below.
>
> --
> *From:* yary 
> *Sent:* Friday, June 30, 2023 8:45 AM
> *To:* Richard Hainsworth 
> *Cc:* perl6-us...@perl.org 
> *Subject:* Re: A question on AND
>
>
> *CAUTION - EXTERNAL: *
> Most of Richard's parting suggestions I understand & agree with, but not
> this: " why are you using '&&' and not 'and' "
>
> My habit (from Perl 5 days) is to use && || for expressions, and reserve
> "and" "or" for "do this if assignment/function call without parens
> succeeds/fails" – is there a refinement on that distinction in Raku which I
> should pay attention to?
>
> -y
>
>
> On Fri, Jun 30, 2023 at 5:40 AM Richard Hainsworth 
> wrote:
>
> I tried this and it worked without any problem.
>
> Here's the whole program:
>
> use v6.d;say @*ARGS.raku;if @*ARGS.elems > 0  &&  "@*ARGS[0]".lc eq "debug"  {
> say 'got'}
> and at the terminal:
>
> $ raku todd-test.raku debug --debug=50
> ["debug", "--debug=50"]
> got
>
>
> FWIW
> why are you quoting ARGS? The .lc coerces to string anyway.
> why are you using && and not 'and'
> why are you not using a sub MAIN with an optional --debug
> eg. sub MAIN( @args, Bool :$debug=False) {
> #stuff
> if $debug { ... }
>
>
>
> On 30/06/2023 06:06, ToddAndMargo via perl6-users wrote:
>
> if @*ARGS.elems > 0  &&  "@*ARGS[0]".lc eq "debug"  {...}
>
> *CAUTION - EXTERNAL EMAIL:* This email originated outside the Judiciary.
> Exercise caution when opening attachments or clicking on links.
>


Re: A question on AND

2023-06-30 Thread Andy Bach
I  always took [1]
 As alternatives to "&&" and "||" when used for control flow, Perl provides
the "and" and "or" operators (see below). The short-circuit behavior is
identical. The precedence of "and" and "or" is much lower, however, so
that you can safely use them after a list operator without the need for
parentheses

to suggest that and and or are the better ones to use and && or || should be 
used only if they're specifically needed.  Which has always been "never" for me.

a

[1]
perldoc perlop
   The "||", "//" and "&&" operators return the last value evaluated (unlike
C's "||" and "&&", which return 0 or 1). Thus, a reasonably portable way
to find out the home directory might be:

$home =  $ENV{HOME}
  // $ENV{LOGDIR}
  // (getpwuid($<))[7]
  // die "You're homeless!\n";

In particular, this means that you shouldn't use this for selecting
between two aggregates for assignment:

@a = @b || @c;  # this is wrong
@a = scalar(@b) || @c;  # really meant this
@a = @b ? @b : @c;  # this works fine, though

As alternatives to "&&" and "||" when used for control flow, Perl provides
the "and" and "or" operators (see below). The short-circuit behavior is
identical. The precedence of "and" and "or" is much lower, however, so
that you can safely use them after a list operator without the need for
parentheses:

unlink "alpha", "beta", "gamma"
or gripe(), next LINE;

With the C-style operators that would have been written like this:

unlink("alpha", "beta", "gamma")
|| (gripe(), next LINE);

It would be even more readable to write that this way:

unless(unlink("alpha", "beta", "gamma")) {
gripe();
next LINE;
}

Using "or" for assignment is unlikely to do what you want; see below.


From: yary 
Sent: Friday, June 30, 2023 8:45 AM
To: Richard Hainsworth 
Cc: perl6-us...@perl.org 
Subject: Re: A question on AND

CAUTION - EXTERNAL:

Most of Richard's parting suggestions I understand & agree with, but not this: 
" why are you using '&&' and not 'and' "

My habit (from Perl 5 days) is to use && || for expressions, and reserve "and" 
"or" for "do this if assignment/function call without parens succeeds/fails" – 
is there a refinement on that distinction in Raku which I should pay attention 
to?

-y


On Fri, Jun 30, 2023 at 5:40 AM Richard Hainsworth 
mailto:rnhainswo...@gmail.com>> wrote:

I tried this and it worked without any problem.

Here's the whole program:

use v6.d;
say @*ARGS.raku;
if @*ARGS.elems > 0  &&  "@*ARGS[0]".lc eq "debug"  {
say 'got'
}
and at the terminal:

$ raku todd-test.raku debug --debug=50
["debug", "--debug=50"]
got


FWIW
why are you quoting ARGS? The .lc coerces to string anyway.
why are you using && and not 'and'
why are you not using a sub MAIN with an optional --debug
eg. sub MAIN( @args, Bool :$debug=False) {
#stuff
if $debug { ... }




On 30/06/2023 06:06, ToddAndMargo via perl6-users wrote:
if @*ARGS.elems > 0  &&  "@*ARGS[0]".lc eq "debug"  {...}
CAUTION - EXTERNAL EMAIL: This email originated outside the Judiciary. Exercise 
caution when opening attachments or clicking on links.



Re: A question on AND

2023-06-30 Thread Vadim Belman

And then nobody mentions that `and` has low priority. Try `say 42 & 13` and 
`say 42 and 13`.

Best regards,
Vadim Belman

> On Jun 30, 2023, at 9:45 AM, yary  wrote:
> 
> Most of Richard's parting suggestions I understand & agree with, but not 
> this: " why are you using '&&' and not 'and' "
> 
> My habit (from Perl 5 days) is to use && || for expressions, and reserve 
> "and" "or" for "do this if assignment/function call without parens 
> succeeds/fails" – is there a refinement on that distinction in Raku which I 
> should pay attention to?
> 
> -y
> 
> 
> On Fri, Jun 30, 2023 at 5:40 AM Richard Hainsworth  > wrote:
>> I tried this and it worked without any problem.
>> 
>> Here's the whole program:
>> 
>> use v6.d;
>> say @*ARGS.raku;
>> if @*ARGS.elems > 0  &&  "@*ARGS[0]".lc eq "debug"  {
>> say 'got'
>> }
>> and at the terminal:
>> 
>> $ raku todd-test.raku debug --debug=50
>> ["debug", "--debug=50"]
>> got
>> 
>> 
>> FWIW 
>> why are you quoting ARGS? The .lc coerces to string anyway.
>> why are you using && and not 'and'
>> why are you not using a sub MAIN with an optional --debug
>> eg. sub MAIN( @args, Bool :$debug=False) { 
>> #stuff
>> if $debug { ... }
>> 
>> 
>> 
>> On 30/06/2023 06:06, ToddAndMargo via perl6-users wrote:
>>> if @*ARGS.elems > 0  &&  "@*ARGS[0]".lc eq "debug"  {...} 



Re: A question on AND

2023-06-30 Thread yary
Most of Richard's parting suggestions I understand & agree with, but not
this: " why are you using '&&' and not 'and' "

My habit (from Perl 5 days) is to use && || for expressions, and reserve
"and" "or" for "do this if assignment/function call without parens
succeeds/fails" – is there a refinement on that distinction in Raku which I
should pay attention to?

-y


On Fri, Jun 30, 2023 at 5:40 AM Richard Hainsworth 
wrote:

> I tried this and it worked without any problem.
>
> Here's the whole program:
>
> use v6.d;say @*ARGS.raku;if @*ARGS.elems > 0  &&  "@*ARGS[0]".lc eq "debug"  {
> say 'got'}
> and at the terminal:
>
> $ raku todd-test.raku debug --debug=50
> ["debug", "--debug=50"]
> got
>
>
> FWIW
> why are you quoting ARGS? The .lc coerces to string anyway.
> why are you using && and not 'and'
> why are you not using a sub MAIN with an optional --debug
> eg. sub MAIN( @args, Bool :$debug=False) {
> #stuff
> if $debug { ... }
>
>
>
> On 30/06/2023 06:06, ToddAndMargo via perl6-users wrote:
>
> if @*ARGS.elems > 0  &&  "@*ARGS[0]".lc eq "debug"  {...}
>
>


Re: A question on AND

2023-06-30 Thread Richard Hainsworth

I tried this and it worked without any problem.

Here's the whole program:

use v6.d;
say @*ARGS.raku;
if @*ARGS.elems > 0 && "@*ARGS[0]".lc eq "debug" {
say 'got' }
and at the terminal:

$ raku todd-test.raku debug --debug=50
["debug", "--debug=50"]
got


FWIW
why are you quoting ARGS? The .lc coerces to string anyway.
why are you using && and not 'and'
why are you not using a sub MAIN with an optional --debug
eg. sub MAIN( @args, Bool :$debug=False) {
#stuff
if $debug { ... }


On 30/06/2023 06:06, ToddAndMargo via perl6-users wrote:

if @*ARGS.elems > 0  &&  "@*ARGS[0]".lc eq "debug"  {...}

Re: "returns" question

2022-12-07 Thread ToddAndMargo via perl6-users

On 12/7/22 02:02, ToddAndMargo via perl6-users wrote:

On my sub declarations, I like to use "export"


I had been doing a lot of module coding.

I should have said "returns", not "export[s]"



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



Re: "returns" question

2022-12-07 Thread ToddAndMargo via perl6-users

On 12/7/22 02:02, ToddAndMargo via perl6-users wrote:

use "export"


"exports", I forgot the "s"


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



Re: BEGIN {} question

2022-09-10 Thread rir
Richard,

That is a nice summary of some differences among various Callables.

Rob

On Tue, Aug 30, 2022 at 09:34:01PM +0100, Richard Hainsworth wrote:
> Hi Todd,
> 
> Long time no see.
> 
> Re your 'keeper'. There is a reason why things are called the way they are
> in Raku (aka Perl6). BEGIN is NOT a special subroutine.
> 
> BEGIN is a phaser. And it introduces a block. Blocks are not subroutines
> (subs). Even though blocks and subs (and methods and callables) are code
> related things, a sub can take a signature, but a block cannot. You can pass
> arguments to a block using pointy syntax, eg -> $x, %y {  ... }, which is
> why it is possible to do things like 'for %some-hash.kv -> $key, $value {
>  }'. The 'for' takes a block, which can be pointy. 'for' does not take a
> special subroutine.
> 
> But a sub can have a parameter list, eg., 'sub (Int $b where *>= 10) { say
> %b }; ' The 'where' bit means that the compiler will put in checks that $b
> is always greater-equal to 10. So subs are far far more than blocks.
> 
> Also you cannot return from a block, but you can return from a sub.
> 
> So, by putting in your keeper that BEGIN is a special subroutine, you are
> ignoring a whole world of Raku goodness, as well as making it difficult for
> yourself to understand other phasers.
> 
> And talking of phasers, there are some really useful ones, like FIRST and
> LAST, that are in loops. So if you want something to happen first time in a
> loop, put it in FIRST { }.
> 
> Also I see you are on the compile time whine again. When perl6 first became
> available as 'pugs', it did take FOREVER. Then as more of perl6 became
> implemented as rakudo, startup times became slower.
> 
> Things changed when modules were precompiled. I really do not understand
> what you are talking about when you say you don't think precompile is useful
> everywhere.
> 
> For example, when I write something that is called from the command line
> (for example in my raku-collection-raku-documentation distribution), I have
> a one-liner raku program 'RakuDoc' that just says 'use Collection::RakuDoc'.
> 
> EVERYTHING else is in the module Collection::RakuDoc, all the MAIN
> subroutines, and stuff. That then only gets compiled once. So, the first
> time RakuDoc is called from the command line, there is a startup delay
> because the whole module is compiled. Every other time RakuDoc is called,
> its really so fast I don't notice a problem. Only the *one* line is compiled
> each time the program is called. All the rest is in precompiled form.
> 
> Same with my Extractor program, which is in the raku-extraction module. This
> is a GUI program that takes the rakudoc (aka POD6) files and converts them
> into markdown. For example, I write the README's for my github repos as
> README.rakudoc, then use Extractor to turn it into a README.md. The result
> is far better because the rakudoc renderer I use (from my pod-render
> distribution) automatically collects all the headers and puts them into a
> Table of Contents. If you've tried to do a TOC in markdown, you know what a
> hassle it is.
> 
> But Extractor is a GTK::Simple program. And GTK::Simple takes forever to
> precompile. But once done, I don't notice any startup time.
> 
> And I change my software quite a lot, so every time I change something, yes,
> startup is slow the first time, but not the next time. Surely, you use a
> piece of software more than once.
> 
> Compared to the OLD days, rakudo programs react like lightning. Design your
> software properly, and you wont - as a human - notice much of a delay.
> 
> I think the startup complaint (not the compile time for something) has been
> effectively relegated to the days when rakudo was young. So whilst in the
> past I truly sympathised with your rants about compile times, I am now quite
> confused and I find sympathy hard to come by.
> 
> Since you continue for ever to complain about 'compile' time issues, rather
> than startup times, I wonder whether the programs you write are massive
> monolithic lines of code with thousands of lines, much like most standard
> software when FORTRAN or COBOL were the high level languages, or whether you
> design things to make each section more manageable.
> 
> If the programs you write to be run from the command line are thousands of
> lines long, then yes!! you will suffer!!! from long startup times
> because the program is re-compiled EVERY time. However, if you redesign the
> code, putting things into classes, roles, subroutines, and Raku-y goody
> things, you can push stuff into modules, and reduce your calling program to
> a single line.
> 
> When you change your software, do you change every part of it every time? Or
> do you change some client related interface part? Put the interface part
> into one module, and the other more stable functionality into other modules.
> Then when you change the interface part, you dont change the other modules.
> They have already been compiled. So the 

Re: BEGIN {} question

2022-09-04 Thread ToddAndMargo via perl6-users

On 9/4/22 04:23, Ralph Mellor wrote:

On Sun, Sep 4, 2022 at 5:07 AM ToddAndMargo via perl6-users
 wrote:


For the fun of it, I placed a "booboo;"

Interesting!


You might like to think of `BEGIN` as a signal to the "compiler":

"Please do more than just "compile" this code. Please also run it,
right now, before "compiling" any more code.".



Thus, when the "compiler" "compiles" the code below it will also "run"
enough of it to display "But this does".

 say "This doesn't appear";
 BEGIN {
   say "Nor this";
   booboo;
   BEGIN say "But this does";
 }}^%^& no matter what nonsense is here or below:

 BEGIN !& }}!!%^&

The "compiler" will then display "===SORRY!===" as it gets to the end
of the first outer `BEGIN` and realizes `booboo` hasn't been post declared
(so hasn't been declared at all).

At that point the "compiler" has already compiled `say "Nor this";` but it
does not run it. This is so despite that `say` having appeared in a `BEGIN`.
That's because the lack of a `booboo` declaration in that outer `BEGIN`
block is considered so important that the "compiler" immediately gives up
doing anything more whatsoever -- so no more compilation *or* running.

Once you understand it's just the "compiler" going sequentially through
the source code, doing what the code tells it to do, and recognizing that
code like `say 42` is telling the "compiler" to display `42` when that line
of code is supposed to run, and recognizing that `BEGIN say 42` tells
the "compiler" that the time when that code is supposed to run is ASAP,
it'll hopefully all seem as simple and nice as it in fact is.



I've "scare-quoted" "compiler", "compiles", and "run" in the above because:

* The Rakudo "compiler" is actually a combined compiler+runner

* In Raku, "compiles" includes "running" code that "runs" at "compile-time"

* "run" means executing code, but that can happen during "compilation"

(Perl has a similar scheme -- it has a similar `BEGIN` construct.)

(In theory, Raku code that's already been compiled ahead of time, and all
that's left is to run it, should significantly outperform Perl. In
practice, getting
to the point that this is generally true is a work in progress.)

--
raiph


Hi Raiph,

Awesomely well written!  What a treat!  Thank you!
Are you a technical writer?

The BEGIN gets me around the slow start up of Raku
programs.  I use it for a splash screen (zenity).

And if I do turn over a program to a customer that
start up speed is an issue, a splash screen will
get me around them thinking the flubbed the double
click and clicking multiple more times and, if
running Windows, crashing their computers.  Not
to mention taking FOREVER for seven copies of
the program to start up.

A good test for BENIN and error after that would be
to insert some Perl 5 code:

   BEGIN {
   }  /\\\/\/\\/\/\\

Aught to do it.

(That was an Perl 5 joke.  No one trying
figuring it out.  It is just nonsense.)

-T



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


Re: BEGIN {} question

2022-09-04 Thread Ralph Mellor
On Sun, Sep 4, 2022 at 5:07 AM ToddAndMargo via perl6-users
 wrote:
>
> For the fun of it, I placed a "booboo;"
>
> Interesting!

You might like to think of `BEGIN` as a signal to the "compiler":

"Please do more than just "compile" this code. Please also run it,
right now, before "compiling" any more code.".



Thus, when the "compiler" "compiles" the code below it will also "run"
enough of it to display "But this does".

say "This doesn't appear";
BEGIN {
  say "Nor this";
  booboo;
  BEGIN say "But this does";
}}^%^& no matter what nonsense is here or below:

BEGIN !& }}!!%^&

The "compiler" will then display "===SORRY!===" as it gets to the end
of the first outer `BEGIN` and realizes `booboo` hasn't been post declared
(so hasn't been declared at all).

At that point the "compiler" has already compiled `say "Nor this";` but it
does not run it. This is so despite that `say` having appeared in a `BEGIN`.
That's because the lack of a `booboo` declaration in that outer `BEGIN`
block is considered so important that the "compiler" immediately gives up
doing anything more whatsoever -- so no more compilation *or* running.

Once you understand it's just the "compiler" going sequentially through
the source code, doing what the code tells it to do, and recognizing that
code like `say 42` is telling the "compiler" to display `42` when that line
of code is supposed to run, and recognizing that `BEGIN say 42` tells
the "compiler" that the time when that code is supposed to run is ASAP,
it'll hopefully all seem as simple and nice as it in fact is.



I've "scare-quoted" "compiler", "compiles", and "run" in the above because:

* The Rakudo "compiler" is actually a combined compiler+runner

* In Raku, "compiles" includes "running" code that "runs" at "compile-time"

* "run" means executing code, but that can happen during "compilation"

(Perl has a similar scheme -- it has a similar `BEGIN` construct.)

(In theory, Raku code that's already been compiled ahead of time, and all
that's left is to run it, should significantly outperform Perl. In
practice, getting
to the point that this is generally true is a work in progress.)

--
raiph


Re: BEGIN {} question

2022-09-03 Thread ToddAndMargo via perl6-users

On 9/2/22 18:14, ToddAndMargo via perl6-users wrote:

On 9/2/22 13:52, ToddAndMargo via perl6-users wrote:

On 9/2/22 00:13, ToddAndMargo via perl6-users wrote:

Found something interesting

$ raku -c GetUpdates.pl6
Syntax OK

Will execute the BEGIN {}, not just
syntax check it.


The guys on the chat line said this is normal
as `BEGIN` runs a compile time




Hi All,

Thinking about it, I thought I did not bring
enough attention to the `-c` switch in the
above command line.  This runs a SYNTAX check
and stops at that.  It does not run the program.
I use the `-c` option extensively to debug my
typos before debugging my programs.

When I found BEGIN actually running when all
I wanted was a syntax check, I was perplexed.
My understanding was that -c only checked my
syntax, including my BEGIN block.

This is why I asked on the chat line. Bug
or suppose to be?  And the answer is that
is just turned out that way.  And that is
fine with me.

:-)

-T


Hi All,

For the fun of it, I placed a "booboo;"
in the BEGIN block to see what the syntax
checker would do:

$ raku -c GetUpdates.pl6
===SORRY!=== Error while compiling /home/linuxutil/GetUpdates.pl6
Undeclared routine:
booboo used at line 28

Caught it.  No BEGIN pop up



Then I moved the booboo to the end of the
program

$ raku -c GetUpdates.pl6
===SORRY!=== Error while compiling /home/linuxutil/GetUpdates.pl6
Undeclared routine:
booboo used at line 11664

Caught it.  And I also got the BEGIN's pop up.

Interesting!

:-)

-T

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


Re: BEGIN {} question

2022-09-02 Thread ToddAndMargo via perl6-users

On 9/2/22 13:52, ToddAndMargo via perl6-users wrote:

On 9/2/22 00:13, ToddAndMargo via perl6-users wrote:

Found something interesting

$ raku -c GetUpdates.pl6
Syntax OK

Will execute the BEGIN {}, not just
syntax check it.


The guys on the chat line said this is normal
as `BEGIN` runs a compile time




Hi All,

Thinking about it, I thought I did not bring
enough attention to the `-c` switch in the
above command line.  This runs a SYNTAX check
and stops at that.  It does not run the program.
I use the `-c` option extensively to debug my
typos before debugging my programs.

When I found BEGIN actually running when all
I wanted was a syntax check, I was perplexed.
My understanding was that -c only checked my
syntax, including my BEGIN block.

This is why I asked on the chat line. Bug
or suppose to be?  And the answer is that
is just turned out that way.  And that is
fine with me.

:-)

-T


Re: BEGIN {} question

2022-09-02 Thread Elizabeth Mattijsen
> On 2 Sep 2022, at 22:52, ToddAndMargo via perl6-users  
> wrote:
> 
> On 9/2/22 00:13, ToddAndMargo via perl6-users wrote:
>> Found something interesting
>> $ raku -c GetUpdates.pl6
>> Syntax OK
>> Will execute the BEGIN {}, not just
>> syntax check it.
> 
> The guys on the chat line said this is normal
> as `BEGIN` runs a compile time

How short *is* your memory?

> From: Elizabeth Mattijsen 
> Subject: Re: BEGIN {} question
> Date: 29 August 2022 at 09:44:30 CEST
> To: ToddAndMargo via perl6-users 
> 
>> Question, would BEGIN go at the top or the bottom
>> of my code?  Seems the compiler would hit it first
>> at the top, but I do not know if it makes a full
>> pass of everything before firing off the BEGIN.
> 
> BEGIN runs at *compile* time.
> 
> This means that anything before the BEGIN statement in the code, is compiled 
> and known and can be referenced in the BEGIN block.
> 
> Anything *after* the BEGIN statement is still unknown to the compiler and can 
> therefore *not* be referenced.
> 
> 
> Liz



Re: BEGIN {} question

2022-09-02 Thread ToddAndMargo via perl6-users

On 9/2/22 00:13, ToddAndMargo via perl6-users wrote:

Found something interesting

$ raku -c GetUpdates.pl6
Syntax OK

Will execute the BEGIN {}, not just
syntax check it.


The guys on the chat line said this is normal
as `BEGIN` runs a compile time


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


Re: BEGIN {} question

2022-09-02 Thread ToddAndMargo via perl6-users

Found something interesting

$ raku -c GetUpdates.pl6
Syntax OK

Will execute the BEGIN {}, not just
syntax check it.


Re: BEGIN {} question

2022-09-02 Thread ToddAndMargo via perl6-users

On 9/1/22 20:16, Andinus via perl6-users wrote:


ToddAndMargo via perl6-users @ 2022-09-01 10:30 -07:


On 9/1/22 00:45, Richard Hainsworth wrote:

Treat the regexes as data for a program. Compile the program once.
Run the regexes as often as you need.


Please elucidate.  That could save me boat loads
of time.


You could take the regex string from an environment variable or read
from a file. The program is compiled only once and you can test regexes
without re-compilation.

Thanks Richard, this is going to save me a lot of time.



There are probably over 600 regex's in the
program in question.  Am I missing something?


Re: BEGIN {} question

2022-09-01 Thread Andinus via perl6-users

ToddAndMargo via perl6-users @ 2022-09-01 10:30 -07:

> On 9/1/22 00:45, Richard Hainsworth wrote:
>> Treat the regexes as data for a program. Compile the program once.
>> Run the regexes as often as you need.
>
> Please elucidate.  That could save me boat loads
> of time.

You could take the regex string from an environment variable or read
from a file. The program is compiled only once and you can test regexes
without re-compilation.

Thanks Richard, this is going to save me a lot of time.


signature.asc
Description: PGP signature


Re: BEGIN {} question

2022-09-01 Thread ToddAndMargo via perl6-users

On 9/1/22 00:45, Richard Hainsworth wrote:
Raku and Perl are two different languages in the same family. They 
evolved with different targets, perl to react quickly to internet 
requests, Raku to be a better programming language. This may not be the 
take the actual developers have, but it's what I think happened.


So the thing you designed for Perl will be faster because it fits the 
pattern. But it's not the best way for Raku. Even though stage parse 
will get significantly faster over time because Raku was designed to be 
optimisable, I think Perl will always be faster.





Hi Richard,

I do not think I have been clean enough
in my intentions.

I have two goals: long and short term.

My short term goal, which I have expounded on at
length, is to assist me with a program for my
business where I have to constantly keep up with
it and have to do a lot recompiling.  .precomp
is not helpful in that instance.

My long term goal is future programs (as I get
better at this stuff and if I EVER have a chance
to learn GLADE).

What I am after is NOT a race between Perl 5 and
Perl 6 (Raku) or any other programming language.
I really do not care if Perl 5 compiles 300 times
faster.  I care what the customer's "perception"
of what the start time is.

Ten microseconds or two seconds, the users
can't tell them apart.  Ten or twenty seconds and
users think something is wrong and start
several more instances of the program. This
is the "professionally embarrassing" part I
have written about.  I constantly have to tell
users (of non Perl 6) programs to just wait
or you will continue to crash things.

A widows work around is to have them start slow
to start programs by right clicking on the icon
and left clicking on "Open".  That way they know
they did not flub the double click.

Think of it this way. An NVMe drive is about eight
times faster that a mechanical drive.  Do the user's
programs run any faster once loaded from either
drive?  Unless they are doing substantial (YUGE)
continuing writes and reads from their drive, no
they do not run any faster.

But!  They load substantially faster, giving
the user the impression of a fast, snappy program.
This colors the rest of the user's experience.
And they don't start five instances of the program
thinking they flubbed the double click.

So I DO NOT CARE if Perl 6 is slower to compiler
AS LONG as the user/customer does not think
something is wrong.  One or two seconds is
just fine with me.  I am not after microseconds.

-T


Re: BEGIN {} question

2022-09-01 Thread ToddAndMargo via perl6-users

On 9/1/22 00:45, Richard Hainsworth wrote:

Work with Raku rather than expect it to be the same as Perl.


Oh I intent too!   I program in Top Down.  Perl 5's
subroutines are a nightmare.  I ADORE Perl 6's subroutines.

By saying above / below, this indicates a linear view of 
code at the same time.


Please elucidate!


Can you show me an example of FIRST and LAST

There are some in the documentation


https://docs.raku.org/syntax/FIRST

syntax FIRST

Documentation for syntax FIRST assembled from
the following types:  language documentation Phasers

From Phasers
(Phasers) Phasers FIRST FIRST

Runs at loop initialization, before c.

Which brings me back to my on going criticism of
the documentation.  It is a "refresher" for those
that already know what they are doing and do not
need it.

Can you point me to a good beginner's reference?


Treat the regexes as data for a program. Compile the program once. Run 
the regexes as often as you need.


Please elucidate.  That could save me boat loads
of time.


Re: BEGIN {} question

2022-09-01 Thread Richard Hainsworth
On Wed, 31 Aug 2022, 00:59 ToddAndMargo via perl6-users, <
perl6-us...@perl.org> wrote:

> On 8/30/22 13:34, Richard Hainsworth wrote:
> > Hi Todd,
> >
> 
> > Since you continue for ever to complain about 'compile' time issues,
>
> "Stage parce" is specifically what I am whining about
>
> > rather than startup times, I wonder whether the programs you write are
> > massive monolithic lines of code with thousands of lines, much like most
> > standard software when FORTRAN or COBOL were the high level languages,
> > or whether you design things to make each section more manageable.
>
>
> $ raku -c --stagestats GetUpdates.pl6
> Stage start : 0.000
> Stage parse : 17.851
> Stage syntaxcheck: Syntax OK
>
> Perl 5 does it over 300 times faster on the code I ported
>
Raku and Perl are two different languages in the same family. They evolved
with different targets, perl to react quickly to internet requests, Raku to
be a better programming language. This may not be the take the actual
developers have, but it's what I think happened.

So the thing you designed for Perl will be faster because it fits the
pattern. But it's not the best way for Raku. Even though stage parse will
get significantly faster over time because Raku was designed to be
optimisable, I think Perl will always be faster.

Having said that Raku is still better because it separates out things that
should be separate. So you may need to change the way you handle your task.
Work with Raku rather than expect it to be the same as Perl.

>
> >
> > If the programs you write to be run from the command line are thousands
> > of lines long, then yes!! you will suffer!!! from long startup times

Think about the difference between start up and parsing. Move as much stuff
away from parsing as possible.

> > because the program is re-compiled EVERY time. However, if you redesign
> 
>
> Hi Richard,
>
> Long time no talk to you either.  Don't be a stranger.
> (If you like, I can always "whine" about compile times
> to get your attention, if you like.  Chuckle.)
>
> Thank you.  That letter took a lot of work!
>
> How does this sound?
>
No. I think you are missing the explicit difference being made in Raku,
which differs from all other languages I know (explicit since one could
argue C preprocessing  does the Sam)  between compile time and run time.
Raku explicitly allows you to specify compile time actions in the program
itself. By saying above / below, this indicates a linear view of code at
the same time.
This distinction will become even greater when the new Macros are
incorporated. That's the next version of Raku.

>
>   BEGIN is a special block of code called a "phaser"
>   that runs at compile time.  It will see any code
>   above it, such as variables and  imported modules,
>   but not below it.
>
> Snip
>
> Can you show me an example of FIRST and LAST
>
> There are some in the documentation
>


>
> Where .precomp does not work for me is my software
> updates program.  This is a behemoth program (imports
> six of my custom modules too) that goes out and checks
> for software updates that I support at my customer
> sites.  it is about 70 programs.
>
Change the way you do this to be more compliant with the realities of Raku.
You may find in the refactoring process that your old way is probably
subject to bit rot.

>
> To do this open the web site with firefox.  Then I
> use their developer's tools to examine the page's
> source code.  I find the fragment I am looking
> for and regex them to extract them.
>
> In the process, I goof the regex/s "A LOT".  Not
> to mention  having to chase down hidden character
> that do not appear in Firefox's page source.
> And download that are different on a web browser
> than with curl.
>
> I do have a function that allows me to only run that
> one web site's extraction, so I do not have to go
> through all 70 of them.
>
> So, I have to recompile the code maybe up to 20 times
> depending on the difficulty of the web site.  The
> L-O-N-G delays drives me nuts.
>
Treat the regexes as data for a program. Compile the program once. Run the
regexes as often as you need.

>
> Snip.
>
> Speaking of BEGIN, is this Raku's "parallel
> processing" method?  Does Raku have a way to
> spawn parallel processes and have them talk to
> each other?
>
> -T
>
> Concurrency is a major change that Raku does differently. But it bursts my
> head. Because concurrency is hard!
>


>
>
>
>
>
>
>


Re: BEGIN {} question

2022-08-30 Thread ToddAndMargo via perl6-users

On 8/30/22 13:34, Richard Hainsworth wrote:

Hi Todd,

Long time no see.

Re your 'keeper'. There is a reason why things are called the way they 
are in Raku (aka Perl6). BEGIN is NOT a special subroutine.


BEGIN is a phaser. And it introduces a block. Blocks are not subroutines 
(subs). Even though blocks and subs (and methods and callables) are code 
related things, a sub can take a signature, but a block cannot. You can 
pass arguments to a block using pointy syntax, eg -> $x, %y {  ... }, 
which is why it is possible to do things like 'for %some-hash.kv -> 
$key, $value {  }'. The 'for' takes a block, which can be pointy. 
'for' does not take a special subroutine.


But a sub can have a parameter list, eg., 'sub (Int $b where *>= 10) { 
say %b }; ' The 'where' bit means that the compiler will put in checks 
that $b is always greater-equal to 10. So subs are far far more than 
blocks.


Also you cannot return from a block, but you can return from a sub.

So, by putting in your keeper that BEGIN is a special subroutine, you 
are ignoring a whole world of Raku goodness, as well as making it 
difficult for yourself to understand other phasers.


And talking of phasers, there are some really useful ones, like FIRST 
and LAST, that are in loops. So if you want something to happen first 
time in a loop, put it in FIRST { }.


Also I see you are on the compile time whine again. When perl6 first 
became available as 'pugs', it did take FOREVER. Then as more of perl6 
became implemented as rakudo, startup times became slower.


Things changed when modules were precompiled. I really do not understand 
what you are talking about when you say you don't think precompile is 
useful everywhere.


For example, when I write something that is called from the command line 
(for example in my raku-collection-raku-documentation distribution), I 
have a one-liner raku program 'RakuDoc' that just says 'use 
Collection::RakuDoc'.


EVERYTHING else is in the module Collection::RakuDoc, all the MAIN 
subroutines, and stuff. That then only gets compiled once. So, the first 
time RakuDoc is called from the command line, there is a startup delay 
because the whole module is compiled. Every other time RakuDoc is 
called, its really so fast I don't notice a problem. Only the *one* line 
is compiled each time the program is called. All the rest is in 
precompiled form.


Same with my Extractor program, which is in the raku-extraction module. 
This is a GUI program that takes the rakudoc (aka POD6) files and 
converts them into markdown. For example, I write the README's for my 
github repos as README.rakudoc, then use Extractor to turn it into a 
README.md. The result is far better because the rakudoc renderer I use 
(from my pod-render distribution) automatically collects all the headers 
and puts them into a Table of Contents. If you've tried to do a TOC in 
markdown, you know what a hassle it is.


But Extractor is a GTK::Simple program. And GTK::Simple takes forever to 
precompile. But once done, I don't notice any startup time.


And I change my software quite a lot, so every time I change something, 
yes, startup is slow the first time, but not the next time. Surely, you 
use a piece of software more than once.


Compared to the OLD days,


Last week ?  Chuckle.

rakudo programs react like lightning. Design 
your software properly, and you wont - as a human - notice much of a delay.


I think the startup complaint (not the compile time for something) has 
been effectively relegated to the days when rakudo was young. So whilst 
in the past I truly sympathised with your rants about compile times, I 
am now quite confused and I find sympathy hard to come by.


Since you continue for ever to complain about 'compile' time issues,


"Stage parce" is specifically what I am whining about

rather than startup times, I wonder whether the programs you write are 
massive monolithic lines of code with thousands of lines, much like most 
standard software when FORTRAN or COBOL were the high level languages, 
or whether you design things to make each section more manageable.



$ raku -c --stagestats GetUpdates.pl6
Stage start : 0.000
Stage parse : 17.851
Stage syntaxcheck: Syntax OK

Perl 5 does it over 300 times faster on the code I ported



If the programs you write to be run from the command line are thousands 
of lines long, then yes!! you will suffer!!! from long startup times 
because the program is re-compiled EVERY time. However, if you redesign 
the code, putting things into classes, roles, subroutines, and Raku-y 
goody things, you can push stuff into modules, and reduce your calling 
program to a single line.


When you change your software, do you change every part of it every 
time? Or do you change some client related interface part? Put the 
interface part into one module, and the other more stable functionality 
into other modules. Then when you change the interface part, you dont 
change the other modules. 

Re: BEGIN {} question

2022-08-30 Thread Richard Hainsworth

Hi Todd,

Long time no see.

Re your 'keeper'. There is a reason why things are called the way they 
are in Raku (aka Perl6). BEGIN is NOT a special subroutine.


BEGIN is a phaser. And it introduces a block. Blocks are not subroutines 
(subs). Even though blocks and subs (and methods and callables) are code 
related things, a sub can take a signature, but a block cannot. You can 
pass arguments to a block using pointy syntax, eg -> $x, %y {  ... }, 
which is why it is possible to do things like 'for %some-hash.kv -> 
$key, $value {  }'. The 'for' takes a block, which can be pointy. 
'for' does not take a special subroutine.


But a sub can have a parameter list, eg., 'sub (Int $b where *>= 10) { 
say %b }; ' The 'where' bit means that the compiler will put in checks 
that $b is always greater-equal to 10. So subs are far far more than blocks.


Also you cannot return from a block, but you can return from a sub.

So, by putting in your keeper that BEGIN is a special subroutine, you 
are ignoring a whole world of Raku goodness, as well as making it 
difficult for yourself to understand other phasers.


And talking of phasers, there are some really useful ones, like FIRST 
and LAST, that are in loops. So if you want something to happen first 
time in a loop, put it in FIRST { }.


Also I see you are on the compile time whine again. When perl6 first 
became available as 'pugs', it did take FOREVER. Then as more of perl6 
became implemented as rakudo, startup times became slower.


Things changed when modules were precompiled. I really do not understand 
what you are talking about when you say you don't think precompile is 
useful everywhere.


For example, when I write something that is called from the command line 
(for example in my raku-collection-raku-documentation distribution), I 
have a one-liner raku program 'RakuDoc' that just says 'use 
Collection::RakuDoc'.


EVERYTHING else is in the module Collection::RakuDoc, all the MAIN 
subroutines, and stuff. That then only gets compiled once. So, the first 
time RakuDoc is called from the command line, there is a startup delay 
because the whole module is compiled. Every other time RakuDoc is 
called, its really so fast I don't notice a problem. Only the *one* line 
is compiled each time the program is called. All the rest is in 
precompiled form.


Same with my Extractor program, which is in the raku-extraction module. 
This is a GUI program that takes the rakudoc (aka POD6) files and 
converts them into markdown. For example, I write the README's for my 
github repos as README.rakudoc, then use Extractor to turn it into a 
README.md. The result is far better because the rakudoc renderer I use 
(from my pod-render distribution) automatically collects all the headers 
and puts them into a Table of Contents. If you've tried to do a TOC in 
markdown, you know what a hassle it is.


But Extractor is a GTK::Simple program. And GTK::Simple takes forever to 
precompile. But once done, I don't notice any startup time.


And I change my software quite a lot, so every time I change something, 
yes, startup is slow the first time, but not the next time. Surely, you 
use a piece of software more than once.


Compared to the OLD days, rakudo programs react like lightning. Design 
your software properly, and you wont - as a human - notice much of a delay.


I think the startup complaint (not the compile time for something) has 
been effectively relegated to the days when rakudo was young. So whilst 
in the past I truly sympathised with your rants about compile times, I 
am now quite confused and I find sympathy hard to come by.


Since you continue for ever to complain about 'compile' time issues, 
rather than startup times, I wonder whether the programs you write are 
massive monolithic lines of code with thousands of lines, much like most 
standard software when FORTRAN or COBOL were the high level languages, 
or whether you design things to make each section more manageable.


If the programs you write to be run from the command line are thousands 
of lines long, then yes!! you will suffer!!! from long startup times 
because the program is re-compiled EVERY time. However, if you redesign 
the code, putting things into classes, roles, subroutines, and Raku-y 
goody things, you can push stuff into modules, and reduce your calling 
program to a single line.


When you change your software, do you change every part of it every 
time? Or do you change some client related interface part? Put the 
interface part into one module, and the other more stable functionality 
into other modules. Then when you change the interface part, you dont 
change the other modules. They have already been compiled. So the first 
time you start up your program, only the section you have changed gets 
recompiled, not the entire monolith.


By the way, I assume that you understand the Raku meaning of 'module', 
as opposed to a 'distribution'. When I write a large piece of software, 
I 

Re: BEGIN {} question

2022-08-29 Thread ToddAndMargo via perl6-users

On 8/28/22 15:58, ToddAndMargo via perl6-users wrote:

Hi All,

I am thinking of using

    BEGIN {}

to fire up a splash screen (libnotify).

Question: is what happens between the brackets
isolated from the rest of the code?   If I set
variable values or declare variables, are they
wiped out, etc.?

Many thanks,
-T






My keeper on BEGIN.  That you for all the help
and tips!



Perl6: BEGIN {}


BEGIN is a special subroutine that runs at compile time.
It will see any code above it, such as variables and
imported modules, but not below it.

The idea is to run something at the start of compile before
the rest of compile completes.  A splash screen for example.

Perl 6's compile can take a very long time and users may not
realize it started and restart it several times.

Note that a space is required between `BEGIN and the `{}`


BEGIN {
   # Splash Screen

 ( my $ProgramName   = $?FILE ) ~~ s|.*"/"||;
   my Str $NotifyStr = "\nStarting $ProgramName\n";
   my Str $Icon  = "/home/linuxutil/Images/Info.png";
   my Str $Title = "$ProgramName Splash Screen";
   my Str $Timeout   = "8";   # zenity = seconds

   # Note: zenity seems to not detach when run without a shell
   shell "zenity --info --title \"$Title\" --text \"$NotifyStr\" 
--width=220 --timeout=$Timeout &";

}



Re: BEGIN {} question

2022-08-29 Thread ToddAndMargo via perl6-users

On 8/29/22 13:03, ToddAndMargo via perl6-users wrote:

On 8/28/22 15:58, ToddAndMargo via perl6-users wrote:

Hi All,

I am thinking of using

    BEGIN {}

to fire up a splash screen (libnotify).

Question: is what happens between the brackets
isolated from the rest of the code?   If I set
variable values or declare variables, are they
wiped out, etc.?

Many thanks,
-T


Follow up:

Thank you all for the help!

My splash screen pops up whilst the
rest of the program compiles.

Here is my BEGIN code.   If you are
wondering why all the variables when
I could just write it in the run line,
it is becasue the names of the variables
and the comments next to them tell me what
the parameters of notify-send are and
how to use them.  Much easier to maintain.



#!/usr/bin/env perl6

use RunNoShellLib :RunNoShell, :RunNoShellCode, :RunNoShellErr;

BEGIN {
    # Splash Screen

  ( my $ProgramName   = $?FILE ) ~~ s|.*"/"||;
    my Str $NotifyStr = "\nStarting $ProgramName\n";
    my Str $Icon  = "/home/linuxutil/Images/Info.png";
    my Str $Title = "$ProgramName Splash Screen";
    my Str $Timeout   = "8000";  # milliseconds

    RunNoShell( "notify-send -u normal -t \"$Timeout\" -i \"$Icon\" 
\"$Title\" \"$NotifyStr\"" );

}



:-)

Love Raku!

-T



I changed my BEGIN a bit.  Send-notify open on the right under the last 
notification.


Zenity allow me to open up right in the middle to the
screen.

And I had to switch from run to shell to get zenity
to detach.  Otherwise the compiler stops until
zenity returns


BEGIN {
   # Splash Screen

 ( my $ProgramName   = $?FILE ) ~~ s|.*"/"||;
   my Str $NotifyStr = "\nStarting $ProgramName\n";
   my Str $Icon  = "/home/linuxutil/Images/Info.png";
   my Str $Title = "$ProgramName Splash Screen";
   # my Str $Timeout   = "8000";  # notify-send = milliseconds
   my Str $Timeout   = "8";   # zenity = seconds

   # Note: zenity seems to not detach when run without a shell
   # RunNoShell( "zenity --info --title \"$Title\" --text 
\"$NotifyStr\" --width=220 --timeout=$Timeout" );
   shell "zenity --info --title \"$Title\" --text \"$NotifyStr\" 
--width=220 --timeout=$Timeout &";

}


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


Re: BEGIN {} question

2022-08-29 Thread ToddAndMargo via perl6-users

On 8/28/22 15:58, ToddAndMargo via perl6-users wrote:

Hi All,

I am thinking of using

    BEGIN {}

to fire up a splash screen (libnotify).

Question: is what happens between the brackets
isolated from the rest of the code?   If I set
variable values or declare variables, are they
wiped out, etc.?

Many thanks,
-T


Follow up:

Thank you all for the help!

My splash screen pops up whilst the
rest of the program compiles.

Here is my BEGIN code.   If you are
wondering why all the variables when
I could just write it in the run line,
it is becasue the names of the variables
and the comments next to them tell me what
the parameters of notify-send are and
how to use them.  Much easier to maintain.



#!/usr/bin/env perl6

use RunNoShellLib :RunNoShell, :RunNoShellCode, :RunNoShellErr;

BEGIN {
   # Splash Screen

 ( my $ProgramName   = $?FILE ) ~~ s|.*"/"||;
   my Str $NotifyStr = "\nStarting $ProgramName\n";
   my Str $Icon  = "/home/linuxutil/Images/Info.png";
   my Str $Title = "$ProgramName Splash Screen";
   my Str $Timeout   = "8000";  # milliseconds

   RunNoShell( "notify-send -u normal -t \"$Timeout\" -i \"$Icon\" 
\"$Title\" \"$NotifyStr\"" );

}



:-)

Love Raku!

-T


Re: BEGIN {} question

2022-08-29 Thread ToddAndMargo via perl6-users

On 8/29/22 10:45, Tom Browder wrote:

On Mon, Aug 29, 2022 at 12:31 PM ToddAndMargo via perl6-users
 wrote:

On 8/29/22 08:41, Tom Browder wrote:

...

And I think you may be surprised how much speedup you may get by using
the precompiled-module "trick" for most of your 11,000-line program.

...

Hi Tom,
The .precomp workaround was never in question!
But there are tines when it is impractical.

...

So lots and lots of compiling that .precomp does not
help me with.

...

More information that you wanted.  Sorry.


No reason to apologize, Todd. I had forgotten how much you were
actually doing with your Raku code--a textbook example for sure!

But I apologize for my impatient replies.  :-)

Blessings,

-Tom


Hi Tom,

You are a force of nature.  I always love
your replies.  I was in no way offended.

:-)

I got long winded because a lot of folks keep
telling me about the .precomp workaround.  I did
not want them to think I was summarily
disregarding their advice (including you).
I wanted to expound on why it is not always
practicle.

-T


Re: BEGIN {} question

2022-08-29 Thread Tom Browder
On Mon, Aug 29, 2022 at 12:31 PM ToddAndMargo via perl6-users
 wrote:
> On 8/29/22 08:41, Tom Browder wrote:
...
> > And I think you may be surprised how much speedup you may get by using
> > the precompiled-module "trick" for most of your 11,000-line program.
...
> Hi Tom,
> The .precomp workaround was never in question!
> But there are tines when it is impractical.
...
> So lots and lots of compiling that .precomp does not
> help me with.
...
> More information that you wanted.  Sorry.

No reason to apologize, Todd. I had forgotten how much you were
actually doing with your Raku code--a textbook example for sure!

But I apologize for my impatient replies.  :-)

Blessings,

-Tom


Re: BEGIN {} question

2022-08-29 Thread ToddAndMargo via perl6-users

On 8/29/22 08:41, Tom Browder wrote:
On Mon, Aug 29, 2022 at 10:29 AM ToddAndMargo via perl6-users 
mailto:perl6-us...@perl.org>> wrote:

...
 > Does the compiler make a full pass through
 > the code before firing off the BEGIN routine

NO.

And I think you may be surprised how much speedup you may get by using 
the precompiled-module "trick" for most of your 11,000-line program.


-Tom




Hi Tom,

The .precomp workaround was never in question!

But there are tines when it is impractical.

Most of the programs I have written for customers
run in the background (rakuw) or at night when
no one cares how long they take to start.

Other programs are to remove mistakes from barcode
data when routed to a bar code program.  The
customer inputs data into their Point of Sale
software that freaks out the bar code printing
program, so I correct it on the fly.  It
is a lot easier than going through their entire
database and having the remote `'` for feet and
`"` for inches in a CSV file sent to the
barcode program (comma-separated value).  Not
to mention it is impossible to get the users
to stop making those mistakes

I also have written my own Dynamic DNS (Domain
Name Server) work around for folks that I
have installed RDP (remote Desktop Protocol) on
and that are using floating WAN (Wide Area
Network) addresses.  But it is pretty simple
and starts quick enough.

Now for where .precomp is not practical.  It is
those projects were the saying "the software is
never finished" applies.   Where I am loath to
start/recommend projects that the customer
expects a reasonable response time to start.
So far, I have been lucky.

For those programs that do not require a lot of
maintenance, the .precomp work around is reasonable.

Primarily where the response time drives me INSANE
is my software updates program.   This program goes
out and checks for new updates for programs I support.
If a new one exists, it downloads.  I carry these
programs with me to customer sites on a read only
flash drive so as to not transfer viruses between
customers.  So far it is about 70 programs.

Because Web Developers are always working on their
sites, I am constantly having to figure out
what is wrong.  "The software is never finished".
So .precomp does not help.

What I have done though is to configure the program
such that if I put the sub name of the target program
on the run line, my program will only run that section
rather that waiting 5 minutes to go through them all.
And if my program finds something on the run line it,
it also triggers my extensive debugging.

And it does take a lot of iterations to debug my regex's.
And the wait time (17 seconds) drives me NUTS.
Sometimes, the "source" code on Firefox's development
tools dos not show hidden character in their pages and
that creates a nightmare too.  I spurt the web page
to a file and then see what the heck is wrong.
I am getting pretty good at it though.  "Git" and
"Brave" (Browser) are interesting to download from.

So lots and lots of compiling that .precomp does not
help me with.

More information that your wanted.  Sorry.

-T


Re: BEGIN {} question

2022-08-29 Thread Tom Browder
On Mon, Aug 29, 2022 at 10:29 AM ToddAndMargo via perl6-users <
perl6-us...@perl.org> wrote:
...
> Does the compiler make a full pass through
> the code before firing off the BEGIN routine

NO.

And I think you may be surprised how much speedup you may get by using the
precompiled-module "trick" for most of your 11,000-line program.

-Tom


Re: BEGIN {} question

2022-08-29 Thread ToddAndMargo via perl6-users

On 8/29/22 00:44, Elizabeth Mattijsen wrote:

Question, would BEGIN go at the top or the bottom
of my code?  Seems the compiler would hit it first
at the top, but I do not know if it makes a full
pass of everything before firing off the BEGIN.


BEGIN runs at *compile* time.

This means that anything before the BEGIN statement in the code, is compiled 
and known and can be referenced in the BEGIN block.

Anything *after* the BEGIN statement is still unknown to the compiler and can 
therefore *not* be referenced.


Liz



Hi Liz,

Excellent explanation.  Thank you!

Does the compiler make a full pass through
the code before firing off the BEGIN routine
or does it fire it off as soon as it finds it?

-T


Re: BEGIN {} question

2022-08-29 Thread Elizabeth Mattijsen
> Question, would BEGIN go at the top or the bottom
> of my code?  Seems the compiler would hit it first
> at the top, but I do not know if it makes a full
> pass of everything before firing off the BEGIN.

BEGIN runs at *compile* time.

This means that anything before the BEGIN statement in the code, is compiled 
and known and can be referenced in the BEGIN block.

Anything *after* the BEGIN statement is still unknown to the compiler and can 
therefore *not* be referenced.


Liz

Re: BEGIN {} question

2022-08-28 Thread ToddAndMargo via perl6-users

On 8/28/22 19:11, Bruce Gray wrote:




On Aug 28, 2022, at 5:58 PM, ToddAndMargo via perl6-users 
 wrote:

Hi All,

I am thinking of using

   BEGIN {}

to fire up a splash screen (libnotify).

Question: is what happens between the brackets
isolated from the rest of the code?   If I set
variable values or declare variables, are they
wiped out, etc.?

Many thanks,
-T


BEGIN blocks create a lexical scope, because they are *blocks*, so any 
variables that you declare within the block don't exist outside the block.

Variables that you define in the lexical scope *surrounding* the BEGIN block 
can have their values set inside the BEGIN block, and those values will be 
retained after BEGIN ends.

my $a_var;
sub do_something ( ) {
 say "did something! By the way: ", (:$a_var), ' inside a sub called from 
the BEGIN block, because the var is shared between them (same lexical scope).';
}
BEGIN {
 $a_var = 42;
 my $b_var = 11;
 say "a_var is $a_var within the BEGIN block";
 say "b_var is $b_var within the BEGIN block";
 do_something();
}
say "a_var is still $a_var outside the BEGIN block";
# say "b_var is still $b_var outside the BEGIN block"; # Commented out, because 
illegal!

Output:
a_var is 42 within the BEGIN block
b_var is 11 within the BEGIN block
did something! By the way: a_var => 42 inside a sub called from the BEGIN 
block, because the var is shared between them (same lexical scope).
a_var is still 42 outside the BEGIN block



Hi Bruce,

Thank you!  I understand now.

I was channeling my old Modula2 days, where
everything had a BEGIN and an END.  I did not
realize BEGIN was a "name".  A special name
of a subroutine that would run before compile
was complete.

I am now thinking of firing off a call to libnotify
with a delayed close out time to simulate a splash
screen.

Question, would BEGIN go at the top or the bottom
of my code?  Seems the compiler would hit it first
at the top, but I do not know if it makes a full
pass of everything before firing off the BEGIN.

-T



Re: BEGIN {} question

2022-08-28 Thread Bruce Gray



> On Aug 28, 2022, at 5:58 PM, ToddAndMargo via perl6-users 
>  wrote:
> 
> Hi All,
> 
> I am thinking of using
> 
>   BEGIN {}
> 
> to fire up a splash screen (libnotify).
> 
> Question: is what happens between the brackets
> isolated from the rest of the code?   If I set
> variable values or declare variables, are they
> wiped out, etc.?
> 
> Many thanks,
> -T

BEGIN blocks create a lexical scope, because they are *blocks*, so any 
variables that you declare within the block don't exist outside the block.

Variables that you define in the lexical scope *surrounding* the BEGIN block 
can have their values set inside the BEGIN block, and those values will be 
retained after BEGIN ends. 

my $a_var;
sub do_something ( ) {
say "did something! By the way: ", (:$a_var), ' inside a sub called from 
the BEGIN block, because the var is shared between them (same lexical scope).';
}
BEGIN {
$a_var = 42;
my $b_var = 11;
say "a_var is $a_var within the BEGIN block";
say "b_var is $b_var within the BEGIN block";
do_something();
}
say "a_var is still $a_var outside the BEGIN block";
# say "b_var is still $b_var outside the BEGIN block"; # Commented out, because 
illegal!

Output:
a_var is 42 within the BEGIN block
b_var is 11 within the BEGIN block
did something! By the way: a_var => 42 inside a sub called from the BEGIN 
block, because the var is shared between them (same lexical scope).
a_var is still 42 outside the BEGIN block

-- 
Hope this helps,
Bruce Gray (Util of PerlMonks)



Re: a question on use and . in class declarations

2020-12-30 Thread ToddAndMargo via perl6-users

On 12/30/20 5:41 PM, ToddAndMargo via perl6-users wrote:

A question on the "use" in a class declaration.

In "use $.x". does the dot have a special meaning
or is it just to make the value ($.x) easier to
access ($objectname.x)?

Many thanks,
-T



From my in progress notes on OOP:


*** addressing values inside an object ***

   The dot itself is technically an operator, it means "call the method
   'apples' on the preceding object".  So $FruitStand.apples translates
   to "call the method 'apples' on the object $FruitStand" [11]

[11] https://webchat.freenode.net/?channels=#raku: guifa2 2020-12-30 
18:06:23




Re: printf question

2020-02-11 Thread WFB
Awesome, thanks!
That is exactly what I was looking for.


On Tue, 11 Feb 2020 at 10:23, Kevin Pye  wrote:

> The "workaround" is well documented:
> https://docs.raku.org/language/create-cli#%*SUB-MAIN-OPTS
>
> It's just a matter of setting named-anywhere option in the %*SUB-MAIN-OPTS
> hash, which you will also need to create. There's an example in that doc
> page.
>
> Kevin.
>
> On Tue, 11 Feb 2020 at 20:07, WFB  wrote:
>
>> Interesting stuff.
>> I would like to take the change and ask one question:
>> One thing, I had to get used to is the MAIN handling of parameters.
>> On the command line it is important to write then named parameter in
>> front of the positional ones:
>> MAIN('compile', :$verbose, :$test-only)
>> needs to write:
>> builder.raku --verbose compile
>> Its not possible to write
>> builder.raku compile --verbose.
>> That is not intuitive, at least for me because that breaks with the other
>> unix command line tools and is annoying if you have to change the script
>> call several times.
>>
>> Why is that so? And is there a workaround for that?
>> Thanks
>> Wolfgang
>>
>> On Mon, 10 Feb 2020 at 12:18, Timo Paulssen  wrote:
>>
>>> Hi Paul and Todd,
>>>
>>> just a little extra info: the limitation for nameds to come after
>>> positionals is only for declarations of signatures.
>>>
>>> Usage of subs/methods as well as capture literals (which you don't use
>>> often, i imagine, so feel free to disregard) allow you to mix nameds and
>>> positionals freely; it will handle named parameters that are put between
>>> positionals as if they were after the positional parameters.
>>>
>>> > sub abcdefg($b, $f, $g, :$a, :$c, :$e) { say $a, $b, $c, $e }
>>> 
>>> > abcdefg(1, a => 5, 2, c => 99, 100, e => 1024)
>>> 51991024
>>>
>>> Most cases where I wanted named parameters early in the call was when
>>> there was something big in the call, for example if a sub takes a block and
>>> a few options, i prefer to put the options before the block, so they are
>>> visible at a glance rather than after scrolling. I suppose this mirrors how
>>> regex modifiers (like :ignorecase / :i, :global, etc) have been moved to
>>> the front of regexes.
>>>
>>> Hope that's interesting
>>>   - Timo
>>> On 10/02/2020 07:48, Paul Procacci wrote:
>>>
>>> Named parameters must come after all positional parameters.
>>> Your example subroutine is invalid for this reason, while the following
>>> would be fine:
>>>
>>> sub abcdefg( $b, $f, $g, :$a, :$c, :$e)
>>>
>>> abcdefg("position1", "position2", "position3", :e("named_e"),
>>> :a("named_a"), :c("named_c"));
>>>
>>>
>>>
>>> On Sun, Feb 9, 2020 at 6:24 PM ToddAndMargo via perl6-users <
>>> perl6-us...@perl.org> wrote:
>>>
 On 2020-02-09 14:53, Paul Procacci wrote:
 > subchdir(IO() $path, :$d=True, :$r, :$w, :$x-->IO::Path:D)

 Hi Paul,

 What I wanted to see is how something liek

 sub abcdefg( :$a, $b, :$c, :$e, $f, $g )

 would be called

 -T

>>>
>>>
>>> --
>>> __
>>>
>>> :(){ :|:& };:
>>>
>>>


Re: printf question

2020-02-11 Thread Kevin Pye
The "workaround" is well documented:
https://docs.raku.org/language/create-cli#%*SUB-MAIN-OPTS

It's just a matter of setting named-anywhere option in the %*SUB-MAIN-OPTS
hash, which you will also need to create. There's an example in that doc
page.

Kevin.

On Tue, 11 Feb 2020 at 20:07, WFB  wrote:

> Interesting stuff.
> I would like to take the change and ask one question:
> One thing, I had to get used to is the MAIN handling of parameters.
> On the command line it is important to write then named parameter in front
> of the positional ones:
> MAIN('compile', :$verbose, :$test-only)
> needs to write:
> builder.raku --verbose compile
> Its not possible to write
> builder.raku compile --verbose.
> That is not intuitive, at least for me because that breaks with the other
> unix command line tools and is annoying if you have to change the script
> call several times.
>
> Why is that so? And is there a workaround for that?
> Thanks
> Wolfgang
>
> On Mon, 10 Feb 2020 at 12:18, Timo Paulssen  wrote:
>
>> Hi Paul and Todd,
>>
>> just a little extra info: the limitation for nameds to come after
>> positionals is only for declarations of signatures.
>>
>> Usage of subs/methods as well as capture literals (which you don't use
>> often, i imagine, so feel free to disregard) allow you to mix nameds and
>> positionals freely; it will handle named parameters that are put between
>> positionals as if they were after the positional parameters.
>>
>> > sub abcdefg($b, $f, $g, :$a, :$c, :$e) { say $a, $b, $c, $e }
>> 
>> > abcdefg(1, a => 5, 2, c => 99, 100, e => 1024)
>> 51991024
>>
>> Most cases where I wanted named parameters early in the call was when
>> there was something big in the call, for example if a sub takes a block and
>> a few options, i prefer to put the options before the block, so they are
>> visible at a glance rather than after scrolling. I suppose this mirrors how
>> regex modifiers (like :ignorecase / :i, :global, etc) have been moved to
>> the front of regexes.
>>
>> Hope that's interesting
>>   - Timo
>> On 10/02/2020 07:48, Paul Procacci wrote:
>>
>> Named parameters must come after all positional parameters.
>> Your example subroutine is invalid for this reason, while the following
>> would be fine:
>>
>> sub abcdefg( $b, $f, $g, :$a, :$c, :$e)
>>
>> abcdefg("position1", "position2", "position3", :e("named_e"),
>> :a("named_a"), :c("named_c"));
>>
>>
>>
>> On Sun, Feb 9, 2020 at 6:24 PM ToddAndMargo via perl6-users <
>> perl6-us...@perl.org> wrote:
>>
>>> On 2020-02-09 14:53, Paul Procacci wrote:
>>> > subchdir(IO() $path, :$d=True, :$r, :$w, :$x-->IO::Path:D)
>>>
>>> Hi Paul,
>>>
>>> What I wanted to see is how something liek
>>>
>>> sub abcdefg( :$a, $b, :$c, :$e, $f, $g )
>>>
>>> would be called
>>>
>>> -T
>>>
>>
>>
>> --
>> __
>>
>> :(){ :|:& };:
>>
>>


Re: printf question

2020-02-11 Thread WFB
Interesting stuff.
I would like to take the change and ask one question:
One thing, I had to get used to is the MAIN handling of parameters.
On the command line it is important to write then named parameter in front
of the positional ones:
MAIN('compile', :$verbose, :$test-only)
needs to write:
builder.raku --verbose compile
Its not possible to write
builder.raku compile --verbose.
That is not intuitive, at least for me because that breaks with the other
unix command line tools and is annoying if you have to change the script
call several times.

Why is that so? And is there a workaround for that?
Thanks
Wolfgang

On Mon, 10 Feb 2020 at 12:18, Timo Paulssen  wrote:

> Hi Paul and Todd,
>
> just a little extra info: the limitation for nameds to come after
> positionals is only for declarations of signatures.
>
> Usage of subs/methods as well as capture literals (which you don't use
> often, i imagine, so feel free to disregard) allow you to mix nameds and
> positionals freely; it will handle named parameters that are put between
> positionals as if they were after the positional parameters.
>
> > sub abcdefg($b, $f, $g, :$a, :$c, :$e) { say $a, $b, $c, $e }
> 
> > abcdefg(1, a => 5, 2, c => 99, 100, e => 1024)
> 51991024
>
> Most cases where I wanted named parameters early in the call was when
> there was something big in the call, for example if a sub takes a block and
> a few options, i prefer to put the options before the block, so they are
> visible at a glance rather than after scrolling. I suppose this mirrors how
> regex modifiers (like :ignorecase / :i, :global, etc) have been moved to
> the front of regexes.
>
> Hope that's interesting
>   - Timo
> On 10/02/2020 07:48, Paul Procacci wrote:
>
> Named parameters must come after all positional parameters.
> Your example subroutine is invalid for this reason, while the following
> would be fine:
>
> sub abcdefg( $b, $f, $g, :$a, :$c, :$e)
>
> abcdefg("position1", "position2", "position3", :e("named_e"),
> :a("named_a"), :c("named_c"));
>
>
>
> On Sun, Feb 9, 2020 at 6:24 PM ToddAndMargo via perl6-users <
> perl6-us...@perl.org> wrote:
>
>> On 2020-02-09 14:53, Paul Procacci wrote:
>> > subchdir(IO() $path, :$d=True, :$r, :$w, :$x-->IO::Path:D)
>>
>> Hi Paul,
>>
>> What I wanted to see is how something liek
>>
>> sub abcdefg( :$a, $b, :$c, :$e, $f, $g )
>>
>> would be called
>>
>> -T
>>
>
>
> --
> __
>
> :(){ :|:& };:
>
>


Re: printf question

2020-02-10 Thread ToddAndMargo via perl6-users

On 2020-02-10 03:18, Timo Paulssen wrote:

Hope that's interesting


Very!   :-)


Re: printf question

2020-02-10 Thread Paul Procacci
Thanks Timo,

I was, in part, aware of this, but didn't have the full knowledge/details
as you've explained it.

Thanks!

On Mon, Feb 10, 2020 at 6:18 AM Timo Paulssen  wrote:

> Hi Paul and Todd,
>
> just a little extra info: the limitation for nameds to come after
> positionals is only for declarations of signatures.
>
> Usage of subs/methods as well as capture literals (which you don't use
> often, i imagine, so feel free to disregard) allow you to mix nameds and
> positionals freely; it will handle named parameters that are put between
> positionals as if they were after the positional parameters.
>
> > sub abcdefg($b, $f, $g, :$a, :$c, :$e) { say $a, $b, $c, $e }
> 
> > abcdefg(1, a => 5, 2, c => 99, 100, e => 1024)
> 51991024
>
> Most cases where I wanted named parameters early in the call was when
> there was something big in the call, for example if a sub takes a block and
> a few options, i prefer to put the options before the block, so they are
> visible at a glance rather than after scrolling. I suppose this mirrors how
> regex modifiers (like :ignorecase / :i, :global, etc) have been moved to
> the front of regexes.
>
> Hope that's interesting
>   - Timo
> On 10/02/2020 07:48, Paul Procacci wrote:
>
> Named parameters must come after all positional parameters.
> Your example subroutine is invalid for this reason, while the following
> would be fine:
>
> sub abcdefg( $b, $f, $g, :$a, :$c, :$e)
>
> abcdefg("position1", "position2", "position3", :e("named_e"),
> :a("named_a"), :c("named_c"));
>
>
>
> On Sun, Feb 9, 2020 at 6:24 PM ToddAndMargo via perl6-users <
> perl6-us...@perl.org> wrote:
>
>> On 2020-02-09 14:53, Paul Procacci wrote:
>> > subchdir(IO() $path, :$d=True, :$r, :$w, :$x-->IO::Path:D)
>>
>> Hi Paul,
>>
>> What I wanted to see is how something liek
>>
>> sub abcdefg( :$a, $b, :$c, :$e, $f, $g )
>>
>> would be called
>>
>> -T
>>
>
>
> --
> __
>
> :(){ :|:& };:
>
>

-- 
__

:(){ :|:& };:


Re: printf question

2020-02-10 Thread Timo Paulssen
Hi Paul and Todd,

just a little extra info: the limitation for nameds to come after
positionals is only for declarations of signatures.

Usage of subs/methods as well as capture literals (which you don't use
often, i imagine, so feel free to disregard) allow you to mix nameds and
positionals freely; it will handle named parameters that are put between
positionals as if they were after the positional parameters.

> sub abcdefg($b, $f, $g, :$a, :$c, :$e) { say $a, $b, $c, $e }   

> abcdefg(1, a => 5, 2, c => 99, 100, e => 1024)
51991024

Most cases where I wanted named parameters early in the call was when
there was something big in the call, for example if a sub takes a block
and a few options, i prefer to put the options before the block, so they
are visible at a glance rather than after scrolling. I suppose this
mirrors how regex modifiers (like :ignorecase / :i, :global, etc) have
been moved to the front of regexes.

Hope that's interesting
  - Timo

On 10/02/2020 07:48, Paul Procacci wrote:
> Named parameters must come after all positional parameters.
> Your example subroutine is invalid for this reason, while the
> following would be fine:
>
> sub abcdefg( $b, $f, $g, :$a, :$c, :$e)
>
> abcdefg("position1", "position2", "position3", :e("named_e"),
> :a("named_a"), :c("named_c"));
>
>
>
> On Sun, Feb 9, 2020 at 6:24 PM ToddAndMargo via perl6-users
> mailto:perl6-us...@perl.org>> wrote:
>
> On 2020-02-09 14:53, Paul Procacci wrote:
> > subchdir(IO() $path, :$d=True, :$r, :$w, :$x-->IO::Path:D)
>
> Hi Paul,
>
> What I wanted to see is how something liek
>
> sub abcdefg( :$a, $b, :$c, :$e, $f, $g )
>
> would be called
>
> -T
>
>
>
> -- 
> __
>
> :(){ :|:& };:


Re: printf question

2020-02-10 Thread ToddAndMargo via perl6-users

On 2020-02-09 22:48, Paul Procacci wrote:

Named parameters must come after all positional parameters.
Your example subroutine is invalid for this reason, while the following 
would be fine:


sub abcdefg( $b, $f, $g, :$a, :$c, :$e)

abcdefg("position1", "position2", "position3", :e("named_e"), 
:a("named_a"), :c("named_c"));




I understand now.  Thank you!


Re: printf question

2020-02-09 Thread Paul Procacci
Named parameters must come after all positional parameters.
Your example subroutine is invalid for this reason, while the following
would be fine:

sub abcdefg( $b, $f, $g, :$a, :$c, :$e)

abcdefg("position1", "position2", "position3", :e("named_e"),
:a("named_a"), :c("named_c"));



On Sun, Feb 9, 2020 at 6:24 PM ToddAndMargo via perl6-users <
perl6-us...@perl.org> wrote:

> On 2020-02-09 14:53, Paul Procacci wrote:
> > subchdir(IO() $path, :$d=True, :$r, :$w, :$x-->IO::Path:D)
>
> Hi Paul,
>
> What I wanted to see is how something liek
>
> sub abcdefg( :$a, $b, :$c, :$e, $f, $g )
>
> would be called
>
> -T
>


-- 
__

:(){ :|:& };:


Re: printf question

2020-02-09 Thread ToddAndMargo via perl6-users

On 2020-02-09 14:53, Paul Procacci wrote:

subchdir(IO() $path, :$d=True, :$r, :$w, :$x-->IO::Path:D)


Hi Paul,

What I wanted to see is how something liek

sub abcdefg( :$a, $b, :$c, :$e, $f, $g )

would be called

-T


Re: printf question

2020-02-09 Thread Paul Procacci
I think it's best that I show you examples from the official documentation.
Let's use chdir as our example.

https://docs.raku.org/routine/chdir

chdir has the following signature:

sub chdir(IO() $path, :$d = True, :$r, :$w, :$x --> IO::Path:D)


So let's break this down.

$path :: This is a positional parameter.  You know it's positional because
of a lack of preceding colon (:)
:$d :: This is a named parameter w/ a default value of True
:$r :: This is a named parameter
:$w :: This is a named parameter
:$x :: This is a named parameter

So let''s try it!

# Just the positional parameter
chdir('/tmp');

# Both positional and named parameter ':d' set to False
chdir('/tmp', :d(False));

# Again, both positional and named, but this time with named parameters
':d' set to False and ':x' set to True.  ':x' is enough to set to True ..
you can alternatively do a ':x(True)'.
chdir('/tmp', :d(False), :x;

# Same as last one, though named parameter order doesn't matter.
chdir('/tmp', :x, :d(False));

Now quickly imagine you had a variable set to False like the following:

my $d = False;

I could instead have written the above examples like the following (in the
order the above was written):

chdir('/tmp');
chdir('/tmp', :$d);
chdir('/tmp', :$d, :x);
chdir('/tmp', :x, :$d);


If you desire another example, please let me know.  I believe given your
latest comment and this latest example, that would be enough.
If not, I'll happily provide another one.

~Paul

On Sun, Feb 9, 2020 at 5:20 PM ToddAndMargo via perl6-users <
perl6-us...@perl.org> wrote:

> On 2020-02-08 15:39, Paul Procacci wrote:
> > sub a(:$a, :$b, :$c) {}
> >
> > a(:c(1), :a(0), :b(3));
>
> Hi Paul,
>
> I think I got it, but would yo give me one more exampale
> to make sure I fully understand?
>
> sub a(:$a, :$b, :$c) {}
>
> a(:c(1), :a(0), :b(3));
>
> But with two that are not named and two that are named.
> And what is the order?
>
>
> Many thanks,
> -T
>


-- 
__

:(){ :|:& };:


Re: printf question

2020-02-09 Thread ToddAndMargo via perl6-users

On 2020-02-08 15:39, Paul Procacci wrote:

sub a(:$a, :$b, :$c) {}

a(:c(1), :a(0), :b(3));


Hi Paul,

I think I got it, but would yo give me one more exampale
to make sure I fully understand?

sub a(:$a, :$b, :$c) {}

a(:c(1), :a(0), :b(3));

But with two that are not named and two that are named.
And what is the order?


Many thanks,
-T


Re: printf question

2020-02-08 Thread Paul Procacci
Named parameters are an important part of the raku language.
In fact, named parameters are used in several other languages as well.
It's in your best interest to learn how they work in order to use the
language properly.

sub a (:$a) {}
    This is a named parameter.

You know it's a named parameter because of the preceding colon (:).
What this means is in order for caller to pass this parameter to this
subroutine, it's necessary for
the caller to call it using a named parameter as an argument.

Here are two examples that utilize the named parameter of the subroutine I
just created above:

##

my $var = 'test';
a(:a($var));
    The named parameter

##

my $a = 'test';
a(:$a));
    The named parameter

##

In the first example, the value I wanted to pass to the named parameter was
stored in '$var'.
The syntax for passing this value to the named parameter as defined in the
subroutine is :a($var) ...
This is saying, pass the value stored in $var to the named parameter that
the subroutine expects as $a.

In the second example, the value I wanted to pass to the named parameter
was stored in '$a'.
The syntax for passing this value to the named parameter as defined in the
subroutine is :a($a)  or if you like shorthand  :$a
This is saying, pass the value stored in $a to the named parameter that the
subroutine expects as $a.

What you are accustomed to are positional parameters like the following:

sub a($a, $b, $c) {}

Positional parameters have to be passed in order ...

a(1,2,3);

Named parameters have a feature that order doesn't matter:

sub a(:$a, :$b, :$c) {}

a(:c(1), :a(0), :b(3));

This is advantageous in certain cases.  One such example is passing a bunch
of booleans though it's not limited to booleans as I've demonstrated in my
original post.
Anyways, learn named parameters.  It's essential to the raku programming
language.


On Sat, Feb 8, 2020 at 12:52 AM ToddAndMargo via perl6-users <
perl6-us...@perl.org> wrote:

> >> On Thu, Feb 6, 2020 at 11:43 AM ToddAndMargo via perl6-users
> >> mailto:perl6-us...@perl.org>> wrote:
> >>
> >> On 2020-02-05 20:12, Paul Procacci wrote:
> >>  > I wasn't going to follow up but decided to do so since there is a
> >> small
> >>  > but subtle bug in my original post.
> >>  > I wouldn't want to mislead you Todd.
> >>  >
> >>  > The \d has been changed to [0..9] as the expected input would
> >> only ever
> >>  > be in that range.  (\d includes Unicode Characters)
> >>  > I've also included an alignment parameter (shadow'ing the sub
> >> written by
> >>  > you Todd).
> >>  >
> >>  > sub sbprint( Int $n, Int :$alignment = 8) {
> >>  >  my Int $padding = $alignment + $n.msb - ( $n.msb +& (
> >>  > $alignment  - 1 ) );
> >>  >  '0b' ~ "\%0{$padding}b".sprintf($n).comb(/<[0..9]> ** {
> >>  > $alignment }/).join('_')
> >>  > }
> >>  >
> >>  > say sbprint 0x04F842;
> >>  > say sbprint 0x04F842, :alignment(4);
> >>  >
> >>  > # ./test.pl6
> >>  > 0b0100_1000_0110
> >>  > 0b0100__1000_0100_0010
> >>
> >>
> >> `Int :$alignment = 8` was inspired!
> >>
> >> What does the ":" do before `alignment`?
> >>
>
> On 2020-02-06 08:52, Paul Procacci wrote:
> > The subroutine I wrote defines a named parameter that goes by the name
> > alignment 'Int :$alignment'.
> > If the caller wants to call the callee using the given named parameter
> > there are several ways to so do   hence the ':alignment(4)'.
> >
> > If instead you have a variable already defined you can instead pass that
> > variable as a named parameter via something like the following:
> >
> > $alignment = 4;
> > sbprint 0x04F842, :$alignment;
> >
> >
> > The documentation goes into much more detail about named arguments.
> >
> > https://docs.raku.org/language/functions#Arguments
> >
>
> Sorry, went right over my head.  Thank you for trying anyway.
>


-- 
__

:(){ :|:& };:


Re: printf question

2020-02-07 Thread ToddAndMargo via perl6-users
On Thu, Feb 6, 2020 at 11:43 AM ToddAndMargo via perl6-users 
mailto:perl6-us...@perl.org>> wrote:


On 2020-02-05 20:12, Paul Procacci wrote:
 > I wasn't going to follow up but decided to do so since there is a
small
 > but subtle bug in my original post.
 > I wouldn't want to mislead you Todd.
 >
 > The \d has been changed to [0..9] as the expected input would
only ever
 > be in that range.  (\d includes Unicode Characters)
 > I've also included an alignment parameter (shadow'ing the sub
written by
 > you Todd).
 >
 > sub sbprint( Int $n, Int :$alignment = 8) {
 >  my Int $padding = $alignment + $n.msb - ( $n.msb +& (
 > $alignment  - 1 ) );
 >  '0b' ~ "\%0{$padding}b".sprintf($n).comb(/<[0..9]> ** {
 > $alignment }/).join('_')
 > }
 >
 > say sbprint 0x04F842;
 > say sbprint 0x04F842, :alignment(4);
 >
 > # ./test.pl6
 > 0b0100_1000_0110
 > 0b0100__1000_0100_0010


`Int :$alignment = 8` was inspired!

What does the ":" do before `alignment`?



On 2020-02-06 08:52, Paul Procacci wrote:
The subroutine I wrote defines a named parameter that goes by the name 
alignment 'Int :$alignment'.
If the caller wants to call the callee using the given named parameter 
there are several ways to so do   hence the ':alignment(4)'.


If instead you have a variable already defined you can instead pass that 
variable as a named parameter via something like the following:


$alignment = 4;
sbprint 0x04F842, :$alignment;


The documentation goes into much more detail about named arguments.

https://docs.raku.org/language/functions#Arguments



Sorry, went right over my head.  Thank you for trying anyway.


Re: printf question

2020-02-06 Thread Paul Procacci
The subroutine I wrote defines a named parameter that goes by the name
alignment 'Int :$alignment'.
If the caller wants to call the callee using the given named parameter
there are several ways to so do   hence the ':alignment(4)'.

If instead you have a variable already defined you can instead pass that
variable as a named parameter via something like the following:

$alignment = 4;
sbprint 0x04F842, :$alignment;


The documentation goes into much more detail about named arguments.

https://docs.raku.org/language/functions#Arguments


On Thu, Feb 6, 2020 at 11:43 AM ToddAndMargo via perl6-users <
perl6-us...@perl.org> wrote:

> On 2020-02-05 20:12, Paul Procacci wrote:
> > I wasn't going to follow up but decided to do so since there is a small
> > but subtle bug in my original post.
> > I wouldn't want to mislead you Todd.
> >
> > The \d has been changed to [0..9] as the expected input would only ever
> > be in that range.  (\d includes Unicode Characters)
> > I've also included an alignment parameter (shadow'ing the sub written by
> > you Todd).
> >
> > sub sbprint( Int $n, Int :$alignment = 8) {
> >  my Int $padding = $alignment + $n.msb - ( $n.msb +& (
> > $alignment  - 1 ) );
> >  '0b' ~ "\%0{$padding}b".sprintf($n).comb(/<[0..9]> ** {
> > $alignment }/).join('_')
> > }
> >
> > say sbprint 0x04F842;
> > say sbprint 0x04F842, :alignment(4);
> >
> > # ./test.pl6
> > 0b0100_1000_0110
> > 0b0100__1000_0100_0010
>
>
> `Int :$alignment = 8` was inspired!
>
> What does the ":" do before `alignment`?
>


-- 
__

:(){ :|:& };:


Re: printf question

2020-02-06 Thread ToddAndMargo via perl6-users

On 2020-02-05 20:12, Paul Procacci wrote:
I wasn't going to follow up but decided to do so since there is a small 
but subtle bug in my original post.

I wouldn't want to mislead you Todd.

The \d has been changed to [0..9] as the expected input would only ever 
be in that range.  (\d includes Unicode Characters)
I've also included an alignment parameter (shadow'ing the sub written by 
you Todd).


sub sbprint( Int $n, Int :$alignment = 8) {
         my Int $padding = $alignment + $n.msb - ( $n.msb +& ( 
$alignment  - 1 ) );
         '0b' ~ "\%0{$padding}b".sprintf($n).comb(/<[0..9]> ** { 
$alignment }/).join('_')

}

say sbprint 0x04F842;
say sbprint 0x04F842, :alignment(4);

# ./test.pl6
0b0100_1000_0110
0b0100__1000_0100_0010



`Int :$alignment = 8` was inspired!

What does the ":" do before `alignment`?


Re: printf question

2020-02-05 Thread ToddAndMargo via perl6-users

On 2020-02-05 20:12, Paul Procacci wrote:
I wasn't going to follow up but decided to do so since there is a small 
but subtle bug in my original post.

I wouldn't want to mislead you Todd.

The \d has been changed to [0..9] as the expected input would only ever 
be in that range.  (\d includes Unicode Characters)
I've also included an alignment parameter (shadow'ing the sub written by 
you Todd).


sub sbprint( Int $n, Int :$alignment = 8) {
         my Int $padding = $alignment + $n.msb - ( $n.msb +& ( 
$alignment  - 1 ) );
         '0b' ~ "\%0{$padding}b".sprintf($n).comb(/<[0..9]> ** { 
$alignment }/).join('_')

}

say sbprint 0x04F842;
say sbprint 0x04F842, :alignment(4);

# ./test.pl6
0b0100_1000_0110
0b0100__1000_0100_0010



I'm not suggesting you use my routine as I have no idea about what 
you're requirements are but wanted to be sure my contribution to your 
problem was sound.


Take Care.

On Wed, Feb 5, 2020 at 10:29 PM ToddAndMargo via perl6-users 
mailto:perl6-us...@perl.org>> wrote:


On 2020-02-03 13:51, ToddAndMargo via perl6-users wrote:
 > Hi All,
 >
 > Is ther a way to get
 >
 > $ p6 'my uint8 $u = 84; printf "\$u = <%08s>\n", $u;'
 > $u = <0084>
 >
 > to print
 >
 > $u = <_0084>
 >
 > ?
 >
 >
 > Many thanks,
 > -T

Hi All,

Just to torment myself, I wrote a sub to do this:

...
sub sbprint( UInt $b )  {
     my $bits  = $b.UInt.msb + 1;
     my $bytes = $bits div 8;
     if ($bits % 8 ) > 0  { $bytes += 1 };
     # say "bits = $bits   bytes = $bytes";
     my Str $bitstr = "";

     loop ( my $i = 0; $i < $bytes; $i += 1 )  {
        my $j = ( $b +> ( $i * 8 ) ) +& 0xFF;
        my $k = sprintf "_%08s", $j.base(2);
        # say "b = $b.base(2)   i = $i   j = $j.base(2)   k = $k";
        $bitstr = $k ~ $bitstr;
        # say $bitstr;
     }
     $bitstr = "0b" ~ $bitstr;
     $bitstr ~~ s/ 0b_ /0b/;
     return $bitstr;
}

say sbprint 0x04F842;
say 0x04F842.base(2);
...

$ intTest.pl6
0b0100_1000_0110
         100 1000 0110    # spaces added by me


I like it!


Re: printf question

2020-02-05 Thread Paul Procacci
I wasn't going to follow up but decided to do so since there is a small but
subtle bug in my original post.
I wouldn't want to mislead you Todd.

The \d has been changed to [0..9] as the expected input would only ever be
in that range.  (\d includes Unicode Characters)
I've also included an alignment parameter (shadow'ing the sub written by
you Todd).

sub sbprint( Int $n, Int :$alignment = 8) {
my Int $padding = $alignment + $n.msb - ( $n.msb +& ( $alignment  -
1 ) );
'0b' ~ "\%0{$padding}b".sprintf($n).comb(/<[0..9]> ** { $alignment
}/).join('_')
}

say sbprint 0x04F842;
say sbprint 0x04F842, :alignment(4);

# ./test.pl6
0b0100_1000_0110
0b0100__1000_0100_0010



I'm not suggesting you use my routine as I have no idea about what you're
requirements are but wanted to be sure my contribution to your problem was
sound.

Take Care.

On Wed, Feb 5, 2020 at 10:29 PM ToddAndMargo via perl6-users <
perl6-us...@perl.org> wrote:

> On 2020-02-03 13:51, ToddAndMargo via perl6-users wrote:
> > Hi All,
> >
> > Is ther a way to get
> >
> > $ p6 'my uint8 $u = 84; printf "\$u = <%08s>\n", $u;'
> > $u = <0084>
> >
> > to print
> >
> > $u = <_0084>
> >
> > ?
> >
> >
> > Many thanks,
> > -T
>
> Hi All,
>
> Just to torment myself, I wrote a sub to do this:
>
> ...
> sub sbprint( UInt $b )  {
> my $bits  = $b.UInt.msb + 1;
> my $bytes = $bits div 8;
> if ($bits % 8 ) > 0  { $bytes += 1 };
> # say "bits = $bits   bytes = $bytes";
> my Str $bitstr = "";
>
> loop ( my $i = 0; $i < $bytes; $i += 1 )  {
>my $j = ( $b +> ( $i * 8 ) ) +& 0xFF;
>my $k = sprintf "_%08s", $j.base(2);
># say "b = $b.base(2)   i = $i   j = $j.base(2)   k = $k";
>$bitstr = $k ~ $bitstr;
># say $bitstr;
> }
> $bitstr = "0b" ~ $bitstr;
> $bitstr ~~ s/ 0b_ /0b/;
> return $bitstr;
> }
>
> say sbprint 0x04F842;
> say 0x04F842.base(2);
> ...
>
> $ intTest.pl6
> 0b0100_1000_0110
> 100 1000 0110# spaces added by me
>


-- 
__

:(){ :|:& };:


Re: printf question

2020-02-05 Thread ToddAndMargo via perl6-users

On 2020-02-03 13:51, ToddAndMargo via perl6-users wrote:

Hi All,

Is ther a way to get

$ p6 'my uint8 $u = 84; printf "\$u = <%08s>\n", $u;'
$u = <0084>

to print

$u = <_0084>

?


Many thanks,
-T


Hi All,

Just to torment myself, I wrote a sub to do this:

...
sub sbprint( UInt $b )  {
   my $bits  = $b.UInt.msb + 1;
   my $bytes = $bits div 8;
   if ($bits % 8 ) > 0  { $bytes += 1 };
   # say "bits = $bits   bytes = $bytes";
   my Str $bitstr = "";

   loop ( my $i = 0; $i < $bytes; $i += 1 )  {
  my $j = ( $b +> ( $i * 8 ) ) +& 0xFF;
  my $k = sprintf "_%08s", $j.base(2);
  # say "b = $b.base(2)   i = $i   j = $j.base(2)   k = $k";
  $bitstr = $k ~ $bitstr;
  # say $bitstr;
   }
   $bitstr = "0b" ~ $bitstr;
   $bitstr ~~ s/ 0b_ /0b/;
   return $bitstr;
}

say sbprint 0x04F842;
say 0x04F842.base(2);
...

$ intTest.pl6
0b0100_1000_0110
   100 1000 0110# spaces added by me


Re: printf question

2020-02-05 Thread ToddAndMargo via perl6-users

On 2020-02-04 17:08, Paul Procacci wrote:

The only thing that's wrong is that you didn't account for leading zero's.
Your initial question has a type who's size is always 1 byte.
However your second question, the one where 'something is wrong' 
requires more bits of information to hold the given value.
You need to modify the sprintf to pad the binary number with the leading 
zeros  (Or you can look at Tom's module which I haven't done).


my $alignment = 8;
my $u = 0x4D4F;
my $padding = $alignment + $u.msb - ( $u.msb +& ( $alignment  - 1 ) );
say '$u = <0b' ~ "\%0{$padding}b".sprintf($u).comb(/\d ** 4/).join('_') 
~ '>;';


That explains it. Thank you!


Re: printf question

2020-02-05 Thread ToddAndMargo via perl6-users

On 2020-02-04 02:49, Tom Browder wrote:
On Tue, Feb 4, 2020 at 01:04 ToddAndMargo via perl6-users 
mailto:perl6-us...@perl.org>> wrote:

...

 >>     Who do I get it to print

 >>
 >>           0b0100_


Look at my module Text::Utils and its "commify" sub taken from "The Perl 
Cookbook." Its algorithm (similar to Paul's) should be able to do what 
you want.


-Tom




I will look!  Thank you


Re: printf question

2020-02-04 Thread Paul Procacci
The only thing that's wrong is that you didn't account for leading zero's.
Your initial question has a type who's size is always 1 byte.
However your second question, the one where 'something is wrong' requires
more bits of information to hold the given value.
You need to modify the sprintf to pad the binary number with the leading
zeros  (Or you can look at Tom's module which I haven't done).

my $alignment = 8;
my $u = 0x4D4F;
my $padding = $alignment + $u.msb - ( $u.msb +& ( $alignment  - 1 ) );
say '$u = <0b' ~ "\%0{$padding}b".sprintf($u).comb(/\d ** 4/).join('_') ~
'>;';


On Tue, Feb 4, 2020 at 2:04 AM ToddAndMargo via perl6-users <
perl6-us...@perl.org> wrote:

> >> On Mon, Feb 3, 2020 at 8:17 PM ToddAndMargo via perl6-users
> >> mailto:perl6-us...@perl.org>> wrote:
> >>
> >> On 2020-02-03 13:51, ToddAndMargo via perl6-users wrote:
> >>  > p6 'my uint8 $u = 84; printf "\$u = <%08s>\n", $u;'
> >>
> >> Oops, that should have been
> >>
> >> $ p6 'my uint8 $u = 0x4F; printf "\$u = <%#b>\n", $u;'
> >> $u = <0b100>
> >>
> >> Who do I get it to print
> >>
> >>   0b0100_
> >>
> >> ?
> >>
> >> -T
> >>
>
> On 2020-02-03 20:28, Paul Procacci wrote:
> > Here's one way
> >
> > my uint8 $u = 0x4F;
> > say '$u = <0b' ~ '%08b'.sprintf($u).comb(/\d ** 4/).join('_') ~ '>;';
> >
> >
> > There's probably others as well.
>
> Hi Paul,
>
> Something is wrong.  Dang!
>
> -T
>
>
>  > my $u = 0x4D4F; say '$u = <0b' ~ '%08b'.sprintf($u).comb(/\d **
> 4/).join('_') ~ '>;';
> $u = <0b1001_1010_1001>;
>
>  > say 0b1001_1010_1001.base(16)
> 9A9
>
>
>  > my $u = 0x3D4F; say '$u = <0b' ~ '%08b'.sprintf($u).comb(/\d **
> 4/).join('_') ~ '>;';
> $u = <0b_0101_0011>;
>
>  > say 0b_0101_0011.base(16)
> F53
>


-- 
__

:(){ :|:& };:


Re: printf question

2020-02-04 Thread Tom Browder
On Tue, Feb 4, 2020 at 01:04 ToddAndMargo via perl6-users <
perl6-us...@perl.org> wrote:
...

> >> Who do I get it to print

>>
> >>   0b0100_


Look at my module Text::Utils and its "commify" sub taken from "The Perl
Cookbook." Its algorithm (similar to Paul's) should be able to do what you
want.

-Tom


Re: printf question

2020-02-03 Thread ToddAndMargo via perl6-users
On Mon, Feb 3, 2020 at 8:17 PM ToddAndMargo via perl6-users 
mailto:perl6-us...@perl.org>> wrote:


On 2020-02-03 13:51, ToddAndMargo via perl6-users wrote:
 > p6 'my uint8 $u = 84; printf "\$u = <%08s>\n", $u;'

Oops, that should have been

$ p6 'my uint8 $u = 0x4F; printf "\$u = <%#b>\n", $u;'
$u = <0b100>

Who do I get it to print

  0b0100_

?

-T



On 2020-02-03 20:28, Paul Procacci wrote:

Here's one way

my uint8 $u = 0x4F;
say '$u = <0b' ~ '%08b'.sprintf($u).comb(/\d ** 4/).join('_') ~ '>;';


There's probably others as well.


Hi Paul,

Something is wrong.  Dang!

-T


> my $u = 0x4D4F; say '$u = <0b' ~ '%08b'.sprintf($u).comb(/\d ** 
4/).join('_') ~ '>;';

$u = <0b1001_1010_1001>;

> say 0b1001_1010_1001.base(16)
9A9


> my $u = 0x3D4F; say '$u = <0b' ~ '%08b'.sprintf($u).comb(/\d ** 
4/).join('_') ~ '>;';

$u = <0b_0101_0011>;

> say 0b_0101_0011.base(16)
F53


Re: printf question

2020-02-03 Thread Paul Procacci
Here's one way

my uint8 $u = 0x4F;
say '$u = <0b' ~ '%08b'.sprintf($u).comb(/\d ** 4/).join('_') ~ '>;';


There's probably others as well.

On Mon, Feb 3, 2020 at 8:17 PM ToddAndMargo via perl6-users <
perl6-us...@perl.org> wrote:

> On 2020-02-03 13:51, ToddAndMargo via perl6-users wrote:
> > p6 'my uint8 $u = 84; printf "\$u = <%08s>\n", $u;'
>
> Oops, that should have been
>
> $ p6 'my uint8 $u = 0x4F; printf "\$u = <%#b>\n", $u;'
> $u = <0b100>
>
> Who do I get it to print
>
>  0b0100_
>
> ?
>
> -T
>


-- 
__

:(){ :|:& };:


Re: printf question

2020-02-03 Thread ToddAndMargo via perl6-users

On 2020-02-03 13:51, ToddAndMargo via perl6-users wrote:

p6 'my uint8 $u = 84; printf "\$u = <%08s>\n", $u;'


Oops, that should have been

$ p6 'my uint8 $u = 0x4F; printf "\$u = <%#b>\n", $u;'
$u = <0b100>

Who do I get it to print

0b0100_

?

-T


Re: printf question

2020-02-03 Thread ToddAndMargo via perl6-users
On Mon, Feb 3, 2020 at 3:52 PM ToddAndMargo via perl6-users 
mailto:perl6-us...@perl.org>> wrote:


Hi All,

Is ther a way to get

$ p6 'my uint8 $u = 84; printf "\$u = <%08s>\n", $u;'
$u = <0084>

to print

$u = <_0084>

?


Many thanks,
-T



On 2020-02-03 14:13, yary wrote:

I think you need a more specific question...
p6 'my uint8 $u = 84; printf "\$u = <_%04s>\n", $u;'

-y




Hi Yary,

That is printing out in base 10.

$ p6 'my uint8 $u = 84; printf "\$u = <_%04s>\n", $u;'
$u = <_0084>

Trying that with base 2 gives me

$ p6 'my uint8 $u = 84; printf "\$u = <_%04b>\n", $u;'
$u = <_1010100>

"_" is in the wrong place.  I want an under score every four bits.

:'(

-T


Re: printf question

2020-02-03 Thread yary
I think you need a more specific question...
p6 'my uint8 $u = 84; printf "\$u = <_%04s>\n", $u;'

-y


On Mon, Feb 3, 2020 at 3:52 PM ToddAndMargo via perl6-users <
perl6-us...@perl.org> wrote:

> Hi All,
>
> Is ther a way to get
>
> $ p6 'my uint8 $u = 84; printf "\$u = <%08s>\n", $u;'
> $u = <0084>
>
> to print
>
> $u = <_0084>
>
> ?
>
>
> Many thanks,
> -T
>


Re: rmdir question

2019-12-03 Thread Timo Paulssen
On 03/12/2019 04:46, Paul Procacci wrote:
> On success it return a Bool::True.
> On failure it throws an exception.
> It doesn't crash the program.
> If you are interested in handling the exception, add logic to handle it.
>
> Examples:
> ---
> # mkdir a ; `which perl6` -e "'a'.IO.rmdir.perl.say"
> Bool::True
> # mkdir a ; `which perl6` -e "'b'.IO.rmdir.perl.say"
> Failure.new(exception => X::IO::Rmdir.new(path => "/root/test/b",
> os-error => "Failed to rmdir: no such file or directory"), backtrace
> => Backtrace.new)
> # mkdir a ; `which perl6` -e "try { 'b'.IO.rmdir.perl.say; CATCH {
> default { 'tsk tsk'.say }}}"
> tsk tsk


Hi Paul,

thanks to your email I found and fixed an oversight in the Raku docs:

it says it throws an exception, when actually it returns a Failure.

Thank you!
  - Timo


Re: rmdir question

2019-12-02 Thread ToddAndMargo via perl6-users
On Mon, Dec 2, 2019 at 9:39 PM ToddAndMargo via perl6-users 
mailto:perl6-us...@perl.org>> wrote:


Hi All,

  From the manual page of rmdir:
https://docs.perl6.org/routine/rmdir

subrmdir(*@dirs --> List:D)
method rmdir(IO::Path:D: --> True)

Does *@dirs mean I can give it multiple directories
as an array?

What does  "--> List:D" give me back?  An array
of Booleans as to which directories successfully removed?
And what is a "List:D?" anyway?


   ...throws an exception of type X::IO::Rmdir if
   the directory cannot be removed

Does this crash the program or just return a "false"?
Does it tell me what went wrong, as in "so and so" has
"such and such" file(s) open and locked?

To delete non-empty directory, see rmtree in File::Directory::Tree
module.

Seems to me I should not have to import a module for
this.  Most rmdir command have a "parents" flag.  Am
I missing something?

Many thanks,
-T


On 2019-12-02 19:46, Paul Procacci wrote:
It seems to me all your questions are answered by the very documentation 
you referenced.


 >> Does *@dirs mean I can give it multiple directories as an array?

Remove the invocant   in sub form  of the provided directories 
in the given list .


Example:
-
# mkdir {a,b} ; ls -ld a b ; `which perl6` -e "rmdir('a','b')" ; ls -ld a b
drwxr-xr-x  2 root  wheel  2 Dec  2 22:22 a
drwxr-xr-x  2 root  wheel  2 Dec  2 22:22 b
ls: a: No such file or directory
ls: b: No such file or directory


 >> What does  "--> List:D" give me back?

It gives you back a list of directories that it successfully removed.
Example:

# mkdir a ; ls -ld a b ; `which perl6` -e "rmdir('a','b').perl.say"
ls: b: No such file or directory
drwxr-xr-x  2 root  wheel  2 Dec  2 22:23 a
["a"]
# mkdir {a,b} ; ls -ld a b ; `which perl6` -e "rmdir('a','b').perl.say"
drwxr-xr-x  2 root  wheel  2 Dec  2 22:23 a
drwxr-xr-x  2 root  wheel  2 Dec  2 22:23 b
["a", "b"]

 >> And what is a "List:D?" anyway?

https://docs.perl6.org/type/Signature#Constraining_argument_definiteness

The above link explains it fully.  Though it uses "Int:D" as an example 
it still applies.


 >>      ...throws an exception of type X::IO::Rmdir if
 >>     the directory cannot be removed
 >>
 >> Does this crash the program or just return a "false"?

On success it return a Bool::True.
On failure it throws an exception.
It doesn't crash the program.
If you are interested in handling the exception, add logic to handle it.

Examples:
---
# mkdir a ; `which perl6` -e "'a'.IO.rmdir.perl.say"
Bool::True
# mkdir a ; `which perl6` -e "'b'.IO.rmdir.perl.say"
Failure.new(exception => X::IO::Rmdir.new(path => "/root/test/b", 
os-error => "Failed to rmdir: no such file or directory"), backtrace => 
Backtrace.new)
# mkdir a ; `which perl6` -e "try { 'b'.IO.rmdir.perl.say; CATCH { 
default { 'tsk tsk'.say }}}"

tsk tsk


 >> Does it tell me what went wrong, as in "so and so" has "such and 
such" file(s) open and locked?

See previous example.  It throws an exception with a detailed error message.

 >> To delete non-empty directory, see rmtree in File::Directory::Tree 
module.

 >>
 >> Seems to me I should not have to import a module for
 >> this.  Most rmdir command have a "parents" flag.  Am
 >> I missing something?

It's true that most binaries with the name rmdir have a p switch for 
removing "empty directories" which I won't argue could be added to perl6 
proper.
That documentation you are referencing though is concerning "non-empty 
directories" and there no such flag for any rmdir binary I've seen.


~Paul



Thank you!


Re: rmdir question

2019-12-02 Thread Paul Procacci
It seems to me all your questions are answered by the very documentation
you referenced.

>> Does *@dirs mean I can give it multiple directories as an array?

Remove the invocant   in sub form  of the provided directories in
the given list .

Example:
-
# mkdir {a,b} ; ls -ld a b ; `which perl6` -e "rmdir('a','b')" ; ls -ld a b
drwxr-xr-x  2 root  wheel  2 Dec  2 22:22 a
drwxr-xr-x  2 root  wheel  2 Dec  2 22:22 b
ls: a: No such file or directory
ls: b: No such file or directory


>> What does  "--> List:D" give me back?

It gives you back a list of directories that it successfully removed.
Example:

# mkdir a ; ls -ld a b ; `which perl6` -e "rmdir('a','b').perl.say"
ls: b: No such file or directory
drwxr-xr-x  2 root  wheel  2 Dec  2 22:23 a
["a"]
# mkdir {a,b} ; ls -ld a b ; `which perl6` -e "rmdir('a','b').perl.say"
drwxr-xr-x  2 root  wheel  2 Dec  2 22:23 a
drwxr-xr-x  2 root  wheel  2 Dec  2 22:23 b
["a", "b"]

>> And what is a "List:D?" anyway?

https://docs.perl6.org/type/Signature#Constraining_argument_definiteness

The above link explains it fully.  Though it uses "Int:D" as an example it
still applies.

>>  ...throws an exception of type X::IO::Rmdir if
>> the directory cannot be removed
>>
>> Does this crash the program or just return a "false"?

On success it return a Bool::True.
On failure it throws an exception.
It doesn't crash the program.
If you are interested in handling the exception, add logic to handle it.

Examples:
---
# mkdir a ; `which perl6` -e "'a'.IO.rmdir.perl.say"
Bool::True
# mkdir a ; `which perl6` -e "'b'.IO.rmdir.perl.say"
Failure.new(exception => X::IO::Rmdir.new(path => "/root/test/b", os-error
=> "Failed to rmdir: no such file or directory"), backtrace =>
Backtrace.new)
# mkdir a ; `which perl6` -e "try { 'b'.IO.rmdir.perl.say; CATCH { default
{ 'tsk tsk'.say }}}"
tsk tsk


>> Does it tell me what went wrong, as in "so and so" has "such and such"
file(s) open and locked?
See previous example.  It throws an exception with a detailed error message.

>> To delete non-empty directory, see rmtree in File::Directory::Tree
module.
>>
>> Seems to me I should not have to import a module for
>> this.  Most rmdir command have a "parents" flag.  Am
>> I missing something?

It's true that most binaries with the name rmdir have a p switch for
removing "empty directories" which I won't argue could be added to perl6
proper.
That documentation you are referencing though is concerning "non-empty
directories" and there no such flag for any rmdir binary I've seen.

~Paul

On Mon, Dec 2, 2019 at 9:39 PM ToddAndMargo via perl6-users <
perl6-us...@perl.org> wrote:

> Hi All,
>
>  From the manual page of rmdir:
> https://docs.perl6.org/routine/rmdir
>
>subrmdir(*@dirs --> List:D)
>method rmdir(IO::Path:D: --> True)
>
> Does *@dirs mean I can give it multiple directories
> as an array?
>
> What does  "--> List:D" give me back?  An array
> of Booleans as to which directories successfully removed?
> And what is a "List:D?" anyway?
>
>
>   ...throws an exception of type X::IO::Rmdir if
>   the directory cannot be removed
>
> Does this crash the program or just return a "false"?
> Does it tell me what went wrong, as in "so and so" has
> "such and such" file(s) open and locked?
>
> To delete non-empty directory, see rmtree in File::Directory::Tree module.
>
> Seems to me I should not have to import a module for
> this.  Most rmdir command have a "parents" flag.  Am
> I missing something?
>
> Many thanks,
> -T
>
>
>
> --
> 
> A computer without Microsoft is like
> a chocolate cake without the mustard
> 
>


-- 
__

:(){ :|:& };:


Re: **@args question

2019-01-04 Thread ToddAndMargo via perl6-users

On 1/3/19 12:43 AM, Richard Hainsworth wrote:




The term "slurpy" did help a lot.

:-)

I am writing your explanation down for my records.



Well Golly!

$ p6 'sub printx(**@args){print(@args)}; printx("abc",1,"def\n");'
abc 1 def

$ p6 'sub printx(**@args){print @args, "\n"}; printx("abc",1,"def");'
abc 1 def

Question:
$ p6 'sub printx(**@args){print(@args)}; printx("abc","xyz","def\n");'
abc xyz def

Are the spaces suppose to be there?


In each case you are using 'print @args', then `printx` adds on a "\n" 
either to the last item or the final string, which in each case results 
in exactly the same string. The way 'print' handles an array is to put a 
space between each item, which can be very confusing when dealing with 
items that are themselves strings with spaces.


For other "stringifications" of an array, try 'print @args.fmt("%s,")' 
if you want a comma, or 'print @args.perl'.


I find '.say for @args' is better because I get an item on each line.

Also 'dd @args' is quite useful.



Thank you!


Re: **@args question

2019-01-04 Thread ToddAndMargo via perl6-users

On 1/4/19 11:39 AM, ToddAndMargo via perl6-users wrote:

On 1/3/19 2:58 AM, Brad Gilbert wrote:

On Thu, Jan 3, 2019 at 12:43 AM ToddAndMargo via perl6-users
 wrote:


On 1/2/19 10:17 PM, ToddAndMargo via perl6-users wrote:

  > On Wed, Jan 2, 2019 at 8:41 PM ToddAndMargo via perl6-users
  >  wrote:
  >>
  >> Hi All,
  >>
  >> Looking at
  >>
  >>  https://docs.perl6.org/routine/print
  >>
  >> I see
  >>
  >>  multi sub print(**@args --> True)
  >>
  >> Question.  If I wanted to create my own print routine
  >> using **@args, how would I declare it?
  >>
  >>  sub printx( **@args data ) {...}
  >>
  >>
  >> Many thanks,
  >> -T


On 1/2/19 10:06 PM, Brad Gilbert wrote:

The variable name in :(**@args) is @args, it could be any valid array
identifier like @data

  sub printx( **@data ){…}

Note that there are several forms for slurpy positional arguments.

  :(   @a ) # not slurpy at all, takes one Positional argument and
aliases it as @a.

  :(  *@a ) # flattening slurpy  (1,),2,3 → 1,2,3 and ((1,),2,3) →
1,2,3
  :( **@a ) # structured slurpy (1,),2,3 → (1,),2,3 and 
((1,),2,3) →

((1,),2,3) # note there is no change
  :(  +@a ) # one-arg rule slurpy (1,),2,3 → (1,),2,3 and 
((1,),2,3)

→ (1,),2,3 # note that the second one changes

Note that itemized values do not get flattened for :(*@a), and that
Array values are itemized.

I like to consider the one-arg rule slurpy :(+@a) to be like a
combination between non-slurpy :(@a) and structured slurpy :(**@a)
That is a one-arg rule slurpy will sometimes be like an alias to a
singular positional, otherwise it will act like a structured slurpy.

Note that all but the [aliasing] non-slurpy :(@a) are [almost] always
Array's.

---

The one-arg rule slurpy is the oddest one of the bunch so here is some
brief information:

The one-arg rule slurpy can be sigiless :(+a), in which case it will
be a List instead of an Array or an alias to the single argument
depending on what it was.

  sub one-arg-rule ( +args ){
  say args.^name, " # ", args.perl;
  }

  one-arg-rule(  (1,),2,3  ); # List # ((1,), 2, 3)
  one-arg-rule( ((1,),2,3) ); # List # ((1,), 2, 3) # one-arg rule
  one-arg-rule( ((1,),2,3).Seq ); # Seq # ((1,), 2, 3).Seq #
one-arg rule
  one-arg-rule(  1..3   ); # List # (1, 2, 3)
  one-arg-rule( (1..3,) ); # List # (1..3,)

  sub one-arg-Array ( +@args ){
  say @args.^name, " # ", @args.perl;
  }

  one-arg-Array(  (1,),2,3  ); # Array # [(1,), 2, 3]
  one-arg-Array( ((1,),2,3) ); # Array # [(1,), 2, 3]
  one-arg-Array( ((1,),2,3).Seq ); # List # ((1,), 2, 3)
  one-arg-Array(  1..3   ); # Array # [1, 2, 3]
  one-arg-Array( (1..3,) ); # Array # [1..3,]

The one-arg rule exists because people tend to write the following:

  my @a = [1,2,3];

When the correct way to write it is:

  my @a = 1,2,3;

There are various other places where the one-arg rule is also used, so
it was made available to everyone.

---

Don't get too flustered if you don't understand all of the nuances, it
take everybody a while to understand them.



Thank you!

The term "slurpy" did help a lot.

:-)

I am writing your explanation down for my records.



Well Golly!

$ p6 'sub printx(**@args){print(@args)}; printx("abc",1,"def\n");'
abc 1 def

$ p6 'sub printx(**@args){print @args, "\n"}; printx("abc",1,"def");'
abc 1 def

Question:
$ p6 'sub printx(**@args){print(@args)}; printx("abc","xyz","def\n");'
abc xyz def

Are the spaces suppose to be there?


The spaces are there because you are passing `@args` to `print` as a
single value.
`print` coerces all its values to `Str` before printing, and an Array
adds spaces between elements when turned into a Str.

Simple fix use `|@args` to Slip it into the call to `print`

 $ p6 'sub printx(**@args){print( |@args, "\n" )};
printx("abc","xyz","def");'
 abcxyzdef



$ p6 'sub printx(**@args){print(|@args)}; printx("abc", "xyz","def\n");'
abcxyzdef

Sweet!  Thank you!



Follow up:


unit module PrintColors;

#`{

 There subs give you the ability to print to the stand output and 
standard error

 with color.

 To use these, place the following at the top(ish) of your program
use lib "/home/linuxutil";
use PrintColors;  # qx[ PrintRed  PrintGreen PrintBlue PrintErr 
PrintRedErr PrintGreenErr PrintBlueErr ]


}

use Terminal::ANSIColor;  # qx[ color ];

sub PrintRed   ( **@args ) is export { print color('bold'), 
color('red'),   |@args, color('reset'); }
sub PrintGreen ( **@args ) is export { print color('bold'), 
color('green'), |@args, color('reset'); }
sub PrintBlue  ( **@args ) is export { print color('bold'), 
color('blue'),  |@args, color('reset'); }


sub PrintErr   ( **@args ) is export { $*ERR.print: |@args; }

sub PrintRedErr   ( **@args ) is export { $*ERR.print: color('bold'), 
color('red'),   |@args, color('reset'); }
sub PrintGreenErr ( **@args ) is export { $*ERR.print: color('bold'), 

Re: **@args question

2019-01-04 Thread ToddAndMargo via perl6-users

On 1/3/19 2:58 AM, Brad Gilbert wrote:

On Thu, Jan 3, 2019 at 12:43 AM ToddAndMargo via perl6-users
 wrote:


On 1/2/19 10:17 PM, ToddAndMargo via perl6-users wrote:

  > On Wed, Jan 2, 2019 at 8:41 PM ToddAndMargo via perl6-users
  >  wrote:
  >>
  >> Hi All,
  >>
  >> Looking at
  >>
  >>  https://docs.perl6.org/routine/print
  >>
  >> I see
  >>
  >>  multi sub print(**@args --> True)
  >>
  >> Question.  If I wanted to create my own print routine
  >> using **@args, how would I declare it?
  >>
  >>  sub printx( **@args data ) {...}
  >>
  >>
  >> Many thanks,
  >> -T


On 1/2/19 10:06 PM, Brad Gilbert wrote:

The variable name in :(**@args) is @args, it could be any valid array
identifier like @data

  sub printx( **@data ){…}

Note that there are several forms for slurpy positional arguments.

  :(   @a ) # not slurpy at all, takes one Positional argument and
aliases it as @a.

  :(  *@a ) # flattening slurpy  (1,),2,3 → 1,2,3 and ((1,),2,3) →
1,2,3
  :( **@a ) # structured slurpy (1,),2,3 → (1,),2,3 and ((1,),2,3) →
((1,),2,3) # note there is no change
  :(  +@a ) # one-arg rule slurpy (1,),2,3 → (1,),2,3 and ((1,),2,3)
→ (1,),2,3 # note that the second one changes

Note that itemized values do not get flattened for :(*@a), and that
Array values are itemized.

I like to consider the one-arg rule slurpy :(+@a) to be like a
combination between non-slurpy :(@a) and structured slurpy :(**@a)
That is a one-arg rule slurpy will sometimes be like an alias to a
singular positional, otherwise it will act like a structured slurpy.

Note that all but the [aliasing] non-slurpy :(@a) are [almost] always
Array's.

---

The one-arg rule slurpy is the oddest one of the bunch so here is some
brief information:

The one-arg rule slurpy can be sigiless :(+a), in which case it will
be a List instead of an Array or an alias to the single argument
depending on what it was.

  sub one-arg-rule ( +args ){
  say args.^name, " # ", args.perl;
  }

  one-arg-rule(  (1,),2,3  ); # List # ((1,), 2, 3)
  one-arg-rule( ((1,),2,3) ); # List # ((1,), 2, 3) # one-arg rule
  one-arg-rule( ((1,),2,3).Seq ); # Seq # ((1,), 2, 3).Seq #
one-arg rule
  one-arg-rule(  1..3   ); # List # (1, 2, 3)
  one-arg-rule( (1..3,) ); # List # (1..3,)

  sub one-arg-Array ( +@args ){
  say @args.^name, " # ", @args.perl;
  }

  one-arg-Array(  (1,),2,3  ); # Array # [(1,), 2, 3]
  one-arg-Array( ((1,),2,3) ); # Array # [(1,), 2, 3]
  one-arg-Array( ((1,),2,3).Seq ); # List # ((1,), 2, 3)
  one-arg-Array(  1..3   ); # Array # [1, 2, 3]
  one-arg-Array( (1..3,) ); # Array # [1..3,]

The one-arg rule exists because people tend to write the following:

  my @a = [1,2,3];

When the correct way to write it is:

  my @a = 1,2,3;

There are various other places where the one-arg rule is also used, so
it was made available to everyone.

---

Don't get too flustered if you don't understand all of the nuances, it
take everybody a while to understand them.



Thank you!

The term "slurpy" did help a lot.

:-)

I am writing your explanation down for my records.



Well Golly!

$ p6 'sub printx(**@args){print(@args)}; printx("abc",1,"def\n");'
abc 1 def

$ p6 'sub printx(**@args){print @args, "\n"}; printx("abc",1,"def");'
abc 1 def

Question:
$ p6 'sub printx(**@args){print(@args)}; printx("abc","xyz","def\n");'
abc xyz def

Are the spaces suppose to be there?


The spaces are there because you are passing `@args` to `print` as a
single value.
`print` coerces all its values to `Str` before printing, and an Array
adds spaces between elements when turned into a Str.

Simple fix use `|@args` to Slip it into the call to `print`

 $ p6 'sub printx(**@args){print( |@args, "\n" )};
printx("abc","xyz","def");'
 abcxyzdef



$ p6 'sub printx(**@args){print(|@args)}; printx("abc", "xyz","def\n");'
abcxyzdef

Sweet!  Thank you!

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


Re: **@args question

2019-01-03 Thread Brad Gilbert
On Thu, Jan 3, 2019 at 12:43 AM ToddAndMargo via perl6-users
 wrote:
>
> On 1/2/19 10:17 PM, ToddAndMargo via perl6-users wrote:
> >  > On Wed, Jan 2, 2019 at 8:41 PM ToddAndMargo via perl6-users
> >  >  wrote:
> >  >>
> >  >> Hi All,
> >  >>
> >  >> Looking at
> >  >>
> >  >>  https://docs.perl6.org/routine/print
> >  >>
> >  >> I see
> >  >>
> >  >>  multi sub print(**@args --> True)
> >  >>
> >  >> Question.  If I wanted to create my own print routine
> >  >> using **@args, how would I declare it?
> >  >>
> >  >>  sub printx( **@args data ) {...}
> >  >>
> >  >>
> >  >> Many thanks,
> >  >> -T
> >
> >
> > On 1/2/19 10:06 PM, Brad Gilbert wrote:
> >> The variable name in :(**@args) is @args, it could be any valid array
> >> identifier like @data
> >>
> >>  sub printx( **@data ){…}
> >>
> >> Note that there are several forms for slurpy positional arguments.
> >>
> >>  :(   @a ) # not slurpy at all, takes one Positional argument and
> >> aliases it as @a.
> >>
> >>  :(  *@a ) # flattening slurpy  (1,),2,3 → 1,2,3 and ((1,),2,3) →
> >> 1,2,3
> >>  :( **@a ) # structured slurpy (1,),2,3 → (1,),2,3 and ((1,),2,3) →
> >> ((1,),2,3) # note there is no change
> >>  :(  +@a ) # one-arg rule slurpy (1,),2,3 → (1,),2,3 and ((1,),2,3)
> >> → (1,),2,3 # note that the second one changes
> >>
> >> Note that itemized values do not get flattened for :(*@a), and that
> >> Array values are itemized.
> >>
> >> I like to consider the one-arg rule slurpy :(+@a) to be like a
> >> combination between non-slurpy :(@a) and structured slurpy :(**@a)
> >> That is a one-arg rule slurpy will sometimes be like an alias to a
> >> singular positional, otherwise it will act like a structured slurpy.
> >>
> >> Note that all but the [aliasing] non-slurpy :(@a) are [almost] always
> >> Array's.
> >>
> >> ---
> >>
> >> The one-arg rule slurpy is the oddest one of the bunch so here is some
> >> brief information:
> >>
> >> The one-arg rule slurpy can be sigiless :(+a), in which case it will
> >> be a List instead of an Array or an alias to the single argument
> >> depending on what it was.
> >>
> >>  sub one-arg-rule ( +args ){
> >>  say args.^name, " # ", args.perl;
> >>  }
> >>
> >>  one-arg-rule(  (1,),2,3  ); # List # ((1,), 2, 3)
> >>  one-arg-rule( ((1,),2,3) ); # List # ((1,), 2, 3) # one-arg rule
> >>  one-arg-rule( ((1,),2,3).Seq ); # Seq # ((1,), 2, 3).Seq #
> >> one-arg rule
> >>  one-arg-rule(  1..3   ); # List # (1, 2, 3)
> >>  one-arg-rule( (1..3,) ); # List # (1..3,)
> >>
> >>  sub one-arg-Array ( +@args ){
> >>  say @args.^name, " # ", @args.perl;
> >>  }
> >>
> >>  one-arg-Array(  (1,),2,3  ); # Array # [(1,), 2, 3]
> >>  one-arg-Array( ((1,),2,3) ); # Array # [(1,), 2, 3]
> >>  one-arg-Array( ((1,),2,3).Seq ); # List # ((1,), 2, 3)
> >>  one-arg-Array(  1..3   ); # Array # [1, 2, 3]
> >>  one-arg-Array( (1..3,) ); # Array # [1..3,]
> >>
> >> The one-arg rule exists because people tend to write the following:
> >>
> >>  my @a = [1,2,3];
> >>
> >> When the correct way to write it is:
> >>
> >>  my @a = 1,2,3;
> >>
> >> There are various other places where the one-arg rule is also used, so
> >> it was made available to everyone.
> >>
> >> ---
> >>
> >> Don't get too flustered if you don't understand all of the nuances, it
> >> take everybody a while to understand them.
> >>
> >
> > Thank you!
> >
> > The term "slurpy" did help a lot.
> >
> > :-)
> >
> > I am writing your explanation down for my records.
>
>
> Well Golly!
>
> $ p6 'sub printx(**@args){print(@args)}; printx("abc",1,"def\n");'
> abc 1 def
>
> $ p6 'sub printx(**@args){print @args, "\n"}; printx("abc",1,"def");'
> abc 1 def
>
> Question:
> $ p6 'sub printx(**@args){print(@args)}; printx("abc","xyz","def\n");'
> abc xyz def
>
> Are the spaces suppose to be there?

The spaces are there because you are passing `@args` to `print` as a
single value.
`print` coerces all its values to `Str` before printing, and an Array
adds spaces between elements when turned into a Str.

Simple fix use `|@args` to Slip it into the call to `print`

$ p6 'sub printx(**@args){print( |@args, "\n" )};
printx("abc","xyz","def");'
abcxyzdef


Re: **@args question

2019-01-03 Thread Richard Hainsworth




The term "slurpy" did help a lot.

:-)

I am writing your explanation down for my records.



Well Golly!

$ p6 'sub printx(**@args){print(@args)}; printx("abc",1,"def\n");'
abc 1 def

$ p6 'sub printx(**@args){print @args, "\n"}; printx("abc",1,"def");'
abc 1 def

Question:
$ p6 'sub printx(**@args){print(@args)}; printx("abc","xyz","def\n");'
abc xyz def

Are the spaces suppose to be there?


In each case you are using 'print @args', then `printx` adds on a "\n" 
either to the last item or the final string, which in each case results 
in exactly the same string. The way 'print' handles an array is to put a 
space between each item, which can be very confusing when dealing with 
items that are themselves strings with spaces.


For other "stringifications" of an array, try 'print @args.fmt("%s,")' 
if you want a comma, or 'print @args.perl'.


I find '.say for @args' is better because I get an item on each line.

Also 'dd @args' is quite useful.


Re: **@args question

2019-01-02 Thread ToddAndMargo via perl6-users

On 1/2/19 10:17 PM, ToddAndMargo via perl6-users wrote:

 > On Wed, Jan 2, 2019 at 8:41 PM ToddAndMargo via perl6-users
 >  wrote:
 >>
 >> Hi All,
 >>
 >> Looking at
 >>
 >>  https://docs.perl6.org/routine/print
 >>
 >> I see
 >>
 >>  multi sub print(**@args --> True)
 >>
 >> Question.  If I wanted to create my own print routine
 >> using **@args, how would I declare it?
 >>
 >>  sub printx( **@args data ) {...}
 >>
 >>
 >> Many thanks,
 >> -T


On 1/2/19 10:06 PM, Brad Gilbert wrote:

The variable name in :(**@args) is @args, it could be any valid array
identifier like @data

 sub printx( **@data ){…}

Note that there are several forms for slurpy positional arguments.

 :(   @a ) # not slurpy at all, takes one Positional argument and
aliases it as @a.

 :(  *@a ) # flattening slurpy  (1,),2,3 → 1,2,3 and ((1,),2,3) → 
1,2,3

 :( **@a ) # structured slurpy (1,),2,3 → (1,),2,3 and ((1,),2,3) →
((1,),2,3) # note there is no change
 :(  +@a ) # one-arg rule slurpy (1,),2,3 → (1,),2,3 and ((1,),2,3)
→ (1,),2,3 # note that the second one changes

Note that itemized values do not get flattened for :(*@a), and that
Array values are itemized.

I like to consider the one-arg rule slurpy :(+@a) to be like a
combination between non-slurpy :(@a) and structured slurpy :(**@a)
That is a one-arg rule slurpy will sometimes be like an alias to a
singular positional, otherwise it will act like a structured slurpy.

Note that all but the [aliasing] non-slurpy :(@a) are [almost] always 
Array's.


---

The one-arg rule slurpy is the oddest one of the bunch so here is some
brief information:

The one-arg rule slurpy can be sigiless :(+a), in which case it will
be a List instead of an Array or an alias to the single argument
depending on what it was.

 sub one-arg-rule ( +args ){
 say args.^name, " # ", args.perl;
 }

 one-arg-rule(  (1,),2,3  ); # List # ((1,), 2, 3)
 one-arg-rule( ((1,),2,3) ); # List # ((1,), 2, 3) # one-arg rule
 one-arg-rule( ((1,),2,3).Seq ); # Seq # ((1,), 2, 3).Seq # 
one-arg rule

 one-arg-rule(  1..3   ); # List # (1, 2, 3)
 one-arg-rule( (1..3,) ); # List # (1..3,)

 sub one-arg-Array ( +@args ){
 say @args.^name, " # ", @args.perl;
 }

 one-arg-Array(  (1,),2,3  ); # Array # [(1,), 2, 3]
 one-arg-Array( ((1,),2,3) ); # Array # [(1,), 2, 3]
 one-arg-Array( ((1,),2,3).Seq ); # List # ((1,), 2, 3)
 one-arg-Array(  1..3   ); # Array # [1, 2, 3]
 one-arg-Array( (1..3,) ); # Array # [1..3,]

The one-arg rule exists because people tend to write the following:

 my @a = [1,2,3];

When the correct way to write it is:

 my @a = 1,2,3;

There are various other places where the one-arg rule is also used, so
it was made available to everyone.

---

Don't get too flustered if you don't understand all of the nuances, it
take everybody a while to understand them.



Thank you!

The term "slurpy" did help a lot.

:-)

I am writing your explanation down for my records.



Well Golly!

$ p6 'sub printx(**@args){print(@args)}; printx("abc",1,"def\n");'
abc 1 def

$ p6 'sub printx(**@args){print @args, "\n"}; printx("abc",1,"def");'
abc 1 def

Question:
$ p6 'sub printx(**@args){print(@args)}; printx("abc","xyz","def\n");'
abc xyz def

Are the spaces suppose to be there?


Re: **@args question

2019-01-02 Thread ToddAndMargo via perl6-users

> On Wed, Jan 2, 2019 at 8:41 PM ToddAndMargo via perl6-users
>  wrote:
>>
>> Hi All,
>>
>> Looking at
>>
>>  https://docs.perl6.org/routine/print
>>
>> I see
>>
>>  multi sub print(**@args --> True)
>>
>> Question.  If I wanted to create my own print routine
>> using **@args, how would I declare it?
>>
>>  sub printx( **@args data ) {...}
>>
>>
>> Many thanks,
>> -T


On 1/2/19 10:06 PM, Brad Gilbert wrote:

The variable name in :(**@args) is @args, it could be any valid array
identifier like @data

 sub printx( **@data ){…}

Note that there are several forms for slurpy positional arguments.

 :(   @a ) # not slurpy at all, takes one Positional argument and
aliases it as @a.

 :(  *@a ) # flattening slurpy  (1,),2,3 → 1,2,3 and ((1,),2,3) → 1,2,3
 :( **@a ) # structured slurpy (1,),2,3 → (1,),2,3 and ((1,),2,3) →
((1,),2,3) # note there is no change
 :(  +@a ) # one-arg rule slurpy (1,),2,3 → (1,),2,3 and ((1,),2,3)
→ (1,),2,3 # note that the second one changes

Note that itemized values do not get flattened for :(*@a), and that
Array values are itemized.

I like to consider the one-arg rule slurpy :(+@a) to be like a
combination between non-slurpy :(@a) and structured slurpy :(**@a)
That is a one-arg rule slurpy will sometimes be like an alias to a
singular positional, otherwise it will act like a structured slurpy.

Note that all but the [aliasing] non-slurpy :(@a) are [almost] always Array's.

---

The one-arg rule slurpy is the oddest one of the bunch so here is some
brief information:

The one-arg rule slurpy can be sigiless :(+a), in which case it will
be a List instead of an Array or an alias to the single argument
depending on what it was.

 sub one-arg-rule ( +args ){
 say args.^name, " # ", args.perl;
 }

 one-arg-rule(  (1,),2,3  ); # List # ((1,), 2, 3)
 one-arg-rule( ((1,),2,3) ); # List # ((1,), 2, 3) # one-arg rule
 one-arg-rule( ((1,),2,3).Seq ); # Seq # ((1,), 2, 3).Seq # one-arg rule
 one-arg-rule(  1..3   ); # List # (1, 2, 3)
 one-arg-rule( (1..3,) ); # List # (1..3,)

 sub one-arg-Array ( +@args ){
 say @args.^name, " # ", @args.perl;
 }

 one-arg-Array(  (1,),2,3  ); # Array # [(1,), 2, 3]
 one-arg-Array( ((1,),2,3) ); # Array # [(1,), 2, 3]
 one-arg-Array( ((1,),2,3).Seq ); # List # ((1,), 2, 3)
 one-arg-Array(  1..3   ); # Array # [1, 2, 3]
 one-arg-Array( (1..3,) ); # Array # [1..3,]

The one-arg rule exists because people tend to write the following:

 my @a = [1,2,3];

When the correct way to write it is:

 my @a = 1,2,3;

There are various other places where the one-arg rule is also used, so
it was made available to everyone.

---

Don't get too flustered if you don't understand all of the nuances, it
take everybody a while to understand them.



Thank you!

The term "slurpy" did help a lot.

:-)

I am writing your explanation down for my records.


Re: **@args question

2019-01-02 Thread Brad Gilbert
The variable name in :(**@args) is @args, it could be any valid array
identifier like @data

sub printx( **@data ){…}

Note that there are several forms for slurpy positional arguments.

:(   @a ) # not slurpy at all, takes one Positional argument and
aliases it as @a.

:(  *@a ) # flattening slurpy  (1,),2,3 → 1,2,3 and ((1,),2,3) → 1,2,3
:( **@a ) # structured slurpy (1,),2,3 → (1,),2,3 and ((1,),2,3) →
((1,),2,3) # note there is no change
:(  +@a ) # one-arg rule slurpy (1,),2,3 → (1,),2,3 and ((1,),2,3)
→ (1,),2,3 # note that the second one changes

Note that itemized values do not get flattened for :(*@a), and that
Array values are itemized.

I like to consider the one-arg rule slurpy :(+@a) to be like a
combination between non-slurpy :(@a) and structured slurpy :(**@a)
That is a one-arg rule slurpy will sometimes be like an alias to a
singular positional, otherwise it will act like a structured slurpy.

Note that all but the [aliasing] non-slurpy :(@a) are [almost] always Array's.

---

The one-arg rule slurpy is the oddest one of the bunch so here is some
brief information:

The one-arg rule slurpy can be sigiless :(+a), in which case it will
be a List instead of an Array or an alias to the single argument
depending on what it was.

sub one-arg-rule ( +args ){
say args.^name, " # ", args.perl;
}

one-arg-rule(  (1,),2,3  ); # List # ((1,), 2, 3)
one-arg-rule( ((1,),2,3) ); # List # ((1,), 2, 3) # one-arg rule
one-arg-rule( ((1,),2,3).Seq ); # Seq # ((1,), 2, 3).Seq # one-arg rule
one-arg-rule(  1..3   ); # List # (1, 2, 3)
one-arg-rule( (1..3,) ); # List # (1..3,)

sub one-arg-Array ( +@args ){
say @args.^name, " # ", @args.perl;
}

one-arg-Array(  (1,),2,3  ); # Array # [(1,), 2, 3]
one-arg-Array( ((1,),2,3) ); # Array # [(1,), 2, 3]
one-arg-Array( ((1,),2,3).Seq ); # List # ((1,), 2, 3)
one-arg-Array(  1..3   ); # Array # [1, 2, 3]
one-arg-Array( (1..3,) ); # Array # [1..3,]

The one-arg rule exists because people tend to write the following:

my @a = [1,2,3];

When the correct way to write it is:

my @a = 1,2,3;

There are various other places where the one-arg rule is also used, so
it was made available to everyone.

---

Don't get too flustered if you don't understand all of the nuances, it
take everybody a while to understand them.

On Wed, Jan 2, 2019 at 8:41 PM ToddAndMargo via perl6-users
 wrote:
>
> Hi All,
>
> Looking at
>
> https://docs.perl6.org/routine/print
>
> I see
>
> multi sub print(**@args --> True)
>
> Question.  If I wanted to create my own print routine
> using **@args, how would I declare it?
>
> sub printx( **@args data ) {...}
>
>
> Many thanks,
> -T
>
>
> --
> ~~
> When you say, "I wrote a program that
> crashed Windows," people just stare at
> you blankly and say, "Hey, I got those
> with the system, for free."
>   -- Linus Torvalds
> ~~


Re: Basic question about lexical binding in relationship with "list assignment"

2019-01-02 Thread Elizabeth Mattijsen
Fixed with https://github.com/rakudo/rakudo/commit/23663609a7

> On 27 Dec 2018, at 09:29, Raymond Dresens  wrote:
> 
> Hello,
> 
> I'm getting up to speed with Perl 6 again after a long while, and I more
> or less 'hit my nose' against something that I can reduce to the
> following very basic snippet of code:
> 
>my $foo = 3;
>say $foo;
> 
>{
>say $foo;
> 
>my $foo = 6;
> 
>say $foo;
>}
> 
> This will not compile with Perl 6 (Rakudo 2018.12) -- lexical symbol
> '$foo' is already bound to an outer symbol; the implicit outer binding
> must be rewritten as OUTER::<$foo> before you can unambiguously declare
> a new '$foo' in this scope.
> 
> This will compile with Perl 5 when I add 'use v5.14;' at the top and it
> will then print 3, then 3 then 6 (as expected).
> 
> Well, it seems that I can 'cheat' by simply doing a list assignment:
> 
>my $foo = 3;
>say $foo;
> 
>{
>say $foo;
> 
>my ($foo) = 6; # avoid `... '$foo' is already bound ...'
> 
>say $foo;
>say $foo.WHAT; # is it really an integer?
>}
> 
> The output is:
> 
>3
>(Any)
>6
>(Int)
> 
> This behavior is fine I think (but a little unexpected due to my
> experience with Perl 5).
> 
> Is this behavior normal/wanted/intented (from a language/compiler
> perspective?).
> 
> Perhaps this shouldn't be and the compiler should also complain in this
> list assignment case, or perhaps generate a warning?
> 
> I'm not that confident to state that this is a bug ;)
> 
> Hence the reason why I kind-of report this,
> 
> I hope this is somewhat useful,
> 
> Thanks for your time,
> 
> Regards,
> 
> Raymond Dresens.


Re: Basic question about lexical binding in relationship with "list assignment"

2018-12-27 Thread Elizabeth Mattijsen
I’d say it is a bug you do not get the error with “my ($foo) = 6”, as clearly 
the first “say $foo” inside the scope is referring to the inner $foo, not the 
outer $foo.  So I’d suggest filing an issue for that: 
https://github.com/rakudo/rakudo/issues

> On 27 Dec 2018, at 09:29, Raymond Dresens  wrote:
> 
> Hello,
> 
> I'm getting up to speed with Perl 6 again after a long while, and I more
> or less 'hit my nose' against something that I can reduce to the
> following very basic snippet of code
> 
>my $foo = 3;
>say $foo;
> 
>{
>say $foo;
> 
>my $foo = 6;
> 
>say $foo;
>}
> 
> This will not compile with Perl 6 (Rakudo 2018.12) -- lexical symbol
> '$foo' is already bound to an outer symbol; the implicit outer binding
> must be rewritten as OUTER::<$foo> before you can unambiguously declare
> a new '$foo' in this scope.
> 
> This will compile with Perl 5 when I add 'use v5.14;' at the top and it
> will then print 3, then 3 then 6 (as expected).
> 
> Well, it seems that I can 'cheat' by simply doing a list assignment:
> 
>my $foo = 3;
>say $foo;
> 
>{
>say $foo;
> 
>my ($foo) = 6; # avoid `... '$foo' is already bound ...'
> 
>say $foo;
>say $foo.WHAT; # is it really an integer?
>}
> 
> The output is:
> 
>3
>(Any)
>6
>(Int)
> 
> This behavior is fine I think (but a little unexpected due to my
> experience with Perl 5).
> 
> Is this behavior normal/wanted/intented (from a language/compiler
> perspective?).
> 
> Perhaps this shouldn't be and the compiler should also complain in this
> list assignment case, or perhaps generate a warning?
> 
> I'm not that confident to state that this is a bug ;)
> 
> Hence the reason why I kind-of report this,
> 
> I hope this is somewhat useful,
> 
> Thanks for your time,
> 
> Regards,
> 
> Raymond Dresens.


Re: Basic question about lexical binding in relationship with "list assignment"

2018-12-27 Thread JJ Merelo
Hi,

El jue., 27 dic. 2018 a las 9:30, Raymond Dresens (<
raymond.dres...@gmail.com>) escribió:

> Hello,
>
> I'm getting up to speed with Perl 6 again after a long while, and I more
> or less 'hit my nose' against something that I can reduce to the
> following very basic snippet of code:
>
> my $foo = 3;
> say $foo;
>
> {
> say $foo;
>
> my $foo = 6;
>
> say $foo;
> }
>
> This will not compile with Perl 6 (Rakudo 2018.12) -- lexical symbol
> '$foo' is already bound to an outer symbol; the implicit outer binding
> must be rewritten as OUTER::<$foo> before you can unambiguously declare
> a new '$foo' in this scope.
>

But where's that error? In the first "say $foo"?

>
> This will compile with Perl 5 when I add 'use v5.14;' at the top and it
> will then print 3, then 3 then 6 (as expected).
>
> Well, it seems that I can 'cheat' by simply doing a list assignment:
>
> my $foo = 3;
> say $foo;
>
> {
> say $foo;
>
> my ($foo) = 6; # avoid `... '$foo' is already bound ...'
>

That should make no difference...

>
> say $foo;
> say $foo.WHAT; # is it really an integer?
> }
>
> The output is:
>
> 3
> (Any)
>

That's the first say $foo in the block, I guess...

6
> (Int)
>
> This behavior is fine I think (but a little unexpected due to my
> experience with Perl 5).
>
> Is this behavior normal/wanted/intented (from a language/compiler
> perspective?).
>
> Perhaps this shouldn't be and the compiler should also complain in this
> list assignment case, or perhaps generate a warning?
>
> I'm not that confident to state that this is a bug ;)
>
> Hence the reason why I kind-of report this,
>


It might be a documentation bug... Which you might want to report anyway.
The thing with Perl 6 is that parsing, compiling and runtime are quite
different. In Perl, far as I can tell, you are actually assigning scope to
$foo when you run that sentence. That's not the case in Perl 6, or does not
seem to be. However, this should be quite clear from the get go.

Cheers

JJ


Re: words[] question

2018-09-26 Thread Brandon Allbery
We really are not communicating at all, are we?

It says "--> Positional". Positional is a role specifying what to do with
[]. Positional is what knows what to do with [], so words() and lines() and
everything else that produces a Positional doesn't have to know that.
This is more or less the *definition* of Positional. It's not up to the
documentation of words() to also tell you the documentation of Positional;
it told you to look there.

And there is more to Positional than just knowing what to do with [], and
that also is not something words() or its documentation should tell you. Or
does every documentation page have to incorporate the whole Perl 6
documentation? ("You might decide to pass this a Str, so I guess I have to
explain in detail what a Str is now just in case"?)

On Wed, Sep 26, 2018 at 6:05 PM ToddAndMargo  wrote:

> On 9/26/18 2:40 PM, Brandon Allbery wrote:
> > Do you really think every function that produces a "list" has built into
> > it secret knowledge of how you would index a list? They just produce a
> > "Positional" or "Seq" or "List", etc. and *those* know what to do with
> > []. The function doesn't even need to say it's doing that; that's to
> > produce better error messages, not "wire what a list is into me".
>
> Hi Brandon,
>
> I know how to use the function and use it all the time.  My
> frustration is with the documentation.
>
> How did this
>
>   multi method words(Str:D $input: $limit = Inf --> Positional)
>
> get to what you describe above?
>
> Yours in confusion,
> -T
>


-- 
brandon s allbery kf8nh
allber...@gmail.com


Re: words[] question

2018-09-26 Thread ToddAndMargo

On 9/26/18 2:40 PM, Brandon Allbery wrote:
Do you really think every function that produces a "list" has built into 
it secret knowledge of how you would index a list? They just produce a 
"Positional" or "Seq" or "List", etc. and *those* know what to do with 
[]. The function doesn't even need to say it's doing that; that's to 
produce better error messages, not "wire what a list is into me".


Hi Brandon,

I know how to use the function and use it all the time.  My
frustration is with the documentation.

How did this

 multi method words(Str:D $input: $limit = Inf --> Positional)

get to what you describe above?

Yours in confusion,
-T


Re: words[] question

2018-09-26 Thread ToddAndMargo

On 9/26/18 6:04 AM, Brian Duggan wrote:

On Tuesday, September 25, Todd Chester wrote:

Not to ask too obvious a question, but why does words use a []
instead of a () ?
...
I am confused as to when to use [] and when to use () with a method.


If a method is called without arguments, the () can be omitted.

"a man a plan a canal -- panama".words()
"a man a plan a canal -- panama".words# <-- same thing

[] acts on the return value -- it takes an element of a list

"a man a plan a canal -- panama".words()[3]
"a man a plan a canal -- panama".words[3]  # <-- same thing

Brian



Hi Brian,

That was beautifully written.  Thank you!

I think I did not make myself clear.  I know how
to use the function and use it all the time.

My frustration is with
 multi method words(Str:D $input: $limit = Inf --> Positional)

Specifically "$limit = Inf".  Why are we using "$limit" instead
of "$selection" and why are we throwing "Inf" into the mix
as it is a "type".  "Types" are written like "Str:D" and come
before the variable, not after.  (I know the ":D" means "defined".)

And where is it stated what goes in the () and what goes
in the []?

My specific goal is to understand what the documentation is trying
to say.  That way, instead of grumbling about how bad it is, I can
make some constructive comments to help improve it.

-T


Re: words[] question

2018-09-26 Thread Brandon Allbery
You're still assuming they're the "same thing"in some sense.

The type of the () postfix operator says it applies to a function or method
(more specifically, to something that supports the Callable role), thus to
"words" itself.
The type of the [] postfix operator says it applies to something that
supports the Positional role; as "words" produces a Positional, the []
applies to the *result* of words.

"words" itself doesn't see or know about either of them. It is invoked by
the () postfix, and its result is processed by the [] postfix.

Do you really think every function that produces a "list" has built into it
secret knowledge of how you would index a list? They just produce a
"Positional" or "Seq" or "List", etc. and *those* know what to do with [].
The function doesn't even need to say it's doing that; that's to produce
better error messages, not "wire what a list is into me".

On Wed, Sep 26, 2018 at 5:32 PM ToddAndMargo  wrote:

> On 9/26/18 11:42 AM, Larry Wall wrote:
> > On Wed, Sep 26, 2018 at 01:16:26PM -0400, Parrot Raiser wrote:
> > : Would it be correct to say:
> > :  [ ] aka square brackets, always surround the subscript of an array or
> > : list, i.e. here "n: is an integer,  [n] always means the nth item,
> > : while
> > : ( ), round brackets or parentheses, separate and group items to
> > : control processing order, and identify subroutine calls, surrounding
> > : the argument list, if any?
> >
> > I'd say there's a bit of confusion here between different syntactic
> > categories.  Your first definition is assuming only postfix position
> > (making [] a "postcircumfix"), while your second definition includes the
> > use of () in both term position and postfix position.  In term position,
> > yes, parentheses control the processing order and group things, but
> > [] also has a term-position interpretation of its own, which is as an
> > array composer (but not a subscript).  In postfix position, [] is always
> > a subscript as you indicated, but () is only for passing arguments
> > to something (and forcing a function call if that something might be
> > construed as a different keyword without the parens).  Any grouping
> > behavior is incidental to the argument processing, and in fact many
> > constructs you can use in normal grouping parens are illegal in an
> > argument list:
> >
> >  > p6 'say abs(42 or 43)'
> >  ===SORRY!=== Error while compiling -e
> >  Unable to parse expression in argument list; couldn't find final
> ')' (corresponding starter was at line 1)
> >  at -e:1
> >  --> say abs(42⏏ or 43)
> >
> > but in term position that's fine since the inside is a whole statement:
> >
> >  > p6 'say abs (42 or 43)'
> >  42
> >
> > The latter cannot be taken as a postfix because of the space. (Unless
> > you use Tuxic, which confuses this intentionally. :)
> >
> > The three main syntax categories you have to be able to track (and
> > it's much easier to track in Perl 6 than in Perl 5), are:
> >
> >  1) when you're expecting a term
> >  2) when you're expecting a postfix (or infix if there's no postfix)
> >  3) when you're expecting only an infix
> >
> > The careful distinction of which category the grammar engine is expecting
> > is critical to understanding any version of Perl, whether 5 or 6.
> > You can't adequately describe any random syntax in Perl without first
> > nailing down which of the main grammar rules is going to be parsing it.
> >
> > Well, I've probably said more than enough.  :)
> >
> > Larry
> >
>
> Hi Larry,
>
> Wonderful explanation!  Thank you!
>
> Followup question.  I am confused.  How did they get from
>
>   multi method words(Str:D $input: $limit = Inf --> Positional)
>
> to what goes in the () and what goes in the []?
>
> And why are they using the term "$limit" instead of "$selection"?
>
> Yours in confusion,
> -T
>
>
>
> --
> ~~
> Computers are like air conditioners.
> They malfunction when you open windows
> ~~
>


-- 
brandon s allbery kf8nh
allber...@gmail.com


Re: words[] question

2018-09-26 Thread ToddAndMargo

On 9/26/18 11:42 AM, Larry Wall wrote:

On Wed, Sep 26, 2018 at 01:16:26PM -0400, Parrot Raiser wrote:
: Would it be correct to say:
:  [ ] aka square brackets, always surround the subscript of an array or
: list, i.e. here "n: is an integer,  [n] always means the nth item,
: while
: ( ), round brackets or parentheses, separate and group items to
: control processing order, and identify subroutine calls, surrounding
: the argument list, if any?

I'd say there's a bit of confusion here between different syntactic
categories.  Your first definition is assuming only postfix position
(making [] a "postcircumfix"), while your second definition includes the
use of () in both term position and postfix position.  In term position,
yes, parentheses control the processing order and group things, but
[] also has a term-position interpretation of its own, which is as an
array composer (but not a subscript).  In postfix position, [] is always
a subscript as you indicated, but () is only for passing arguments
to something (and forcing a function call if that something might be
construed as a different keyword without the parens).  Any grouping
behavior is incidental to the argument processing, and in fact many
constructs you can use in normal grouping parens are illegal in an
argument list:

 > p6 'say abs(42 or 43)'
 ===SORRY!=== Error while compiling -e
 Unable to parse expression in argument list; couldn't find final ')' 
(corresponding starter was at line 1)
 at -e:1
 --> say abs(42⏏ or 43)

but in term position that's fine since the inside is a whole statement:

 > p6 'say abs (42 or 43)'
 42

The latter cannot be taken as a postfix because of the space. (Unless
you use Tuxic, which confuses this intentionally. :)

The three main syntax categories you have to be able to track (and
it's much easier to track in Perl 6 than in Perl 5), are:

 1) when you're expecting a term
 2) when you're expecting a postfix (or infix if there's no postfix)
 3) when you're expecting only an infix
 
The careful distinction of which category the grammar engine is expecting

is critical to understanding any version of Perl, whether 5 or 6.
You can't adequately describe any random syntax in Perl without first
nailing down which of the main grammar rules is going to be parsing it.

Well, I've probably said more than enough.  :)

Larry



Hi Larry,

Wonderful explanation!  Thank you!

Followup question.  I am confused.  How did they get from

 multi method words(Str:D $input: $limit = Inf --> Positional)

to what goes in the () and what goes in the []?

And why are they using the term "$limit" instead of "$selection"?

Yours in confusion,
-T



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


Re: words[] question

2018-09-26 Thread Larry Wall
On Wed, Sep 26, 2018 at 01:16:26PM -0400, Parrot Raiser wrote:
: Would it be correct to say:
:  [ ] aka square brackets, always surround the subscript of an array or
: list, i.e. here "n: is an integer,  [n] always means the nth item,
: while
: ( ), round brackets or parentheses, separate and group items to
: control processing order, and identify subroutine calls, surrounding
: the argument list, if any?

I'd say there's a bit of confusion here between different syntactic
categories.  Your first definition is assuming only postfix position
(making [] a "postcircumfix"), while your second definition includes the
use of () in both term position and postfix position.  In term position,
yes, parentheses control the processing order and group things, but
[] also has a term-position interpretation of its own, which is as an
array composer (but not a subscript).  In postfix position, [] is always
a subscript as you indicated, but () is only for passing arguments
to something (and forcing a function call if that something might be
construed as a different keyword without the parens).  Any grouping
behavior is incidental to the argument processing, and in fact many
constructs you can use in normal grouping parens are illegal in an
argument list:

> p6 'say abs(42 or 43)'
===SORRY!=== Error while compiling -e
Unable to parse expression in argument list; couldn't find final ')' 
(corresponding starter was at line 1)
at -e:1
--> say abs(42⏏ or 43)

but in term position that's fine since the inside is a whole statement:

> p6 'say abs (42 or 43)'
42

The latter cannot be taken as a postfix because of the space. (Unless
you use Tuxic, which confuses this intentionally. :)

The three main syntax categories you have to be able to track (and
it's much easier to track in Perl 6 than in Perl 5), are:

1) when you're expecting a term
2) when you're expecting a postfix (or infix if there's no postfix)
3) when you're expecting only an infix

The careful distinction of which category the grammar engine is expecting
is critical to understanding any version of Perl, whether 5 or 6.
You can't adequately describe any random syntax in Perl without first
nailing down which of the main grammar rules is going to be parsing it.

Well, I've probably said more than enough.  :)

Larry


Re: words[] question

2018-09-26 Thread Parrot Raiser
Would it be correct to say:
 [ ] aka square brackets, always surround the subscript of an array or
list, i.e. here "n: is an integer,  [n] always means the nth item,
while
( ), round brackets or parentheses, separate and group items to
control processing order, and identify subroutine calls, surrounding
the argument list, if any?

On 9/26/18, Brian Duggan  wrote:
> On Tuesday, September 25, Todd Chester wrote:
>> Not to ask too obvious a question, but why does words use a []
>> instead of a () ?
>> ...
>> I am confused as to when to use [] and when to use () with a method.
>
> If a method is called without arguments, the () can be omitted.
>
>"a man a plan a canal -- panama".words()
>"a man a plan a canal -- panama".words# <-- same thing
>
> [] acts on the return value -- it takes an element of a list
>
>"a man a plan a canal -- panama".words()[3]
>"a man a plan a canal -- panama".words[3]  # <-- same thing
>
> Brian
>


Re: words[] question

2018-09-26 Thread Brian Duggan
On Tuesday, September 25, Todd Chester wrote: 
> Not to ask too obvious a question, but why does words use a []
> instead of a () ?
> ...
> I am confused as to when to use [] and when to use () with a method.

If a method is called without arguments, the () can be omitted.

   "a man a plan a canal -- panama".words()
   "a man a plan a canal -- panama".words# <-- same thing

[] acts on the return value -- it takes an element of a list

   "a man a plan a canal -- panama".words()[3]
   "a man a plan a canal -- panama".words[3]  # <-- same thing

Brian


Re: words[] question

2018-09-26 Thread Todd Chester




On 09/25/2018 11:37 PM, Todd Chester wrote:

How about my `Str:D $input:` question?


That chat line just told me it is an optional
way of writing it.  I like it!


Re: words[] question

2018-09-26 Thread Todd Chester




El mié., 26 sept. 2018 a las 8:27, Todd Chester (>) escribió:




 >> El mié., 26 sept. 2018 a las 6:12, Todd Chester
(mailto:toddandma...@zoho.com>
 >> >>)
escribió:
 >>
 >> Hi All,
 >>
 >> https://docs.perl6.org/routine/words
 >> is no help
 >>
 >> Not to ask too obvious a question, but why does words use a []
 >> instead of a () ?

On 09/25/2018 10:38 PM, JJ Merelo wrote:
 >
 >
 >
 >
 > Are you referring to a particular example? I can't find it.

yes the ones in the original post.

 >
 > At any rate, $whatever.words[4] is the same as $whatever.words()[4].
 > That method needs no arguments, so it makes do without
parentheses. When
 > it uses it, it's to limit the number of words returned.
 >
 > Cheers
 >
 > JJ


I am confused as to when to use [] and when to use () with a method.

The only thing can think of is that [] allows me to do thing like
 [4]
 [4,6]
 [4..6]
Where I can't do it with ()

But why is (4) different than [4]?

And
https://docs.perl6.org/routine/words#class_Str
 (Str) routine words

   multi subwords(Str:D $input, $limit = Inf --> Positional)
   multi method words(Str:D $input: $limit = Inf --> Positional)

Also is `Str:D $input:` written correctly?  I have only seen it as
`Str:D:` before.



On 09/25/2018 11:29 PM, JJ Merelo wrote:
() is to pass arguments, [] is for array indexing. In your example, 
words(4) calls words with the number 4. words[4] would do words()[4], 
that is, words with no argument, that returns array, array indexed by 4




Something is wrong...

 $ p6 'say "1a 2b 3c 4c 5c".words("c");'
 Cannot convert string to number: base-10 number must begin with
 valid digits or '.' in '⏏c' (indicated by ⏏)
 in block  at -e line 1

 $ p6 'say "1a 2b 3c 4c 5c".words(c);'
 ===SORRY!=== Error while compiling -e
 Undeclared routine:
 c used at line 1

 $ p6 'say "1a 2b 3c 4c 5c".words(3);'
 (1a 2b 3c)

 $ p6 'say "5a 4b 3c 2c 1c".words(4);'
 (5a 4b 3c 2c)


Boy the docs really struck out on explaining this!

How about my `Str:D $input:` question?


Re: words[] question

2018-09-26 Thread Todd Chester




El mié., 26 sept. 2018 a las 6:12, Todd Chester (>) escribió:


Hi All,

https://docs.perl6.org/routine/words
is no help

Not to ask too obvious a question, but why does words use a []
instead of a () ?


On 09/25/2018 10:38 PM, JJ Merelo wrote:





Are you referring to a particular example? I can't find it.


yes the ones in the original post.



At any rate, $whatever.words[4] is the same as $whatever.words()[4]. 
That method needs no arguments, so it makes do without parentheses. When 
it uses it, it's to limit the number of words returned.


Cheers

JJ



I am confused as to when to use [] and when to use () with a method.

The only thing can think of is that [] allows me to do thing like
   [4]
   [4,6]
   [4..6]
Where I can't do it with ()

But why is (4) different than [4]?

And
   https://docs.perl6.org/routine/words#class_Str
   (Str) routine words

 multi subwords(Str:D $input, $limit = Inf --> Positional)
 multi method words(Str:D $input: $limit = Inf --> Positional)

Also is `Str:D $input:` written correctly?  I have only seen it as
`Str:D:` before.


-T


  1   2   3   4   >