Re: trouble returning a value from sub

2022-06-18 Thread ToddAndMargo via perl6-users

On 6/16/22 10:10, Rick Bychowski wrote:

sub MAIN($n = 20) {
    .say for factors($n); # Nil
}



I thought `MAIN` was a reserved variable.  Am
I missing something?


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


Re: trouble returning a value from sub

2022-06-18 Thread Bruce Gray



> On Jun 18, 2022, at 10:42 PM, ToddAndMargo via perl6-users 
>  wrote:
> 
> On 6/16/22 10:10, Rick Bychowski wrote:
>> sub MAIN($n = 20) {
>>.say for factors($n); # Nil
>> }
> 
> 
> I thought `MAIN` was a reserved variable.  Am
> I missing something?

MAIN has a special meaning as a sub name; it declares a CLI (command-line 
interface).

Just like this code declares a subroutine (that you can call within your 
program) that expects two filenames and an optional flag :
sub do_it ( $file1, $file2, Bool :$dry-run ) {
...
}
, the same signature in a sub named "MAIN" declares that your whole script is 
to be called on the command-line with two filenames and an optional flag :
sub MAIN ( $file1, $file2, Bool :$dry-run ) {
...
}

If I call that script like this:
./myscript.raku a.txt b.txt
, then MAIN gets 'a.txt' in $file1 and 'b.txt' in $file2. If I call it badly:
./myscript.raku a.txt b.txt c.txt
, then I get an error, with a usage message auto-generated by Raku:
myscript.raku [--dry-run]  

For full details, see:
https://docs.raku.org/language/create-cli#index-entry-MAIN

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

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 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 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 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: trouble returning a value from sub

2022-06-18 Thread ToddAndMargo via perl6-users

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




On Jun 18, 2022, at 10:42 PM, ToddAndMargo via perl6-users 
 wrote:

On 6/16/22 10:10, Rick Bychowski wrote:

sub MAIN($n = 20) {
.say for factors($n); # Nil
}



I thought `MAIN` was a reserved variable.  Am
I missing something?


MAIN has a special meaning as a sub name; it declares a CLI (command-line 
interface).

Just like this code declares a subroutine (that you can call within your 
program) that expects two filenames and an optional flag :
 sub do_it ( $file1, $file2, Bool :$dry-run ) {
 ...
 }
, the same signature in a sub named "MAIN" declares that your whole script is 
to be called on the command-line with two filenames and an optional flag :
 sub MAIN ( $file1, $file2, Bool :$dry-run ) {
 ...
 }

If I call that script like this:
 ./myscript.raku a.txt b.txt
, then MAIN gets 'a.txt' in $file1 and 'b.txt' in $file2. If I call it badly:
 ./myscript.raku a.txt b.txt c.txt
, then I get an error, with a usage message auto-generated by Raku:
 myscript.raku [--dry-run]  

For full details, see:
https://docs.raku.org/language/create-cli#index-entry-MAIN




I can definitely see a usage for that!  Thank you!


I currently use something like this:


# Note: @*ARGS[x] starts counting at 0
if @*ARGS.elems > 0  {
   $Usage   = lc "@*ARGS[0]";# lc = lower case
   if $Usage eq "--debug" || $Usage eq "debug" {
  $Debug = True;
  $Usage = "";
   } else {
  $RunSpecific = "@*ARGS[0]";
  $Debug   = True;
   }
}


if ( "$Usage" eq "--help" || "$Usage" eq "help" || "$Usage" eq "-?" || 
"$Usage" eq "/?" ) {

   PrintGreen "Usage: $IAm [ debug | --help ] [ Run_Specific_Module ] \n";
   PrintGreen "   $IAm debug Run_Specific_Module\n";
   PrintGreen "   $IAm debug GetADWCleaner\n\n";
   PrintGreen "Note: module name is case sensititive; debug 
and help are not\n";

   exit;
}