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



-c question

2024-02-05 Thread ToddAndMargo via perl6-users

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



.contains question

2023-12-10 Thread ToddAndMargo via perl6-users

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-users@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-users@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-users@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"  {...}

A question on AND

2023-06-29 Thread ToddAndMargo via perl6-users

Hi All,

This gets the finger wagged at me for a "Nil"
when @*ARGS.elems equals zero:

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


I have to do this instead:

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


Do I misunderstand something?  In an AND, is
not the test suppose to stop at the first fail?

I have not checked OR, but is that not suppose
to jump out at the first pass?  Or does it
check everything too?

Many thanks,
-T







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



"returns" question

2022-12-07 Thread ToddAndMargo via perl6-users

Hi All,

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

sub abc() returns Str {...}

becasue it makes eh sub easier to figure out at
a glance when I go to maintain it.

Two exports I have not figured out are
   1) an array,
   2) an object created from a custom class.

returns @

gets the finger wagged at me.

What is the proper syntax for these two?


Many thanks,
-T


--

Yesterday it worked.
Today it is not working.
Windows is like that.



Re: NativeCall and pointers question

2022-11-30 Thread ToddAndMargo via perl6-users

On 11/30/22 12:53, ToddAndMargo via perl6-users wrote:

Let me ask this question a little simpler:



To answer my own questions, which I figured out
the hard way.


1) how to I tell NativeCall I only want the
C pointer back, not what it points to?


By declaring it as a pointer and creating it with
".new".   No ".new", and you get back garbage.

sub GetWTSEnumerateSession(
   #`{
   C++
   BOOL WTSEnumerateSessionsA(
 [in]  HANDLE hServer,
 [in]  DWORD  Reserved,
 [in]  DWORD  Version,
 [out] PWTS_SESSION_INFOA *ppSessionInfo,
 [out] DWORD  *pCount
   );
   Returns zero if this function fails.
   }
   DWORD $hServer,   # [in]  HANDLE
   DWORD $Reserved,  # [in] always 0
   DWORD $Version,   # [in] always 1
   Pointer $ppSessionInf is rw,  # [out] <---
   DWORD $pCount is rw   # [out] DWORD
   )
   is native("Wtsapi32.dll")
   is symbol("WTSEnumerateSessionsA")
   returns DWORD  # If the function fails, the return value is zero.
   { * };


   my $ppSessionInfo = NativeCall::Types::Pointer.new();





2) how do I tell NativeCall I am sending it
a C pointer?


Declare it a Pointer, same as above.  See

   my $ppSessionInfo

Do not forget the .new.  There are no
error warnings if you forget.  The resulting
garbage yo get back will drive you nuts,
especially when the next API call that
reuses that point will cause your program to
exit with not explanation.



Yours in confusion (but not this, finally),
-T

--
~~~
Serious error.
All shortcuts have disappeared.
Screen. Mind. Both are blank.
~~~


Re: NativeCall and pointers question

2022-11-30 Thread ToddAndMargo via perl6-users

Let me ask this question a little simpler:

1) how to I tell NativeCall I only want the
C pointer back, not what it points to?

2) how do I tell NativeCall I am sending it
a C pointer?

Many thanks,
-T



NativeCall and pointers question

2022-11-30 Thread ToddAndMargo via perl6-users

Hi All,

In the following:

use NativeCall;
constant BYTE := uint8;
constant LPDWORD  := uint64;# long pointer to a DWORD
constant LPSTR= CArray[BYTE];   # long pointer to a string
constant DWORD:= uint32;
constant HANDLE   = Pointer[void];

sub WTSOpenServerA(
  #`{

https://learn.microsoft.com/en-us/windows/win32/api/wtsapi32/nf-wtsapi32-wtsopenservera?redirectedfrom=MSDN
  C++
  HANDLE WTSOpenServerA(
  [in] LPSTR pServerName
  );
   }

   LPSTR $pServerName
   )

   is native("Wtsapi32.dll")
   is symbol("WTSOpenServerA")
   returns DWORD
   { * };


NativeCall is resolving the pointers automatically
for me.  It is taking $pServerName, which is a
Long Pointer to String (LPSTR) and creating the
pointer for me.  This is appreciated.

It also returns and resolves the value of “HANDLE”
which is a C Pointer DWORD..

Question 1:  how do I tell NativeCall I actually
want the C Pointer of HANDLE  back and not what
it resolves to?

Question 2: how do I give NativeCall a pointer
value and tell Native call I do not want it
resolved into another pointer?

Many thanks,
-T




Re: Pointer to bug question

2022-11-28 Thread ToddAndMargo via perl6-users

On 11/27/22 19:13, Clifton Wood wrote:
ToddAndMargo: Why are you referencing NativeHelpers::Blob when I've 
linked to the code you need. The bug was in the code snippet I've sent. 
NONE of my stuff is available via zef because CURI (and hence zef) have 
problems with large scale code that I am still trying to resolve.


You should be able to get a clean copy of the role from here 
. You should be able to download it, copy it to your project directory and execute it.


No zef necessary.


Hi Clifton,

I have been looking over the code.  I am not sure what
I am looking at.

Would you give me a brief summary of what it is
suppose to do?

Many thanks,
-T



Re: Pointer to bug question

2022-11-28 Thread ToddAndMargo via perl6-users

On 11/27/22 19:13, Clifton Wood wrote:
ToddAndMargo: Why are you referencing NativeHelpers::Blob when I've 
linked to the code you need. The bug was in the code snippet I've sent. 
NONE of my stuff is available via zef because CURI (and hence zef) have 
problems with large scale code that I am still trying to resolve.


You should be able to get a clean copy of the role from here 
. You should be able to download it, copy it to your project directory and execute it.


No zef necessary.

Sorry.  I did not realize it was there.

Is it supporting Win32 yet?


Re: Pointer to bug question

2022-11-27 Thread Clifton Wood
ToddAndMargo: Why are you referencing NativeHelpers::Blob when I've linked
to the code you need. The bug was in the code snippet I've sent. NONE of my
stuff is available via zef because CURI (and hence zef) have problems with
large scale code that I am still trying to resolve.

You should be able to get a clean copy of the role from here
.
You should be able to download it, copy it to your project directory and
execute it.

No zef necessary.

On Fri, Nov 25, 2022 at 4:50 PM ToddAndMargo  wrote:

> On 11/24/22 20:55, Clifton Wood wrote:
> > Heh!  I had a bug in my code and you pretty much mimic'd it. That's on
> > me. Line 114 should read:
> >
> > "my $a = GLib::Roles::TypedBuffer[WTS_SESSION_INFOA].new($ppSessionInf);"
> >
> > Let me know how it works out.
> >
>
>
>
> zef uninstall NativeHelpers::Blob
> ===> Uninstalled from C:\Users\tony\.raku
> NativeHelpers::Blob:ver<0.1.12>:auth
>
> K:\Windows\NtUtil>zef install NativeHelpers::Blob
> ===> Searching for: NativeHelpers::Blob
> ===> Updating fez mirror: https://360.zef.pm/
> ===> Updated fez mirror: https://360.zef.pm/
> ===> Updating rea mirror:
> https://raw.githubusercontent.com/Raku/REA/main/META.json
> ===> Updated rea mirror:
> https://raw.githubusercontent.com/Raku/REA/main/META.json
> ===> Testing: NativeHelpers::Blob:ver<0.1.12>:auth
> [NativeHelpers::Blob] ===SORRY!=== Error while compiling
>
> C:\Users\tony\.zef\tmp\NativeHelpers%3A%3ABlob%3Aver%3C0.1.12%3E%3Aauth%3Cgithub%3Asalortiz%3E.tar.gz\NativeHelpers-Blob-master/t\02-cstruct.t
> [NativeHelpers::Blob] Failed to open file
> C:\Users\tony\.zef\tmp\NativeHelpers%3A%3ABlob%3Aver%3C0.1.12%3E%3Aauth%3Cgithub%3Asalortiz%3E.tar.gz\NativeHelpers-Blob-master\t\.precomp\BE04B1FADFC312E3411CB403B43E629B7AED3ADC\27\27F410113BBD23B298581F9F713FBCFB39C1584E.repo-id.2BAIB5TQR7KNKMX1796GKOJF6.tmp:
>
> No such file or directory
> [NativeHelpers::Blob] at
>
> C:\Users\tony\.zef\tmp\NativeHelpers%3A%3ABlob%3Aver%3C0.1.12%3E%3Aauth%3Cgithub%3Asalortiz%3E.tar.gz\NativeHelpers-Blob-master/t\02-cstruct.t:3
> [NativeHelpers::Blob] Actually thrown at:
> [NativeHelpers::Blob]   in any statement_control at C:\Program
> Files\Rakudo\bin\..\share\perl6\lib/Perl6/Grammar.moarvm line 1
> [NativeHelpers::Blob] ===SORRY!=== Error while compiling
>
> C:\Users\tony\.zef\tmp\NativeHelpers%3A%3ABlob%3Aver%3C0.1.12%3E%3Aauth%3Cgithub%3Asalortiz%3E.tar.gz\NativeHelpers-Blob-master/t\99-my-meta.t
> [NativeHelpers::Blob] Failed to open file
> C:\Users\tony\.zef\tmp\NativeHelpers%3A%3ABlob%3Aver%3C0.1.12%3E%3Aauth%3Cgithub%3Asalortiz%3E.tar.gz\NativeHelpers-Blob-master\lib\.precomp\BE04B1FADFC312E3411CB403B43E629B7AED3ADC\27\27F410113BBD23B298581F9F713FBCFB39C1584E.repo-id.2Q72L8EJX9FJGLKXVSQOGR36G.tmp:
>
> No such file or directory
> [NativeHelpers::Blob] at
>
> C:\Users\tony\.zef\tmp\NativeHelpers%3A%3ABlob%3Aver%3C0.1.12%3E%3Aauth%3Cgithub%3Asalortiz%3E.tar.gz\NativeHelpers-Blob-master/t\99-my-meta.t:3
> [NativeHelpers::Blob] Actually thrown at:
> [NativeHelpers::Blob]   in any statement_control at C:\Program
> Files\Rakudo\bin\..\share\perl6\lib/Perl6/Grammar.moarvm line 1
> ===> Testing [FAIL]: NativeHelpers::Blob:ver<0.1.12>:auth
> Aborting due to test failure:
> NativeHelpers::Blob:ver<0.1.12>:auth (use --force-test
> to override)
>
>


Re: NativeCall pointer question?

2022-11-24 Thread ToddAndMargo via perl6-users
On Sun, Nov 20, 2022 at 3:48 AM ToddAndMargo via perl6-users 
mailto:perl6-users@perl.org>> wrote:


Hi All,

In one of my native call, I get returned a
pointer to a DWORD (uint32).

How do I turn that into the actual value
in the DWORD?

Many thanks,
-T


On 11/20/22 16:00, Clifton Wood wrote:

@ToddAndMargo,

Two ways:

  - Use "my CArray[uint32] $p", use $p as your parameter, and access the 
value as "$p[0]"


or

- Use "my Pointer[uint32] $p"  and use "$p.deref"

My personal preference is the former, as it is the best way to access 
AND set the actual former value. The latter can only deref. To my 
knowledge, you cannot set the referenced value of a Pointer type. I do 
reserve the right to be wrong on this, though.



Hi Clifton,

I have a pointer $p (from a Windows API call)
that points to a spot in memory that is 24
bytes long.

# Where do I tell it I want 24 bytes back?
my $ca = CArray[uint8].new( 0xFF ** 24 )
$ca = $p.deref;

Internal error: unhandled target type


Yours in confusion,
-T



Re: Pointer to bug question

2022-11-24 Thread ToddAndMargo via perl6-users

On 11/23/22 20:01, Clifton Wood wrote:

Long story short:

my $a = GLib::Roles::TypedBuffer[.new($ppSessionInf);
$a.setSize($pCount, :forced);
my @sessions = $a.Array;

That should return you an array of  objects.





raku PopUpTest2.pl6
===SORRY!=== Error while compiling K:\Windows\NtUtil/PopUpTest2.pl6
Cannot use variable $a in declaration to initialize itself
at K:\Windows\NtUtil/PopUpTest2.pl6:115
-->$a.setSize( ($pCount* 12 * $Win64bit), :f
expecting any of:
term



   class WTS_SESSION_INFOA is repr {
  has uint16 $.SessionID;
  has LPSTR $.pWinStationName;
  #has WTS_CONNECTSTATE_CLASS $.State
  has DWORD $.State
   }

   my WTS_SESSION_INFOA $SessionInfo;



   #`{
  comment What is PWTS_SESSION_INFOA? was posted by Castorix31 on 
Microsoft Q:

  C++ is 12 bytes in x86, 24 bytes in x64
  It is 3*8 :
  // x64
 int nSize1 = sizeof WTS_SESSION_INFOA; // 24

 int nOffset1 = offsetof(WTS_SESSION_INFOA, SessionId); // 0
 int nOffset2 = offsetof(WTS_SESSION_INFOA, pWinStationName); // 8
 int nOffset3 = offsetof(WTS_SESSION_INFOA, State); // 16

  On 11/23/22 20:01, Clifton Wood wrote:
  my $a = GLib::Roles::TypedBuffer[.new($ppSessionInf);
  $a.setSize($pCount, :forced);
  my @sessions = $a.Array;

   }

113:   # my BYTES  $Sessions = CArray[BYTE].new( 0xFF xx $pCount * 32 );
114:   my $a = 
GLib::Roles::TypedBuffer[.new($ppSessionInf);

115:   $a.setSize( ($pCount * 12 * $Win64bit), :forced );
   # my $Sessions = buf8.new( 0xFF xx (12 * $Win64bit) );
   my @Sessions = $ppSessionInf.deref[BYTES].CArray.buf8;
   print "\@Sessions = <" ~ @Sessions ~ "<\n";



Re: Pointer to bug question

2022-11-23 Thread Clifton Wood
@ToddAndMargo 

I'm about to go to sleep for the night. I thought I sent you a link to a
role that someone gave me for solving this problem. Please check out this
role
<https://github.com/Xliff/p6-GLib/blob/master/lib/GLib/Roles/TypedBuffer.pm6#L120>.
Please feel free to download the entire file and use it. If you need more
help, I should be available sometime in the morning.

Long story short:

my $a = GLib::Roles::TypedBuffer[.new($ppSessionInf);
$a.setSize($pCount, :forced);
my @sessions = $a.Array;

That should return you an array of  objects.

Good luck!



On Wed, Nov 23, 2022 at 9:46 PM ToddAndMargo via perl6-users <
perl6-users@perl.org> wrote:

> >>> Hi All,
> >>>
> >>> This is driving me nuts!
> >>>
> >>> Native Call question. I have a Pointer ($ppSessionInf).
> >>>
> >>> It points to a structure of $pCount bytes.
> >>>
> >>> How do I load what $ppSessionInf points to into $Sessions
> >>>
> >>>  # something gets assigned to it from an API call
> >>>  my Pointer $ppSessionInf = Pointer.new();
> >>>
> >>>  # length of the data I want also from the API call
> >>>  my DWORD   $pCount;  # length of the data I want
> >>>
> >>>  # Buffer I want the data pointer to by
> >>>  # $ppSessionInf loaded into
> >>>  my BYTES  $Sessions = CArray[BYTE].new( 0xFF xx $pCount );
> >>>
> >>>  $Sessions = $ppSessionInf.deref;
> >>>
> >>> Which obviously does not work:
> >>>Internal error: unhandled target type
> >>>
> >>> Many thanks,
> >>> -T
> >>>
>
> >> On Wed, Nov 23, 2022 at 9:21 PM Clifton Wood  >> <mailto:clifton.w...@gmail.com>> wrote:
> >>
> >> @ToddAndMargo <mailto:toddandma...@zoho.com> - Did you try my
> >> suggestion with GLib::Roles::TypedBuffer?
> >>
> >> The "unhandled target type" occurs when NativeCall can't figure out
> >> how to deref the referenced value. In this case, this would be the
> >> BYTE of the CArray.
> >>
> >> What type is BYTE, pray tell?
> >>
> >> - Cliff
> >>
> >> On Wed, Nov 23, 2022 at 9:08 PM ToddAndMargo via perl6-users
> >> mailto:perl6-users@perl.org>> wrote:
> >>
> >> removing my typos:
> >>
>
> On 11/23/22 18:22, Clifton Wood wrote:
> > @ToddAndMargo <mailto:toddandma...@zoho.com> -- Also, Pointer cannot
> > deref a Pointer, which I think is the real error.
>
>
> How do I load what $ppSessionInf points to into $Sessions?
>
>
>


Re: Pointer to bug question

2022-11-23 Thread ToddAndMargo via perl6-users

Hi All,

This is driving me nuts!

Native Call question. I have a Pointer ($ppSessionInf).

It points to a structure of $pCount bytes.

How do I load what $ppSessionInf points to into $Sessions

 # something gets assigned to it from an API call
 my Pointer $ppSessionInf = Pointer.new();

 # length of the data I want also from the API call
 my DWORD   $pCount;  # length of the data I want

 # Buffer I want the data pointer to by
 # $ppSessionInf loaded into
 my BYTES  $Sessions = CArray[BYTE].new( 0xFF xx $pCount );

 $Sessions = $ppSessionInf.deref;

Which obviously does not work:
   Internal error: unhandled target type

Many thanks,
-T



On Wed, Nov 23, 2022 at 9:21 PM Clifton Wood <mailto:clifton.w...@gmail.com>> wrote:


@ToddAndMargo <mailto:toddandma...@zoho.com> - Did you try my
suggestion with GLib::Roles::TypedBuffer?

The "unhandled target type" occurs when NativeCall can't figure out
how to deref the referenced value. In this case, this would be the
BYTE of the CArray.

What type is BYTE, pray tell?

- Cliff

On Wed, Nov 23, 2022 at 9:08 PM ToddAndMargo via perl6-users
mailto:perl6-users@perl.org>> wrote:

removing my typos:



On 11/23/22 18:22, Clifton Wood wrote:
@ToddAndMargo <mailto:toddandma...@zoho.com> -- Also, Pointer cannot 
deref a Pointer, which I think is the real error.



How do I load what $ppSessionInf points to into $Sessions?




Re: Pointer to bug question

2022-11-23 Thread ToddAndMargo via perl6-users

On 11/23/22 18:21, Clifton Wood wrote:

What type is BYTE, pray tell?



constant BYTE := uint8;



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



Re: Pointer to bug question

2022-11-23 Thread ToddAndMargo via perl6-users

On 11/23/22 18:07, ToddAndMargo via perl6-users wrote:

removing my typos:


Hi All,

This is driving me nuts!

Native Call question. I have a Pointer ($ppSessionInf).

It points to a structure of $pCount bytes.

How do I load what $ppSessionInf points to into $Sessions

    # something gets assigned to it from an API call
    my Pointer $ppSessionInf = Pointer.new();

    # length of the data I want also from the API call
    my DWORD   $pCount;  # length of the data I want

    # Buffer I want the data pointer to by
    # $ppSessionInf loaded into
    my BYTES  $Sessions = CArray[BYTE].new( 0xFF xx $pCount );

    $Sessions = $ppSessionInf.deref;

Which obviously does not work:
  Internal error: unhandled target type

Many thanks,
-T




ppSessionInf = >
pCount = <2>

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



Re: Pointer to bug question

2022-11-23 Thread Clifton Wood
@ToddAndMargo  -- Also, Pointer cannot deref a
Pointer, which I think is the real error.


On Wed, Nov 23, 2022 at 9:21 PM Clifton Wood  wrote:

> @ToddAndMargo  - Did you try my suggestion with
> GLib::Roles::TypedBuffer?
>
> The "unhandled target type" occurs when NativeCall can't figure out how to
> deref the referenced value. In this case, this would be the BYTE of the
> CArray.
>
> What type is BYTE, pray tell?
>
> - Cliff
>
> On Wed, Nov 23, 2022 at 9:08 PM ToddAndMargo via perl6-users <
> perl6-users@perl.org> wrote:
>
>> removing my typos:
>>
>>
>> Hi All,
>>
>> This is driving me nuts!
>>
>> Native Call question. I have a Pointer ($ppSessionInf).
>>
>> It points to a structure of $pCount bytes.
>>
>> How do I load what $ppSessionInf points to into $Sessions
>>
>> # something gets assigned to it from an API call
>> my Pointer $ppSessionInf = Pointer.new();
>>
>> # length of the data I want also from the API call
>> my DWORD   $pCount;  # length of the data I want
>>
>> # Buffer I want the data pointer to by
>> # $ppSessionInf loaded into
>> my BYTES  $Sessions = CArray[BYTE].new( 0xFF xx $pCount );
>>
>> $Sessions = $ppSessionInf.deref;
>>
>> Which obviously does not work:
>>   Internal error: unhandled target type
>>
>> Many thanks,
>> -T
>>
>>


Re: Pointer to bug question

2022-11-23 Thread Clifton Wood
@ToddAndMargo  - Did you try my suggestion with
GLib::Roles::TypedBuffer?

The "unhandled target type" occurs when NativeCall can't figure out how to
deref the referenced value. In this case, this would be the BYTE of the
CArray.

What type is BYTE, pray tell?

- Cliff

On Wed, Nov 23, 2022 at 9:08 PM ToddAndMargo via perl6-users <
perl6-users@perl.org> wrote:

> removing my typos:
>
>
> Hi All,
>
> This is driving me nuts!
>
> Native Call question. I have a Pointer ($ppSessionInf).
>
> It points to a structure of $pCount bytes.
>
> How do I load what $ppSessionInf points to into $Sessions
>
> # something gets assigned to it from an API call
> my Pointer $ppSessionInf = Pointer.new();
>
> # length of the data I want also from the API call
> my DWORD   $pCount;  # length of the data I want
>
> # Buffer I want the data pointer to by
> # $ppSessionInf loaded into
> my BYTES  $Sessions = CArray[BYTE].new( 0xFF xx $pCount );
>
> $Sessions = $ppSessionInf.deref;
>
> Which obviously does not work:
>   Internal error: unhandled target type
>
> Many thanks,
> -T
>
>


Re: Pointer to bug question

2022-11-23 Thread ToddAndMargo via perl6-users

removing my typos:


Hi All,

This is driving me nuts!

Native Call question. I have a Pointer ($ppSessionInf).

It points to a structure of $pCount bytes.

How do I load what $ppSessionInf points to into $Sessions

   # something gets assigned to it from an API call
   my Pointer $ppSessionInf = Pointer.new();

   # length of the data I want also from the API call
   my DWORD   $pCount;  # length of the data I want

   # Buffer I want the data pointer to by
   # $ppSessionInf loaded into
   my BYTES  $Sessions = CArray[BYTE].new( 0xFF xx $pCount );

   $Sessions = $ppSessionInf.deref;

Which obviously does not work:
 Internal error: unhandled target type

Many thanks,
-T



Pointer to bug question

2022-11-23 Thread ToddAndMargo via perl6-users

Hi All,

This is driving me nuts!

Native Call question. I have a Pointer ($ppSessionInf).

It points to a structure of $pCount bytes.

How do I read that into a Buf of $ my DWORD   $pCount   = 0;  bytes?

   my Pointer $ppSessionInf = Pointer.new();
   my DWORD   $pCount   = 32 times something bytes long;
   my BYTES  $Sessions  = CArray[BYTE].new( 0xFF xx $pCount );

How do I load what $ppSessionInf points to into $Sessions

   $Sessions = $ppSessionInf.deref;

Which obviously does not work.

"Internal error: unhandled target type"

  

Many thanks,
-T

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


Re: NativeCall C++ structure question

2022-11-21 Thread ToddAndMargo via perl6-users

On 11/21/22 05:01, ToddAndMargo via perl6-users wrote:

Hi All,

Windows ChromeBook Edition (W11-22H2).

I have been doing a lot of head scratching here.

I have a project were I need to use

     BOOL WTSEnumerateSessionsA(
   [in]  HANDLE hServer,
     # WTS_CURRENT_SERVER_HANDLE to use the RD Session Host server that 
hosts your application.

   [in]  DWORD  Reserved,
   [in]  DWORD  Version,
   [out] PWTS_SESSION_INFOA *ppSessionInfo,
   [out] DWORD  *pCount
     );

to dig out a pointer (*ppSessionInfo) to a
C++ OOP data structure, which is repeated
pCount times.  (No problem coding the above.)

The data structure is
     C++
     typedef struct _WTS_SESSION_INFOA {
    DWORD    SessionId;    # 4 bytes
    LPSTR    pWinStationName;  # 4 or 8 or 12 bytes
    WTS_CONNECTSTATE_CLASS State;  # 4 or 8 bytes maybe
  } WTS_SESSION_INFOA, *PWTS_SESSION_INFOA;


"_WTS_SESSION_INFOA" is 12 bytes in x86 and
24 bytes in x64:

     int nSize1 = sizeof WTS_SESSION_INFOA;
     // 12 in x86, 24 in x64


What I need to do is shown in C++


     WTSEnumerateSessionsA(WTS_CURRENT_SERVER, 0, 1, , )

  for (DWORD i = 0; i < dwCount; i++)
  {
  if (pwsi[i].State == WTSActive)
  {
  dwSession = pwsi[i].SessionId;
  break;
  }
  }


Basically, I need to walk though the C++ structure
looking for State == WTSActive (0), read the
value of SessionId, exit the loop, and return
the value of SessionId.


How in the world do I use NativeCall to read
"_WTS_SESSION_INFOA"'s structure?

I will only be operating in 64 bit, so I take it
I have to create a Buf of 24 bytes.  Then
take the buffer apart using little endian.

And the [i] in the C++ code will be me incrementing
*pCount by 24 bytes each successive read.

Is there an easier way to do this?


Many thanks,
-T

I have to do the above becasue the "SessionID"
is reported incorrectly by M$'s other API's
if you are running your program from the Task
Scheduler

Oh and I almost forgot:  A H !



Another question:

Is there a way to use the returned pointer and
the pCount to to read the data into a Raku
Buf or similar?



NativeCall C++ structure question

2022-11-21 Thread ToddAndMargo via perl6-users

Hi All,

Windows ChromeBook Edition (W11-22H2).

I have been doing a lot of head scratching here.

I have a project were I need to use

BOOL WTSEnumerateSessionsA(
  [in]  HANDLE hServer,
# WTS_CURRENT_SERVER_HANDLE to use the RD Session Host server that 
hosts your application.

  [in]  DWORD  Reserved,
  [in]  DWORD  Version,
  [out] PWTS_SESSION_INFOA *ppSessionInfo,
  [out] DWORD  *pCount
);

to dig out a pointer (*ppSessionInfo) to a
C++ OOP data structure, which is repeated
pCount times.  (No problem coding the above.)

The data structure is
C++
typedef struct _WTS_SESSION_INFOA {
   DWORDSessionId;# 4 bytes
   LPSTRpWinStationName;  # 4 or 8 or 12 bytes
   WTS_CONNECTSTATE_CLASS State;  # 4 or 8 bytes maybe
 } WTS_SESSION_INFOA, *PWTS_SESSION_INFOA;


"_WTS_SESSION_INFOA" is 12 bytes in x86 and
24 bytes in x64:

int nSize1 = sizeof WTS_SESSION_INFOA;
// 12 in x86, 24 in x64


What I need to do is shown in C++


WTSEnumerateSessionsA(WTS_CURRENT_SERVER, 0, 1, , )

 for (DWORD i = 0; i < dwCount; i++)
 {
 if (pwsi[i].State == WTSActive)
 {
 dwSession = pwsi[i].SessionId;
 break;
 }
 }


Basically, I need to walk though the C++ structure
looking for State == WTSActive (0), read the
value of SessionId, exit the loop, and return
the value of SessionId.


How in the world do I use NativeCall to read
"_WTS_SESSION_INFOA"'s structure?

I will only be operating in 64 bit, so I take it
I have to create a Buf of 24 bytes.  Then
take the buffer apart using little endian.

And the [i] in the C++ code will be me incrementing
*pCount by 24 bytes each successive read.

Is there an easier way to do this?


Many thanks,
-T

I have to do the above becasue the "SessionID"
is reported incorrectly by M$'s other API's
if you are running your program from the Task
Scheduler

Oh and I almost forgot:  A H !


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


Re: NativeCall pointer question?

2022-11-20 Thread ToddAndMargo via perl6-users
On Sun, Nov 20, 2022 at 3:48 AM ToddAndMargo via perl6-users 
mailto:perl6-users@perl.org>> wrote:


Hi All,

In one of my native call, I get returned a
pointer to a DWORD (uint32).

How do I turn that into the actual value
in the DWORD?

Many thanks,
-T



On 11/20/22 16:00, Clifton Wood wrote:

@ToddAndMargo,

Two ways:

  - Use "my CArray[uint32] $p", use $p as your parameter, and access the 
value as "$p[0]"


or

- Use "my Pointer[uint32] $p"  and use "$p.deref"

My personal preference is the former, as it is the best way to access 
AND set the actual former value. The latter can only deref. To my 
knowledge, you cannot set the referenced value of a Pointer type. I do 
reserve the right to be wrong on this, though.



Thank you!

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



Re: NativeCall pointer question?

2022-11-20 Thread Clifton Wood
@ToddAndMargo,

Two ways:

 - Use "my CArray[uint32] $p", use $p as your parameter, and access the
value as "$p[0]"

or

- Use "my Pointer[uint32] $p"  and use "$p.deref"

My personal preference is the former, as it is the best way to access AND
set the actual former value. The latter can only deref. To my knowledge,
you cannot set the referenced value of a Pointer type. I do reserve the
right to be wrong on this, though.



On Sun, Nov 20, 2022 at 3:48 AM ToddAndMargo via perl6-users <
perl6-users@perl.org> wrote:

> Hi All,
>
> In one of my native call, I get returned a
> pointer to a DWORD (uint32).
>
> How do I turn that into the actual value
> in the DWORD?
>
> Many thanks,
> -T
>


NativeCall pointer question?

2022-11-20 Thread ToddAndMargo via perl6-users

Hi All,

In one of my native call, I get returned a
pointer to a DWORD (uint32).

How do I turn that into the actual value
in the DWORD?

Many thanks,
-T


Re: BEGIN {} question

2022-09-10 Thread rir
t; 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 may
> have three or four different modules under the lib/ directory. The top level
> program (I try to make it one line only), uses one module, which then may
> use other modules, all of them in the same directory, under the lib/
> subdirectory. The distribution can then also contain simple tests under t/
> and development tests under xt/
> 
> Regards,
> 
> Richard
> 
> On 30/08/2022 2:38 am, 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
> > > 
> > > 
> > 
> > 
> > 
> > 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-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: sprintf and print question

2022-09-02 Thread ToddAndMargo via perl6-users

On 9/1/22 23:50, ToddAndMargo via perl6-users wrote:

On 9/1/22 19:37, ToddAndMargo via perl6-users wrote:

Hi All,

Is there a cleaner way to do this?

 $ raku -e 'print( (sprintf "%.4s", "andefghi" ) ~ "\n";)'
 ande

I want to print the first four letter s to STDOUT.

-T




$ raku -e 'printf "%.4s\n", "andefghi";'
ande



$ raku -e 'print "andefghi".substr(0,4), "\n";'
ande

$ perl6 -I/home/linuxutil/p6lib -e 'use PrintColors :PrintGreen; 
PrintGreen "abcdefghi".substr(0,4), "\n";'

abcd


Re: sprintf and print question

2022-09-02 Thread ToddAndMargo via perl6-users

On 9/1/22 19:37, ToddAndMargo via perl6-users wrote:

Hi All,

Is there a cleaner way to do this?

     $ raku -e 'print( (sprintf "%.4s", "andefghi" ) ~ "\n";)'
     ande

I want to print the first four letter s to STDOUT.

-T




$ raku -e 'printf "%.4s\n", "andefghi";'
ande


Thank you all!

-T


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: sprintf and print question

2022-09-01 Thread William Michels via perl6-users
Hi Todd,

~$ raku -e '(sprintf "%.4s", "andefghi" ).put;'
ande
~$ raku -e 'put (sprintf "%.4s", "andefghi" );'
ande

If sprintf isn't a requirement, then:

~$ raku -e 'put substr("andefghi", 0..3);'
ande

HTH, Bill.


On Thu, Sep 1, 2022 at 7:37 PM ToddAndMargo via perl6-users <
perl6-users@perl.org> wrote:

> Hi All,
>
> Is there a cleaner way to do this?
>
>  $ raku -e 'print( (sprintf "%.4s", "andefghi" ) ~ "\n";)'
>  ande
>
> I want to print the first four letter s to STDOUT.
>
> -T
>


Re: sprintf and print question

2022-09-01 Thread Andinus via perl6-users

ToddAndMargo via perl6-users @ 2022-09-01 19:37 -07:

> Is there a cleaner way to do this?
>
> $ raku -e 'print( (sprintf "%.4s", "andefghi" ) ~ "\n";)'
> ande
>
> I want to print the first four letter s to STDOUT.

You can use substr,

  | put "andefghi".substr(0, 4)
  ande


signature.asc
Description: PGP signature


Re: sprintf and print question

2022-09-01 Thread Norman Gaywood
On Fri, 2 Sept 2022 at 12:37, ToddAndMargo via perl6-users <
perl6-users@perl.org> wrote:

> Is there a cleaner way to do this?
>
>  $ raku -e 'print( (sprintf "%.4s", "andefghi" ) ~ "\n";)'
>  ande
>
> I want to print the first four letter s to STDOUT.
>

 $ raku -e 'printf "%.4s\n","andefghi"'
ande

-- 
Norman Gaywood, Computer Systems Officer
School of Science and Technology
University of New England
Armidale NSW 2351, Australia

ngayw...@une.edu.au  http://turing.une.edu.au/~ngaywood
Phone: +61 (0)2 6773 2412  Mobile: +61 (0)4 7862 0062

Please avoid sending me Word or Power Point attachments.
See http://www.gnu.org/philosophy/no-word-attachments.html


sprintf and print question

2022-09-01 Thread ToddAndMargo via perl6-users

Hi All,

Is there a cleaner way to do this?

$ raku -e 'print( (sprintf "%.4s", "andefghi" ) ~ "\n";)'
ande

I want to print the first four letter s to STDOUT.

-T


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-users@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
tware, 
I may have three or four different modules under the lib/ directory. The 
top level program (I try to make it one line only), uses one module, 
which then may use other modules, all of them in the same directory, 
under the lib/ subdirectory. The distribution can then also contain 
simple tests under t/ and development tests under xt/


Regards,

Richard

On 30/08/2022 2:38 am, 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






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/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-users@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-users@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)



BEGIN {} question

2022-08-28 Thread ToddAndMargo via perl6-users

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


--

If I had a dime every time I didn't know
what was going on, I'd be like, "Why is
everyone giving me all these dimes?"



Re: Hex string to buf question

2022-06-19 Thread ToddAndMargo via perl6-users

On 6/19/22 03:06, ToddAndMargo via perl6-users wrote:

On 6/19/22 00:33, ToddAndMargo via perl6-users wrote:

Hi All,

I have a string:

 > my Str $x = "1BB67AE85A";
1BB67AE85A

which has the hexadecimal values I want to
add to a buffer:

 > my buf8 $y = buf8.new($x.base(16));
No such method 'base' for invocant of type 'Str'.  Did you mean any of
these: 'Bag', 'Date', 'Hash', 'are', 'asec', 'hash', 'take'?
   in block  at  line 1

In other words, I want to set $y to
    0x1B 0xB6 0x7A 0xE8 0x5A

How do I do this?

Many thanks,
-T





The guys on the chat line helped me figure it
out.  Give me a few minutes to pretty it up
and report back.



Hexadecimal string to Buffer:

Quick example:
> my Str $x = '0x84 0x73 0x77 0x84 0x79 0x87 0x84 0x68 0x73'

> my buf8 $y = buf8.new($x.match(/( ** 2)/, 
:g)».Str».parse-base(16));

Buf[uint8]:0x<84 73 77 84 79 87 84 68 73>


More in depth:

> use BigRoot;
Nil

>  BigRoot.precision = 10;
10

> my $BigNum  = BigRoot.newton's-sqrt: 11
3.3166247904

> my Str $MyCypher  = sprintf $BigNum.base(16);
3.510E527FE

> $MyCypher ~~ s/ '.' //;
「.」

> $MyCypher ~~ s:g/ (..) /0x$0, /;
(「3」
 0 => 「3」 「51」
 0 => 「51」 「0E」
 0 => 「0E」 「52」
 0 => 「52」 「7F」
 0 => 「7F」)

> $MyCypher ~~ s/ (.*) $(Q[,]) /$0/;
「0x3, 0x51, 0x0E, 0x52, 0x7F,」
 0 => 「0x3, 0x51, 0x0E, 0x52, 0x7F」

> my buf8 $MyCypherBuf = buf8.new($MyCypher.match(/( ** 2)/, 
:g)».Str».parse-base(16));

Buf[uint8]:0x<51 0E 52 7F>




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


Re: Hex string to buf question

2022-06-19 Thread ToddAndMargo via perl6-users

On 6/19/22 00:33, ToddAndMargo via perl6-users wrote:

Hi All,

I have a string:

 > my Str $x = "1BB67AE85A";
1BB67AE85A

which has the hexadecimal values I want to
add to a buffer:

 > my buf8 $y = buf8.new($x.base(16));
No such method 'base' for invocant of type 'Str'.  Did you mean any of
these: 'Bag', 'Date', 'Hash', 'are', 'asec', 'hash', 'take'?
   in block  at  line 1

In other words, I want to set $y to
    0x1B 0xB6 0x7A 0xE8 0x5A

How do I do this?

Many thanks,
-T





The guys on the chat line helped me figure it
out.  Give me a few minutes to pretty it up
and report back.


Re: Hex string to buf question

2022-06-19 Thread ToddAndMargo via perl6-users

On 6/19/22 00:33, ToddAndMargo via perl6-users wrote:

Hi All,

I have a string:

 > my Str $x = "1BB67AE85A";
1BB67AE85A

which has the hexadecimal values I want to
add to a buffer:

 > my buf8 $y = buf8.new($x.base(16));
No such method 'base' for invocant of type 'Str'.  Did you mean any of
these: 'Bag', 'Date', 'Hash', 'are', 'asec', 'hash', 'take'?
   in block  at  line 1

In other words, I want to set $y to
    0x1B 0xB6 0x7A 0xE8 0x5A

How do I do this?

Many thanks,
-T





Won't let me push an integer on a buffer either:

> my buf8 $y;

> $a
-68

> $y.push($a.Buf)
No such method 'Buf' for invocant of type 'Int'
  in block  at  line 1




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


Hex string to buf question

2022-06-19 Thread ToddAndMargo via perl6-users

Hi All,

I have a string:

> my Str $x = "1BB67AE85A";
1BB67AE85A

which has the hexadecimal values I want to
add to a buffer:

> my buf8 $y = buf8.new($x.base(16));
No such method 'base' for invocant of type 'Str'.  Did you mean any of
these: 'Bag', 'Date', 'Hash', 'are', 'asec', 'hash', 'take'?
  in block  at  line 1

In other words, I want to set $y to
   0x1B 0xB6 0x7A 0xE8 0x5A

How do I do this?

Many thanks,
-T


--

If I had a dime every time I didn't know
what was going on, I'd be like, "Why is
everyone giving me all these dimes?"



Re: append to Bug question

2022-06-19 Thread ToddAndMargo via perl6-users

Typo.

Should have been:

append to Buf question

And in my Keeper, I keep typing "bugger" instead
of "buffer".  Can't win.


Re: append to Bug question

2022-06-19 Thread ToddAndMargo via perl6-users

On 6/18/22 22:58, Bruce Gray wrote:

If all you want is to append 0xBB to $y, either of these will work:
$y ~= Buf.new(0xBB);
$y.append(0xBB);



Did not realize I could use buf new like that.  Thank you!


Append numbers to a buffer:
   > $x
   Buf:0x<41 42 43 44>
   > $x.append( 0xDD );
   Buf:0x<41 42 43 44 DD>
   > $x.append( 0xEE..0xF1 );
   Buf:0x<41 42 43 44 DD EE EF F0 F1>
   > $x.append( 0xA1, 0xA3, 0xA5 );
   Buf:0x<41 42 43 44 DD EE EF F0 F1 A1 A3 A5>
   $x ~= buf8.new( 0xBB, 0xBC );
   Buf:0x<41 42 43 44 DD EE EF F0 F1 A1 A3 A5 BB BC>



Re: append to Bug question

2022-06-19 Thread ToddAndMargo via perl6-users

On 6/18/22 22:58, Bruce Gray wrote:


 From just looking at your code, I am not clear on what you are trying to do.


I am updating my Keeper on buffers.  I have four of them
that are a mess and I an going to consolidate them into
a single .ODT (open document text) file with an index.




Re: append to Bug question

2022-06-18 Thread Bruce Gray



> On Jun 18, 2022, at 11:13 PM, ToddAndMargo via perl6-users 
>  wrote:
> 
> Hi All,
> 
> What am I doing wrong here:

From just looking at your code, I am not clear on what you are trying to do.

> > my Buf $y = Buf.new( 0xFA xx 10);
> Buf:0x
> 
> > $y ~= 0xBB.encode.Buf;
> Buf:0x
> 
> I got three entries (31 38 37) instead of one (0xBB)

Yes, because:
raku -e 'say 0xBB.encode;'
utf8:0x<31 38 37>


> Some more goofing around:
> > $y ~= 0xBB;
> Stringification of a Buf is not done with 'Str'.  The 'decode' method should 
> be used to convert a Buf to a Str.
> [10] > $y += 0xBB;
> Type check failed in assignment to $y; expected Buf but got Int (201)

--snip--

If all you want is to append 0xBB to $y, either of these will work:
$y ~= Buf.new(0xBB);
$y.append(0xBB);

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



Re: append to Bug question

2022-06-18 Thread ToddAndMargo via perl6-users

On 6/18/22 21:13, ToddAndMargo via perl6-users wrote:

Hi All,

What am I doing wrong here:

 > my Buf $y = Buf.new( 0xFA xx 10);
Buf:0x

 > $y ~= 0xBB.encode.Buf;
Buf:0x

I got three entries (31 38 37) instead of one (0xBB)


Some more goofing around:

 > $y ~= 0xBB;
Stringification of a Buf is not done with 'Str'.  The 'decode' method
should be used to convert a Buf to a Str.
   in block  at  line 1

[10] > $y += 0xBB;
Type check failed in assignment to $y; expected Buf but got Int (201)
   in block  at  line 1



Many thanks,
-T


Figured it out.  Use `append`:

   > $x
   Buf:0x<41 42 43 44>

   > $x.append( 0xDD );
   Buf:0x<41 42 43 44 DD>

   > $x.append( 0xEE..0xF1 );
   Buf:0x<41 42 43 44 DD EE EF F0 F1>

   > $x.append( 0xA1, 0xA3, 0xA5 );
   Buf:0x<41 42 43 44 DD EE EF F0 F1 A1 A3 A5>



Re: append to Bug question

2022-06-18 Thread ToddAndMargo via perl6-users

On 6/18/22 22:12, ToddAndMargo via perl6-users wrote:

What am I doing wrong here too?

my $d = buf8.new( 0xDE..0xDB );
Buf[uint8]:0x<>



Not sure why the above did not work, but this does:

Presalt with swept entries:
   > my buf8 $e = buf8.new(0x5..0x8);
   Buf[uint8]:0x<05 06 07 08>

   > my buf8 $e = buf8.new(0x5A..0x5D);
   Buf[uint8]:0x<5A 5B 5C 5D>



Re: append to Bug question

2022-06-18 Thread ToddAndMargo via perl6-users

What am I doing wrong here too?

my $d = buf8.new( 0xDE..0xDB );
Buf[uint8]:0x<>


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


append to Bug question

2022-06-18 Thread ToddAndMargo via perl6-users

Hi All,

What am I doing wrong here:

> my Buf $y = Buf.new( 0xFA xx 10);
Buf:0x

> $y ~= 0xBB.encode.Buf;
Buf:0x

I got three entries (31 38 37) instead of one (0xBB)


Some more goofing around:

> $y ~= 0xBB;
Stringification of a Buf is not done with 'Str'.  The 'decode' method
should be used to convert a Buf to a Str.
  in block  at  line 1

[10] > $y += 0xBB;
Type check failed in assignment to $y; expected Buf but got Int (201)
  in block  at  line 1



Many thanks,
-T



--
~
When we ask for advice, we are usually looking for an accomplice.
   --  Charles Varlet de La Grange
~


Re: Dual Buf and Str question

2022-06-11 Thread ToddAndMargo via perl6-users

On 6/11/22 02:28, ToddAndMargo via perl6-users wrote:

On 6/9/22 22:54, ToddAndMargo via perl6-users wrote:

Hi All,

I can easily  get away with this in Modula2, but
how can I do this with Raku?

I wish to create a single variable that can be
manipulated in two ways:

1) as a fixed length string (Str)

2) as a fixed length buffer (Buf)

I can think of ways to do this, but it would
require separate variable and conversions routines
back and forth.

Any words of Raku wisdom?

Many thanks,
-T




Hi All,

I do believe what I am asking is not possible in
Raku.  In Modula2, it is ridiculously easy to
do. But there is a fly in the ointment.  There
is a possibility of chr(0)'s in the resultant
string.  And in Modula2, as is in C, that is
a string terminator.  So Raku is a much better
choice, as the length of a string is kept in
a hidden structure and not in the the string
itself.  And I am done with Modula2 and use
Raku for a reason.

Anyway, I have been wrapping my mind around
how to do this in Raku.  With some chr's and
ord's, I can accomplish what I need.  And
some string tricks I learned in Perl 5.

When I come up working module for this, I
will get back.  I think you all will find it
very useful.  Ya, I know I am being
a bit cryptic, but all will be revealed.
Eventually.

:-)

-T


Hi All,

Thank you for all the help and tips on this!

One of the unusual decisions Raku make concerning
string was the that would only have one element and
you could not address the indexes as you would an
array. `.elems` will always be 1.  (Use `.chars`
instead.)

But, they came up with a way to do it anyway
called `substr-rw`.

This gives me the ability to do:


BigRoot.precision = $SourceStr.chars * 2;
$BigNum= BigRoot.newton's-sqrt: $PrimeNumber;
$MyCypher  = sprintf $BigNum.base(16);
$MyCypher ~~ s/ $( Q[.] ) //;

loop  (my $Index=0; $Index < $SourceStr.chars; $Index += 1) {
   $ScrambleStr ~= chr( ord($SourceStr.substr-rw( $Index, 1 ) ) +^ 
ord( $MyCypher.substr-rw( $Index, 1 ) ) );

   # print $ScrambleStr ~ "\n";
}


And now you know what I am up to.   I am placing
a string with somewhat private information up on a
web file sharing service and needed to get around:

1) data mining
2) prying employees eyes
3) hackers

And yes, there is a hardened password.

So in other words, despite what the services say, there is zero trust.

Running the scrambled string back through the
above gets you your original text back.

Is it just me, or does `sprintf` just blow your
mind on how useful it is.  Beats the heck out of
a beginner trying to figure out the "encode"
intricacies.




My keeper on String indexes.  (I show how
the read, not just write.  The doc page
only shows how to write or I could not
find it):

Raku: reading and writing to a string's index:

Reference:
https://docs.raku.org/routine/substr-rw
https://raku.land/github:thundergnat/String::Splice

Note: Raku's Strings can not be directly addressed
  by their indexes, as you can other arrays.
  Therefore .elems will always be 1.  Use
  .chars instead

  Use `substr-rw` to work around this.


method substr-rw($from, $length = *)


> my Str $i="abcdef"
abcdef

> say $i.substr-rw(2, 1)
c

$i.substr-rw(2, 1) ="x"
x

> say $i
abxdef


> loop (my $j=0; $j < $i.chars; $j += 1) {say "$i.substr-rw($j,1)";}
a
b
x
d
e
f


Re: BigRoot precision question

2022-06-11 Thread Bruce Gray



> On Jun 11, 2022, at 4:41 AM, ToddAndMargo via perl6-users 
>  wrote:
> 
> Hi All,
> 
> In the following paper on Big Root:
> 
> https://newbedev.com/how-can-i-set-the-level-of-precision-for-raku-s-sqrt
> 
> 
> > use BigRoot;
> > BigRoot.precision = 7;
> > say (BigRoot.newton's-sqrt: 2;).base(10)
> 1.4142136
> > say (BigRoot.newton's-sqrt: 2;).base(16)
> 1.6A09E7
> 
> That is a base(10) precision.  In base(16) (Hex)
> that is only 3 digits past the decimal.
>0x6A-0x09-0xE7
> 
> Is there a way to tell BigRoot I want a certain
> amount of Hex digits I want after the decimal?

No, https://github.com/juliodcs/BigRoot/blob/master/lib/BigRoot.rakumod shows 
that BigRoot only allows setting precision as decimal.

> Or just ask for double I want and prune afterwards?

Doubling your desired precision is overkill; you only need a 21% increase. 
Since:
decimal_precision =~= ( hexadecimal_precision_wanted * log(16) / log(10) );
, this should work:
BigRoot.precision = ( $hexadecimal_precision_wanted * log10(16) ).ceiling;

As evidence:
my $hexadecimal_precision_wanted = 2 ** 13;
my $decimal_precision_via_log= ( $hexadecimal_precision_wanted * 
log10(16) ).ceiling;
my $largest_hex_number_that_size = 'F' x $hexadecimal_precision_wanted;
my $decimal_precision_via_chars  = 
$largest_hex_number_that_size.parse-base(16).chars;
.say for ( :$hexadecimal_precision_wanted, :$decimal_precision_via_log, 
:$decimal_precision_via_chars );
Output:
hexadecimal_precision_wanted => 8192
decimal_precision_via_log => 9865
decimal_precision_via_chars => 9865

-- 
Hope this helps,
Bruce Gray (Util of PerlMonks) [who just learned of the BigRoot module]



BigRoot precision question

2022-06-11 Thread ToddAndMargo via perl6-users

Hi All,

In the following paper on Big Root:

https://newbedev.com/how-can-i-set-the-level-of-precision-for-raku-s-sqrt


> use BigRoot;
> BigRoot.precision = 7;
> say (BigRoot.newton's-sqrt: 2;).base(10)
1.4142136
> say (BigRoot.newton's-sqrt: 2;).base(16)
1.6A09E7

That is a base(10) precision.  In base(16) (Hex)
that is only 3 digits past the decimal.
0x6A-0x09-0xE7

Is there a way to tell BigRoot I want a certain
amount of Hex digits I want after the decimal?

Or just ask for double I want and prune afterwards?


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: Dual Buf and Str question

2022-06-11 Thread ToddAndMargo via perl6-users

On 6/9/22 22:54, ToddAndMargo via perl6-users wrote:

Hi All,

I can easily  get away with this in Modula2, but
how can I do this with Raku?

I wish to create a single variable that can be
manipulated in two ways:

1) as a fixed length string (Str)

2) as a fixed length buffer (Buf)

I can think of ways to do this, but it would
require separate variable and conversions routines
back and forth.

Any words of Raku wisdom?

Many thanks,
-T




Hi All,

I do believe what I am asking is not possible in
Raku.  In Modula2, it is ridiculously easy to
do. But there is a fly in the ointment.  There
is a possibility of chr(0)'s in the resultant
string.  And in Modula2, as is in C, that is
a string terminator.  So Raku is a much better
choice, as the length of a string is kept in
a hidden structure and not in the the string
itself.  And I am done with Modula2 and use
Raku for a reason.

Anyway, I have been wrapping my mind around
how to do this in Raku.  With some chr's and
ord's, I can accomplish what I need.  And
some string tricks I learned in Perl 5.

When I come up working module for this, I
will get back.  I think you all will find it
very useful.  Ya, I know I am being
a bit cryptic, but all will be revealed.
Eventually.

:-)

-T


Re: Dual Buf and Str question

2022-06-10 Thread ToddAndMargo via perl6-users

On 6/10/22 02:36, Elizabeth Mattijsen wrote:

On 10 Jun 2022, at 11:20, ToddAndMargo via perl6-users  
wrote:


On 10 Jun 2022, at 07:54, ToddAndMargo via perl6-users  
wrote:

Hi All,

I can easily  get away with this in Modula2, but
how can I do this with Raku?

I wish to create a single variable that can be
manipulated in two ways:

1) as a fixed length string (Str)

2) as a fixed length buffer (Buf)

I can think of ways to do this, but it would
require separate variable and conversions routines
back and forth.

Any words of Raku wisdom?

Many thanks,
-T


On 6/10/22 01:23, Elizabeth Mattijsen wrote:

Perhaps https://raku.land/zef:raku-community-modules/Pythonic::Str is what 
you're after?


No really.

Maybe if I was to tell you what I am trying to do.

I am trying to do a bitwise XOR on each byte
against another Buf.  Then I want it to act
like a string again.

I want the variable to act as both an array
of characters and a binary array of bytes.


Convert a string to a Buf:  say "abc".encode.Buf;  # Buf:0x<61 62 63>
Convert a Buf to a Str: say Buf.new(97,98,99).decode;  # abc

Technically, I think the .encode is enough for what you want:

say "abc".encode.does(Blob);  # True



I like it.  Thank you!



Re: Dual Buf and Str question

2022-06-10 Thread Elizabeth Mattijsen
> On 10 Jun 2022, at 11:20, ToddAndMargo via perl6-users  
> wrote:
> 
>>> On 10 Jun 2022, at 07:54, ToddAndMargo via perl6-users 
>>>  wrote:
>>> 
>>> Hi All,
>>> 
>>> I can easily  get away with this in Modula2, but
>>> how can I do this with Raku?
>>> 
>>> I wish to create a single variable that can be
>>> manipulated in two ways:
>>> 
>>> 1) as a fixed length string (Str)
>>> 
>>> 2) as a fixed length buffer (Buf)
>>> 
>>> I can think of ways to do this, but it would
>>> require separate variable and conversions routines
>>> back and forth.
>>> 
>>> Any words of Raku wisdom?
>>> 
>>> Many thanks,
>>> -T
> 
> On 6/10/22 01:23, Elizabeth Mattijsen wrote:
>> Perhaps https://raku.land/zef:raku-community-modules/Pythonic::Str is what 
>> you're after?
> 
> No really.
> 
> Maybe if I was to tell you what I am trying to do.
> 
> I am trying to do a bitwise XOR on each byte
> against another Buf.  Then I want it to act
> like a string again.
> 
> I want the variable to act as both an array
> of characters and a binary array of bytes.

Convert a string to a Buf:  say "abc".encode.Buf;  # Buf:0x<61 62 63>
Convert a Buf to a Str: say Buf.new(97,98,99).decode;  # abc

Technically, I think the .encode is enough for what you want:

say "abc".encode.does(Blob);  # True

Re: Dual Buf and Str question

2022-06-10 Thread ToddAndMargo via perl6-users

On 10 Jun 2022, at 07:54, ToddAndMargo via perl6-users  
wrote:

Hi All,

I can easily  get away with this in Modula2, but
how can I do this with Raku?

I wish to create a single variable that can be
manipulated in two ways:

1) as a fixed length string (Str)

2) as a fixed length buffer (Buf)

I can think of ways to do this, but it would
require separate variable and conversions routines
back and forth.

Any words of Raku wisdom?

Many thanks,
-T


On 6/10/22 01:23, Elizabeth Mattijsen wrote:

Perhaps https://raku.land/zef:raku-community-modules/Pythonic::Str is what 
you're after?


No really.

Maybe if I was to tell you what I am trying to do.

I am trying to do a bitwise XOR on each byte
against another Buf.  Then I want it to act
like a string again.

I want the variable to act as both an array
of characters and a binary array of bytes.




Re: Dual Buf and Str question

2022-06-10 Thread Elizabeth Mattijsen
Perhaps https://raku.land/zef:raku-community-modules/Pythonic::Str is what 
you're after?

> On 10 Jun 2022, at 07:54, ToddAndMargo via perl6-users  
> wrote:
> 
> Hi All,
> 
> I can easily  get away with this in Modula2, but
> how can I do this with Raku?
> 
> I wish to create a single variable that can be
> manipulated in two ways:
> 
> 1) as a fixed length string (Str)
> 
> 2) as a fixed length buffer (Buf)
> 
> I can think of ways to do this, but it would
> require separate variable and conversions routines
> back and forth.
> 
> Any words of Raku wisdom?
> 
> Many thanks,
> -T
> 
> -- 
> ~~
> Computers are like air conditioners.
> They malfunction when you open windows
> ~~



Dual Buf and Str question

2022-06-09 Thread ToddAndMargo via perl6-users

Hi All,

I can easily  get away with this in Modula2, but
how can I do this with Raku?

I wish to create a single variable that can be
manipulated in two ways:

1) as a fixed length string (Str)

2) as a fixed length buffer (Buf)

I can think of ways to do this, but it would
require separate variable and conversions routines
back and forth.

Any words of Raku wisdom?

Many thanks,
-T

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


  1   2   3   4   5   6   7   >