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


Re: Primitive benchmark comparison (parsing LDIF)

2021-10-28 Thread Norman Gaywood
On Fri, 29 Oct 2021 at 09:14, Norman Gaywood  wrote:

>
> Might have to test this example again on 2021.10 (not easy for me).
>

I mean, test again on 2021.9 to see if there was a regex speed up in
2021.10

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


Re: Primitive benchmark comparison (parsing LDIF)

2021-10-28 Thread Norman Gaywood
On Fri, 29 Oct 2021 at 00:46, yary  wrote:

> A small thing to begin with in the regex  m/ ^ (@attributes) ':' \s (.+)
> $ /;
> m/ ^ (@attributes) ': ' (.*) $ /;
>

Yes, nice cleanup. Thanks.


> Next, how about adding a 2nd regex test similar to the "split" that also
> relies on User ignoring unknown fields? This accepts an empty-string key,
> which the "split" string handler does too.
>
> m/ ^ (<-[:]>*) ': ' (.*) /;
>

$ ./icheck.raku regex2
41391 entries by regex2 in 4.615332639 seconds

Woh! That was surprising. The new regex is only about 2x slower than the
"split" method.

I did read on SO that someone claimed " longest-match alternation of the
list's elements" is slow.
But I thought the conclusion in the answers was that, in general, regex's
are slow.

Might have to test this example again on 2021.10 (not easy for me).


>>> Results for rakudo-pkg-2021.9.0-01:
>>> $ ./icheck.raku regex
>>> 41391 entries by regex in 27.859560887 seconds
>>> $ ./icheck.raku starts
>>> 41391 entries by starts-with in 5.970667533 seconds
>>> $ ./icheck.raku split
>>> 41391 entries by split in 5.12252741 seconds
>>>
>>> Results for rakudo-pkg-2021.10.0-01
>>> $ ./icheck.raku regex
>>> 41391 entries by regex in 27.833870158 seconds
>>> $ ./icheck.raku starts
>>> 41391 entries by starts-with in 2.560101599 seconds
>>> $ ./icheck.raku split
>>> 41391 entries by split in 2.307679407 seconds
>>>
>>>
--
 #!/usr/bin/env raku

class User {
has $.uid;
has $.uidNumber;
has $.gidNumber;
has $.homeDirectory;
has $.mode = 0;

method attributes {
   # return ;
   User.^attributes(:local)>>.name>>.substr(2);  # Is the order
guaranteed?
}
}

# Read user info from LDIF file
my %ldap;
my @attributes = User.attributes;

multi MAIN ( "regex", $ldif-fn = "db/icheck.ldif" ) {
my ( %f );
for $ldif-fn.IO.lines -> $line {
when not $line {  # blank line is LDIF entry terminator
%ldap{%f} = User.new( |%f );
}
when $line.starts-with( 'dn: ' ) { %f = () }   # dn: starts a new
entry

next unless $line ~~ m/ ^ (@attributes) ': ' (.*) $ /;
%f{$0} = "$1";
}
say "{%ldap.elems} entries by regex in {now - BEGIN now} seconds";
}

multi MAIN ( "regex2", $ldif-fn = "db/icheck.ldif" ) {
my ( %f );
for $ldif-fn.IO.lines -> $line {
when not $line {  # blank line is LDIF entry terminator
%ldap{%f} = User.new( |%f );
}
when $line.starts-with( 'dn: ' ) { %f = () }   # dn: starts a new
entry

next unless $line ~~ m/ ^ (<-[:]>*) ': ' (.*) $ /;
%f{$0} = "$1";
}
say "{%ldap.elems} entries by regex2 in {now - BEGIN now} seconds";
}

multi MAIN ( "starts", $ldif-fn = "db/icheck.ldif" ) {
my ( %f );
for $ldif-fn.IO.lines -> $line {
when not $line {  # blank line is LDIF entry terminator
%ldap{%f} = User.new( |%f );
}
when $line.starts-with( 'dn: ' ) { %f = () }   # dn: starts a new
entry

for @attributes -> $a {
if $line.starts-with( $a ~ ": " ) {
   %f{$a} = (split( ": ", $line, 2))[1];
   last;
}
 }
}
say "{%ldap.elems} entries by starts-with in {now - BEGIN now} seconds";
}

multi MAIN ( "split", $ldif-fn = "db/icheck.ldif" ) {
my ( %f, $k, $v );
for $ldif-fn.IO.lines -> $line {
when not $line {  # blank line is LDIF entry terminator
%ldap{%f} = User.new( |%f ); # attributes not used
are ignored
}
when $line.starts-with( 'dn: ' ) { %f = () }   # dn: starts a new
entry

($k, $v) = split( ": ", $line, 2);
%f{$k} = $v;
}
say "{%ldap.elems} entries by split in {now - BEGIN now} seconds";
}



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


Re: Primitive benchmark comparison (parsing LDIF)

2021-10-28 Thread Norman Gaywood
Oh, and I welcome suggestions on how I might do the task more quickly,
elegantly, differently, etc :-)
And critiques of the code also welcome. I still have a strong perl5 accent
I suspect.

On Thu, 28 Oct 2021 at 13:15, Norman Gaywood  wrote:

> Executive summary:
>  - comparing raku 2021.10 with raku 2021.9
>  -comparing 3 ways of parsing (although the 2 string function ways are
> similar)
> - raku 2021.10 is better than 2 times as fast as 2021.9 using the
> string functions
> - raku 2021.10 is about the same as 2021.9 using a more general
> regular expression
> - regular expressions are still slow in 2021.10
>
> Side note: not shown here is also parsing with Text::LDIF. In 2021.9 it
> was comparable to the regex method. Not tried with 2021.10.
>
> I need to parse a 40K entry LDIF file.
>
> Below is some code that uses 3 ways to parse.
> There are 3 MAIN subs that differ in a few last lines of the for loop.
> The loop reads the LDIF entries and populates %ldap keyed on the "uid" of
> the LDIF entry.
> The values of %ldap are User objects.
> A %f hash is used to build the values of User on each LDIF entry
>
> The aim is to show the difference in timings between 3 ways of parsing the
> LDIF
>
> The 1st MAIN (regex) uses this general regular expression to build %f
>  next unless $line ~~ m/ ^ (@attributes) ':' \s (.+) $ /;
> %f{$0} = "$1";
>
> The "starts" MAIN uses starts-with() to build %f
>for @attributes -> $a {
> if $line.starts-with( $a ~ ": " ) {
>%f{$a} = (split( ": ", $line, 2))[1];
>last;
> }
>
> And finally the "split" MAIN uses split() but also uses the feature that
> User.new() will ignore attributes that are not used.
> ($k, $v) = split( ": ", $line, 2);
> %f{$k} = $v;
>
> That's the difference between the MAIN()'s below. Sorry I couldn't golf it
> down more.
> Running the benchmarks multiple times does vary the times slightly but not
> significantly.
>
> Results for rakudo-pkg-2021.9.0-01:
> $ ./icheck.raku regex
> 41391 entries by regex in 27.859560887 seconds
> $ ./icheck.raku starts
> 41391 entries by starts-with in 5.970667533 seconds
> $ ./icheck.raku split
> 41391 entries by split in 5.12252741 seconds
>
> Results for rakudo-pkg-2021.10.0-01
> $ ./icheck.raku regex
> 41391 entries by regex in 27.833870158 seconds
> $ ./icheck.raku starts
> 41391 entries by starts-with in 2.560101599 seconds
> $ ./icheck.raku split
> 41391 entries by split in 2.307679407 seconds
>
> -
> #!/usr/bin/env raku
>
> class User {
> has $.uid;
> has $.uidNumber;
> has $.gidNumber;
> has $.homeDirectory;
> has $.mode = 0;
>
> method attributes {
># return ;
>User.^attributes(:local)>>.name>>.substr(2);  # Is the order
> guaranteed?
> }
> }
>
> # Read user info from LDIF file
> my %ldap;
> my @attributes = User.attributes;
>
> multi MAIN ( "regex", $ldif-fn = "db/icheck.ldif" ) {
> my ( %f );
> for $ldif-fn.IO.lines -> $line {
> when not $line {  # blank line is LDIF entry terminator
> %ldap{%f} = User.new( |%f );
> }
> when $line.starts-with( 'dn: ' ) { %f = () }   # dn: starts a new
> entry
>
> next unless $line ~~ m/ ^ (@attributes) ':' \s (.+) $ /;
> %f{$0} = "$1";
> }
> say "{%ldap.elems} entries by regex in {now - BEGIN now} seconds";
> }
>
> multi MAIN ( "starts", $ldif-fn = "db/icheck.ldif" ) {
> my ( %f );
> for $ldif-fn.IO.lines -> $line {
> when not $line {  # blank line is LDIF entry terminator
> %ldap{%f} = User.new( |%f );
> }
> when $line.starts-with( 'dn: ' ) { %f = () }   # dn: starts a new
> entry
>
> for @attributes -> $a {
> if $line.starts-with( $a ~ ": " ) {
>%f{$a} = (split( ": ", $line, 2))[1];
>last;
> }
>  }
>
> }
> say "{%ldap.elems} entries by starts-with in {now - BEGIN now}
> seconds";
> }
>
> multi MAIN ( "split", $ldif-fn = "db/icheck.ldif" ) {
> my ( %f, $k, $v );
> for $ldif-fn.IO.lines -> $line {
> when not $line {  # blank line is LDIF entry terminator
> %ldap{%f} = User.new( |%f ); # attributes not
> used are ignored
> }
> when $line.starts-with( 'dn: ' ) { %f = () }   # dn: st

Primitive benchmark comparison (parsing LDIF)

2021-10-27 Thread Norman Gaywood
Executive summary:
 - comparing raku 2021.10 with raku 2021.9
 -comparing 3 ways of parsing (although the 2 string function ways are
similar)
- raku 2021.10 is better than 2 times as fast as 2021.9 using the
string functions
- raku 2021.10 is about the same as 2021.9 using a more general regular
expression
- regular expressions are still slow in 2021.10

Side note: not shown here is also parsing with Text::LDIF. In 2021.9 it was
comparable to the regex method. Not tried with 2021.10.

I need to parse a 40K entry LDIF file.

Below is some code that uses 3 ways to parse.
There are 3 MAIN subs that differ in a few last lines of the for loop.
The loop reads the LDIF entries and populates %ldap keyed on the "uid" of
the LDIF entry.
The values of %ldap are User objects.
A %f hash is used to build the values of User on each LDIF entry

The aim is to show the difference in timings between 3 ways of parsing the
LDIF

The 1st MAIN (regex) uses this general regular expression to build %f
 next unless $line ~~ m/ ^ (@attributes) ':' \s (.+) $ /;
%f{$0} = "$1";

The "starts" MAIN uses starts-with() to build %f
   for @attributes -> $a {
if $line.starts-with( $a ~ ": " ) {
   %f{$a} = (split( ": ", $line, 2))[1];
   last;
}

And finally the "split" MAIN uses split() but also uses the feature that
User.new() will ignore attributes that are not used.
($k, $v) = split( ": ", $line, 2);
%f{$k} = $v;

That's the difference between the MAIN()'s below. Sorry I couldn't golf it
down more.
Running the benchmarks multiple times does vary the times slightly but not
significantly.

Results for rakudo-pkg-2021.9.0-01:
$ ./icheck.raku regex
41391 entries by regex in 27.859560887 seconds
$ ./icheck.raku starts
41391 entries by starts-with in 5.970667533 seconds
$ ./icheck.raku split
41391 entries by split in 5.12252741 seconds

Results for rakudo-pkg-2021.10.0-01
$ ./icheck.raku regex
41391 entries by regex in 27.833870158 seconds
$ ./icheck.raku starts
41391 entries by starts-with in 2.560101599 seconds
$ ./icheck.raku split
41391 entries by split in 2.307679407 seconds

-
#!/usr/bin/env raku

class User {
has $.uid;
has $.uidNumber;
has $.gidNumber;
has $.homeDirectory;
has $.mode = 0;

method attributes {
   # return ;
   User.^attributes(:local)>>.name>>.substr(2);  # Is the order
guaranteed?
}
}

# Read user info from LDIF file
my %ldap;
my @attributes = User.attributes;

multi MAIN ( "regex", $ldif-fn = "db/icheck.ldif" ) {
my ( %f );
for $ldif-fn.IO.lines -> $line {
when not $line {  # blank line is LDIF entry terminator
%ldap{%f} = User.new( |%f );
}
when $line.starts-with( 'dn: ' ) { %f = () }   # dn: starts a new
entry

next unless $line ~~ m/ ^ (@attributes) ':' \s (.+) $ /;
%f{$0} = "$1";
}
say "{%ldap.elems} entries by regex in {now - BEGIN now} seconds";
}

multi MAIN ( "starts", $ldif-fn = "db/icheck.ldif" ) {
my ( %f );
for $ldif-fn.IO.lines -> $line {
when not $line {  # blank line is LDIF entry terminator
%ldap{%f} = User.new( |%f );
}
when $line.starts-with( 'dn: ' ) { %f = () }   # dn: starts a new
entry

for @attributes -> $a {
if $line.starts-with( $a ~ ": " ) {
   %f{$a} = (split( ": ", $line, 2))[1];
   last;
}
 }

}
say "{%ldap.elems} entries by starts-with in {now - BEGIN now} seconds";
}

multi MAIN ( "split", $ldif-fn = "db/icheck.ldif" ) {
my ( %f, $k, $v );
for $ldif-fn.IO.lines -> $line {
when not $line {  # blank line is LDIF entry terminator
%ldap{%f} = User.new( |%f ); # attributes not used
are ignored
}
when $line.starts-with( 'dn: ' ) { %f = () }   # dn: starts a new
entry

($k, $v) = split( ": ", $line, 2);
%f{$k} = $v;
}
say "{%ldap.elems} entries by split in {now - BEGIN now} seconds";
}

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


Re: Font used for raku welcome message

2021-08-28 Thread Norman Gaywood
Hi William,

Yes, the Fedora/Centos packages look like the come from:

https://savannah.gnu.org/projects/freefont/

$ dnf info gnu-free-serif-fonts
...
Name : gnu-free-serif-fonts
Version  : 20120503
...
>From repo: appstream
Summary  : GNU FreeFont Serif Font
URL  : http://www.gnu.org/software/freefont/
...

I think it was the gnu-free-serif-fonts package but these are the complete
set on Centos/Fedora:

gnu-free-mono-fonts-20120503-18.el8.0.1.noarch
gnu-free-sans-fonts-20120503-18.el8.0.1.noarch
gnu-free-serif-fonts-20120503-18.el8.0.1.noarch
gnu-free-fonts-common-20120503-18.el8.0.1.noarch

gnu-free-fonts-common-20120503-24.fc34.noarch
gnu-free-sans-fonts-20120503-24.fc34.noarch
gnu-free-serif-fonts-20120503-24.fc34.noarch
gnu-free-mono-fonts-20120503-24.fc34.noarch


On Sat, 28 Aug 2021 at 16:01, William Michels  wrote:

> Hello Norman!
>
> Just to clarify, these were the fonts that you had success with?
>
> https://savannah.gnu.org/projects/freefont/
>
> FWIW, the (.otf) FreeMono -- Regular font works fine on my MacOS system
> (Terminal.app), with the words 퐑퐚퐤퐮퐝퐨™ and  퐑퐚퐤퐮™ appropriately
> showing up in Bold.
>
> Best, Bill.
>
> On Fri, Aug 27, 2021 at 6:46 PM Norman Gaywood 
> wrote:
>
>> Thanks for the suggestions Andinus and James Cloos
>>
>> In the end I was able to solve the issue by doing:
>>
>> lsof -p 
>>
>> and examining the open font files. There were not that many of them (only
>> 9).
>>
>> Then this, on one of the open font files (my 3rd file attempt):
>>
>> dnf whatprovides /usr/share/fonts/gnu-free/FreeSerif.ttf
>> gnu-free-serif-fonts-20120503-24.fc34.noarch
>>
>> Then on the troublesome system (Centos 8), I did:
>>  dnf install gnu-free-serif-fonts   # which also pulls
>> in gnu-free-fonts-common
>>
>> and bingo, all the missing raku fonts started displaying correctly.
>>
>>
>> On Fri, 27 Aug 2021 at 15:50, Norman Gaywood  wrote:
>>
>>> On Linux (various versions), if I ssh to another system and start the
>>> raku REPL , I am  greeted with:
>>>
>>> Welcome to 퐑퐚퐤퐮퐝퐨™ v2021.08.
>>> Implementing the 퐑퐚퐤퐮™ programming language v6.d.
>>>
>>> On some systems, this is displayed as (embedded graphic):
>>>
>>> [image: image.png]
>>>
>>> While others:
>>>
>>> [image: image.png]
>>>
>>> Does anyone know what font package provides the required font here?
>>>
>>> Pretty sure I have to install this font on the system I'm ssh'ing FROM.
>>> It's correctly displayed ssh'ing from Windows 10.
>>>
>>> --
>>> 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
>>>
>>
>>
>> --
>> 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
>>
>

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


Re: Font used for raku welcome message

2021-08-27 Thread Norman Gaywood
Thanks for the suggestions Andinus and James Cloos

In the end I was able to solve the issue by doing:

lsof -p 

and examining the open font files. There were not that many of them (only
9).

Then this, on one of the open font files (my 3rd file attempt):

dnf whatprovides /usr/share/fonts/gnu-free/FreeSerif.ttf
gnu-free-serif-fonts-20120503-24.fc34.noarch

Then on the troublesome system (Centos 8), I did:
 dnf install gnu-free-serif-fonts   # which also pulls
in gnu-free-fonts-common

and bingo, all the missing raku fonts started displaying correctly.


On Fri, 27 Aug 2021 at 15:50, Norman Gaywood  wrote:

> On Linux (various versions), if I ssh to another system and start the raku
> REPL , I am  greeted with:
>
> Welcome to 퐑퐚퐤퐮퐝퐨™ v2021.08.
> Implementing the 퐑퐚퐤퐮™ programming language v6.d.
>
> On some systems, this is displayed as (embedded graphic):
>
> [image: image.png]
>
> While others:
>
> [image: image.png]
>
> Does anyone know what font package provides the required font here?
>
> Pretty sure I have to install this font on the system I'm ssh'ing FROM.
> It's correctly displayed ssh'ing from Windows 10.
>
> --
> 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
>


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


Font used for raku welcome message

2021-08-26 Thread Norman Gaywood
On Linux (various versions), if I ssh to another system and start the raku
REPL , I am  greeted with:

Welcome to 퐑퐚퐤퐮퐝퐨™ v2021.08.
Implementing the 퐑퐚퐤퐮™ programming language v6.d.

On some systems, this is displayed as (embedded graphic):

[image: image.png]

While others:

[image: image.png]

Does anyone know what font package provides the required font here?

Pretty sure I have to install this font on the system I'm ssh'ing FROM.
It's correctly displayed ssh'ing from Windows 10.

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


Re: How do a pe-salt an array inside an object?

2021-07-05 Thread Norman Gaywood
$ raku
Welcome to 퐑퐚퐤퐮퐝퐨™ v2021.06.
Implementing the 퐑퐚퐤퐮™ programming language v6.d.
Built on MoarVM version 2021.06.

To exit type 'exit' or '^D'
> class AA { has Str @.I is rw; };
(AA)
> my $CC = AA.new( I => [Str,"abc"] );
AA.new(I => Array[Str].new(Str, "abc"))
> say $CC.I;
[(Str) abc]
> say $CC.I[1];
abc
> $CC.I[0] = "zyz";
zyz
> say $CC.I;
[zyz abc]
>

On Tue, 6 Jul 2021 at 10:55, ToddAndMargo via perl6-users <
perl6-users@perl.org> wrote:

> Hi All,
>
> On creation, I would like to salt some of the
> values inside an object  when the variable
> inside is an array:
>
>
> First a concept test:
> $ p6 'class AA { has Str @.I is rw; }; my $CC= AA.new; $CC.I[1] = "def";
> say $CC.I[1];'
>
> def
>
>
> Now for the pre-salt test
> $ p6 'class AA { has Str @.I is rw; }; my $CC = AA.new( I[1] => "abc" );
> say $CC.I[1];'
>
> ===SORRY!=== Error while compiling -e
> Undeclared name:
>  I used at line 1
>
>
> What am I doing wrong?
>
> 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?"
> 
>


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


gather take eager syntax

2021-04-19 Thread Norman Gaywood
Hi, I can't figure out why the last line here is failing.
Version 2020.07

$ raku
To exit type 'exit' or '^D'
> my %h = gather { take "foo"=>1; take "bar"=>2;}
{bar => 2, foo => 1}
> my %h = gather { take "foo"=>1}
{foo => 1}
> my %h = gather { take eager "foo"=>1; take "bar"=>2;}
{foo 1 => bar => 2}
> my %h = gather { take eager "foo"=>1}
Odd number of elements found where hash initializer expected:
Only saw: $(:foo(1),)
  in block  at  line 1

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


Re: qqx with quotes

2020-02-26 Thread Norman Gaywood
I don't have a windows system to test, but in all the examples shown I did
not see:

qqx{ C:/Windows/System32/fsutil.exe usn readdata "$FileName" };

which is how I would have expected to write the command.

On Thu, 27 Feb 2020 at 09:49, ToddAndMargo via perl6-users <
perl6-users@perl.org> wrote:

>  > *From:* ToddAndMargo via perl6-users 
>  > *Sent:* Tuesday, February 25, 2020 11:12 AM
>  > *To:* perl6-users@perl.org 
>  > *Subject:* Re: qqx with quotes
>  >>> On Mon, Feb 24, 2020 at 4:01 PM ToddAndMargo via perl6-users
>  >>> mailto:perl6-users@perl.org>> wrote:
>  >>>
>  >>> Hi All,
>  >>>
>  >>> Windows 7
>  >>>
>  >>> In the following
>  >>>
>  >>> @Result = qqx { C:/Windows/System32/fsutil.exe usn readdata
>  >>> \"$FileName\" }.lines;
>  >>>
>  >>>
>  >>> $FileName needs to be in quotes as it can have
>  >>> spaces in it.
>  >>>
>  >>>
>  >>> The following did not work:
>  >>>
>  >>> \"$FileName\"
>  >>> "$FileName\
>  >>> $FileName
>  >>>
>  >>> What am I doing wrong, this time?
>  >>>
>  >>> Many thanks,
>  >>> -T
>
>
> On 2020-02-26 14:16, Andy Bach wrote:
> > @Result = qqx { C:/Windows/System32/fsutil.exe usn
> > readdata \"$FileName\" }.lines;
> >
> > Doesn't windows do something special for files with spaces in them?  Hm,
> > $ type "hi mom" > "test 1"
> > $ dir test
> > $ dir "test 1"
> >
> > but, you're right, I couldn't find a combination of dbl, single, q, qq,
> > qqx, qx that'd let me run
> > dir "test 1"
> > via qqx or qx - windows is funny that way, I guess.
>
> Hi Andy,
>
> Thank you for the confirmation!  For once, it wasn't me.
> I wonder if this is a bug in Raku?
>
> I will try the Shell command.  No need for
> quotes in that.
>
> -T
>


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


Re: irrational nubmer?

2020-02-20 Thread Norman Gaywood
On Fri, 21 Feb 2020 at 13:31, ToddAndMargo via perl6-users <
perl6-users@perl.org> wrote:

> $ perl6 -e 'say sqrt(2).base-repeating();'
> No such method 'base-repeating' for invocant of type 'Num'
>in block  at -e line 1
>

perl6 -e 'say sqrt(2).Rat.base-repeating();'
(1.4
14213197969543147208121827411167512690355329949238578680203045685279187817258883248730964467005076)

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


Re: REPL and arrows problem

2020-01-22 Thread Norman Gaywood
Hi Todd,
I don't think this is a Rakudo problem. It's a Fedora 31 problem.
ALready, when you start raku without Readline installed, it gives the
message:

> $ raku
> You may want to `zef install Readline` or `zef install Linenoise` or use
rlwrap for a line editor
>
> To exit type 'exit' or '^D'

Which is pretty much what you are requesting in the two RFEs you posted.

The problem I think in this case is that Readline is not working in Fedora
31 even with the following packages installed:

> rakudo-0.2019.11-3.fc31.x86_64
> rakudo-Readline-0.1.5-2.fc31.x86_64

On Thu, 23 Jan 2020 at 06:21, ToddAndMargo via perl6-users <
perl6-users@perl.org> wrote:

> RFE: REPL dependency check for Readline #153
> https://github.com/Raku/problem-solving/issues/153
>
> By the way, when you do this, it pops up immediately
> on the chat line!  They think of everything.
>
> :-)
>
> -T
>


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


Re: REPL and arrows problem

2020-01-21 Thread Norman Gaywood
On Wed, 22 Jan 2020 at 13:30, Todd Chester via perl6-users <
perl6-users@perl.org> wrote:

> On 2020-01-21 16:38, Todd Chester via perl6-users wrote:
> > Fedora31
>

I have Fedora 31 and Readline does not seem to be working for me in the
raku REPL as well.
But see below!


> $ rpm -qa \*raku\*
> xfce4-terminal-0.8.9.1-1.fc31.x86_64
>

Hmm, I don't think that is output from that command. Mine:
 $ rpm -qa \*raku\*
rakudo-XML-0.0.3-0.6.20190728git417f637.fc31.x86_64
rakudo-MIME-Base64-1.2.1-6.fc31.x86_64
rakudo-zef-0.8.2-1.fc31.x86_64
rakudo-0.2019.11-3.fc31.x86_64
rakudo-Readline-0.1.5-2.fc31.x86_64
rakudo-URI-0.2.2-1.fc31.x86_64


> $ raku -v
> This is Rakudo version 2019.07.1 built on MoarVM version 2019.07.1
> implementing Perl 6.d.
>

Looks like you might have your own rakudo installed not from the default
system packages. Mine:
$ which raku
/usr/bin/raku
$ raku -v
This is Rakudo version 2019.11 built on MoarVM version 2019.11
implementing Perl 6.d.

In any case, I also have the problem with raku REPL not using Readline
despite rakudo-Readline-0.1.5-2 being installed.
$ raku
You may want to `zef install Readline` or `zef install Linenoise` or use
rlwrap for a line editor

To exit type 'exit' or '^D'
> my $history^[[A^[[A

This seems like a Fedora 31 packaging problem to me.

However, after this:
$ zef install Readline

The arrow keys once again work for me.

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


Re: Using raku/perl6 as unix "cat"....

2020-01-20 Thread Norman Gaywood
On Tue, 21 Jan 2020 at 03:12, Brad Gilbert  wrote:

> .say for lines
>

Since .say calls gist(), would it be not be better/safer to call .put
instead?

   .put for lines

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


Re: Need help with a regex

2019-05-06 Thread Norman Gaywood
The .*? expression is not matching anything. I think you want to use .+

perl6 -e 'my $x="\$1.23"; $x~~s/("\$") (.*?)/$0:$1:USD/; say $x;'
$::USD1.23

perl6 -e 'my $x="\$1.23"; $x~~s/ \$(.+) /$0USD/; say $x'
1.23USD



On Tue, 7 May 2019 at 13:10, ToddAndMargo via perl6-users <
perl6-users@perl.org> wrote:

> Hi All,
>
> What am I doing wrong here?
>
> $ p6 'my $x="\$1.23"; $x~~s/("\$") (.*?)/$1USD/; say $x;'
> USD1.23
>
> I am expecting to see  `1.23USD`
>
> Many thanks,
> -T
>
>
>
>
>
>
> --
> ~~
> Computers are like air conditioners.
> They malfunction when you open windows
> ~~
>


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


Re: "read" options?

2019-02-03 Thread Norman Gaywood
On Mon, 4 Feb 2019 at 15:12, ToddAndMargo via perl6-users <
perl6-users@perl.org> wrote:

> https://docs.perl6.org/routine/read
>
> Where is the list of the options this thing will take, such
> as :ro and :bin?
>
>
Those are options for open()

https://docs.perl6.org/routine/open

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


KEEP/UNDO phaser question

2018-10-27 Thread Norman Gaywood
Just been reading  the latest of Elizabeth's wonderful blog posts on how
phasers work in perl6:
https://opensource.com/article/18/10/how-phasers-work-perl-6?fbclid=IwAR3eJSn5EdJh2DYgpjrFOy7kg-dShuilwQhHDHTANeb4JmHYSBiTz3WyxPA

I have question on the KEEP/UNDO example:
{
KEEP $dbh.commit;
UNDO $dbh.rollback;
...# set up a big transaction in a database
True;  # indicate success
}

Won't that "True;  # indicate success" just force the KEEP phaser to run?
Shouldn't you just use the result of  whatever  is the result of "... # set
up a big transaction in a database"?


Re: EVAL?

2018-06-14 Thread Norman Gaywood
On Fri, 15 Jun 2018 at 06:13, Trey Harris  wrote:

Thanks for the nice examples of IntStr and friends.

I was intrigued with this statement at the end:

> Also note that using s/printf at all is not encouraged

Could you expand on that?

> ​
>


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


Re: How do I remove leading zeros?

2018-06-12 Thread Norman Gaywood
On Wed, 13 Jun 2018 at 14:57, ToddAndMargo  wrote:

> I am trying to turn
>
>  01.02.03
>
> into
>
>  1.2.3
>
> What am I doing wrong, this time?
>
> $ p6 'my $x="01.02.03"; $x ~~ s:global/"0"(\d)/ $0 /; say "$x"'
>   1 . 2 . 3
>
>
The second part of the s/// operator is a string (spaces count), not a
regex (spaces ignored).

> my $x="01.02.03"; $x ~~ s:global/"0"(\d)/$0/; say "$x"
1.2.3

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


Re: An operation first awaited

2018-05-28 Thread Norman Gaywood
I've moved this question to stackoverflow

https://stackoverflow.com/questions/50573586/perl6-an-operation-first-awaited

More comments inline below.

On Tue, 29 May 2018 at 01:40, Brad Gilbert  wrote:

> .
> > An operation first awaited:
> >   in sub MAIN at ./traverse-dir0.p6 line 24
> >   in block  at ./traverse-dir0.p6 line 5
> >
> > Died with the exception:
> > Cannot find method 'path': no method cache and no .^find_method
> >   in block  at ./traverse-dir0.p6 line 16
>
>

> > my $dir-read = start {
> > $dir-channel.send( $_ ) for dir $dir;
> > $dir-channel.close;
> > }
> >
> > my @workers = (^$N).map: {
> > start {
> > while my $file = $dir-channel.receive() {
> > say $file.path;
> > }
> > CATCH {
> > when X::Channel::ReceiveOnClosed { .resume }
>
> --
>
> What did you expect to happen if you resumed?
>
> Because I expect it to try to run `say $file.path;` with invalid data.
> You can just remove the `.resume` and it works.
>

Hmm, I was expecting the resume to make  $dir-channel.receive() fail and
hence the loop

 while my $file = $dir-channel.receive()

to finish. That is control would not move to inside the while() loop.

It seems not :-( I'll need to get my head around what is happening.

.
> > await $dir-read, @workers;
> > }
>
> There is no need to await for $dir-read, as the workers won't finish
> until it's done anyway.
>

Yep :-)


>
> ---
>
> Anyway I would use a `react` block.
>

Nice, I'll work on this. Thanks.

My original intention was to rewrite my code with "back-pressure" on the dir()
read thread.

And then I got stuck on this error I'm posting about :-(



> my @workers = (^$N).map: {
> start react whenever $dir-channel -> $file {
> say $file.path;
> }
> }
>
> Note that `start` and `react` don't need {}, but you can use them if
> neccesary.
>
>
> my @workers = (^$N).map: {
> start {
> say 'started';
>
> react {
> say 'reacting';
>
> whenever Promise.in(½) { say '½ second has elapsed' }
>
> whenever $dir-channel -> $file {
> say $file.path;
> }
> }
> }
> }
>


An operation first awaited

2018-05-28 Thread Norman Gaywood
T""his simple program creates a thread to read a directory with dir()
and place the files on a channel. $N worker threads read that channel
and "process" (prints) the files. But I'm getting this "An operation
first awaited:"
error.

I've read the traps page about this error several times, but still can't
make sense of it. Can some explain what's going on here?

The directory contents:
$ ls
a  b  c  traverse-dir0.p6

Running the program:
$ ./traverse-dir0.p6
traverse-dir0.p6
a
b
c
An operation first awaited:
  in sub MAIN at ./traverse-dir0.p6 line 24
  in block  at ./traverse-dir0.p6 line 5

Died with the exception:
Cannot find method 'path': no method cache and no .^find_method
  in block  at ./traverse-dir0.p6 line 16

The program:
$ cat traverse-dir0.p6
#!/usr/bin/env perl6
# There is a thread to populate $dir-channel by reading filenames in a
directory with dir()
# and $N worker threads to read the filenames from the $dir-channel.

sub MAIN( Str $dir = ".", Int :$N = 4 ) {

my $dir-channel = Channel.new();
my $dir-read = start {
$dir-channel.send( $_ ) for dir $dir;
$dir-channel.close;
}

my @workers = (^$N).map: {
start {
while my $file = $dir-channel.receive() {
say $file.path;
}
CATCH {
when X::Channel::ReceiveOnClosed { .resume }
}
}
}

await $dir-read, @workers;
}


Re: Need match character help

2018-05-17 Thread Norman Gaywood
Nice RE tutorial :-)

/^ [ | <[d..z]-[g]> | g ]* $/

One question I have is what is the first | for?

On Thu, 17 May 2018 at 21:10, Timo Paulssen <t...@wakelift.de> wrote:

> The description perhaps doesn't point out clearly enough: the reason why
> the stuff inside the [ ] will match any amount of times is only the * at
> the end, the [ ] is only there because otherwise the regex would instead
> match something you didn't mean at all. If you're interested, read on for
> an explanation, but it might actually be more confusing than helpful:
>
> The resulting regex means "either the beginning of the string is followed
> by any letter from d to z except g, or there's a g that's either not before
> an m, or it is, and followed by the end of the string".
>
> That's because now the | would not only separate the ^ and $ anchors into
> becoming alternatives, but the * would cling to the  which is
> now allowed to not match at all (because it's a * and not a +).
>
> Also, putting a quantifier (which is what * and + are called) on a before
> or after assertion makes no sense and probably leads to an infinite loop
> (the regex engine tries to make you proud by matching it as often as it
> possibly can. which if the assertion is true, is infinitely often. it is
> very diligent, but it does not really think much about what it does).
>
> Hope that helps
>   - Timo
>
> On 17/05/18 12:51, Timo Paulssen wrote:
>
> character classes are fundamentally the wrong thing for "phrases", since
> they describe only a character.
>
> Your current regex (before changing [gm] to ["gm"]) was expressing "from
> the start of the string, there's any amount of characters d through z (but
> neither g nor m) and then the end of the string", which can be more easily
> expressed as "the whole string contains only letters d through z (but
> neither g nor m)".
>
> What you apparently want is "the whole string contains only letters d
> through z, but never the phrase 'gm'", which - in order to get to a working
> regex - we can rephrase as "the whole string contains only letters d
> through z and no occurrence of g is followed by an m". Let's turn that into
> a regex:
>
> /^ # Require the match to start at the beginning of the
># string so nothing can sneak in before that.
> [  # Everything in this group will be matched a bunch
># of times.
> |  <[d..z]-[g]>  # either anything between d and z, with no
>  # further restrictions, except for g.
> |  g  # If there's a g, it must not be followed
>  # by an m.
> ]* # end of the group, allow the things in the group to
># occur any amount of times.
> $/ # Require the match to end at the end of the string,
># so nothing at the end can sneak in.
>
> Important things to note here:
>
>-  (spoken as "do not match before an m") will be fine with
>occurrences at the end of the string, too.
>- we don't remove the m from the character class any more, we only
>keep the g in there, because m can be in the string without restrictions;
>if there is an m after a g, our regex will already have failed before it
>even reaches the m, and all other cases are fine (like dm or fm or hm).
>- you are allowed to put a | not only between things, but also at the
>very front. This is allowed in the syntax so that you can line things up
>vertically like I did. Think of it as similar to allowing a , after the
>last element in a list, like with [1, 2, 3, 4, ]
>
> hi
> Match: 「hi」
> bleh
> Match: Nil
> fog
> Match: 「fog」
> dm
> Match: 「dm」
> fm
> Match: 「fm」
> hm
> Match: 「hm」
> gm
> Match: Nil
> rofl
> Match: 「rofl」
> dddg
> Match: 「dddg」
> 
> Match: 「」
> 
> Match: 「」
>
>
> Hope that helps!
>   - Timo
>
>
>

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


Slides for "8 ways to do concurrency and parallelism in Perl 6"?

2018-04-11 Thread Norman Gaywood
There was a talk by Jonathan Worthington at the German Perl Workshop 2018,

http://act.yapc.eu/gpw2018/talk/7326

"8 ways to do concurrency and parallelism in Perl 6"

I'd be very interested in seeing the slides and/or video of this talk.

Anyone know if it is available or will be available anywhere?

Currently not available on: http://www.jnthn.net/slides.html


Re: Set difference using hashes vs array

2017-11-22 Thread Norman Gaywood
Talking to myself :-)

Seems it has something to do with the values in the hash. If they are just
True, this works:
$ perl6
To exit type 'exit' or '^D'
> my %a= :k, :e, :r; my %r= :r; my %e= :e; my Set $s = %a (-) %r (-) %e;
set(k)



On 23 November 2017 at 16:20, Norman Gaywood <ngayw...@une.edu.au> wrote:

> For compactness, here are the 1-liners:
>
> $ perl6
> To exit type 'exit' or '^D'
> > my %a= k=>"k", e=>"e", r=>"r"; my %r= r=>"r"; my %e= e=>"e"; my Set $s =
> %a (-) %r (-) %e;
> Cannot convert string to number: base-10 number must begin with valid
> digits or '.' in '⏏k' (indicated by ⏏)
>   in block  at  line 1
>
> > my %a= k=>"k", e=>"e", r=>"r"; my %r= r=>"r"; my %e= e=>"e"; my Set $s =
> (%a (-) %r) (-) %e;
> set(k)
> > my @a= "k", "e", "r"; my @r= "r"; my @e= "e"; my Set $s = @a (-) @r (-)
> @e;
> set(k)
> >
>
>
> On 23 November 2017 at 15:41, Norman Gaywood <ngayw...@une.edu.au> wrote:
>
>> I'm not sure what this error message means and what is going on here:
>> perl6 --version
>> This is Rakudo version 2017.08 built on MoarVM version 2017.08.1
>> implementing Perl 6.c.
>>
>> $ cat tt-h.p6
>> #!/usr/bin/env perl6
>>
>> my %excludes = "exclude" => "exclude";
>> my %all = :keep("keep"), :exclude("exclude"), :remove("remove");
>> my %remove = :remove("remove");
>>
>> my Set $take1 = (%all (-) %remove) (-) %excludes;
>> dd $take1;
>> my Set $take2 = %all (-) %remove (-) %excludes;
>> dd $take2;
>>
>> $ ./tt-h.p6
>> Set $take1 = set("keep")
>> Cannot convert string to number: base-10 number must begin with valid
>> digits or '.' in '⏏remove' (indicated by ⏏)
>>   in block  at ./tt-h.p6 line 10
>>
>> The difference in $take1 and $take2 are the brackets around the 1st set
>> operation.
>>
>> If I use arrays then no problem with either expression:
>>
>> $ cat tt-a.p6
>> #!/usr/bin/env perl6
>>
>> my @excludes = "exclude";
>> my @all = "keep", "exclude", "remove";
>> my @remove = "remove";
>>
>> my Set $take1 = (@all (-) @remove) (-) @excludes;
>> dd $take1;
>> my Set $take2 = @all (-) @remove (-) @excludes;
>> dd $take2;
>>
>> $ ./tt-a.p6
>> Set $take1 = set("keep")
>> Set $take2 = set("keep")
>>
>> --
>> 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 <(02)%206773%202412>  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
>>
>
>
>
> --
> 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 <(02)%206773%202412>  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
>



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


Re: Nice Channel and thread example

2017-10-30 Thread Norman Gaywood
Hmm, in developing this I was using an old perl6:

This is rakudo version 2015.11-554-g3b4964b built on MoarVM version
2015.11-49-g27f15d9 implementing Perl v6.b.

I updated perl6 to the one that comes with Fedora:

This is Rakudo version 2017.08 built on MoarVM version 2017.08.1
implementing Perl 6.c

Now when I run this program I get an exception when I do:

close $dir-channel;

Tried to get the result of a broken Promise
  in block  at ./traverse-dir0.p6 line 7

Original exception:
Cannot resolve caller close(Channel); none of these signatures match:
(IO::Handle:D $fh)
  in block  at ./traverse-dir0.p6 line 12

However, if I change the line 12 to:

$dir-channel.close;

The program does not throw and exception on this line and runs properly.



On 30 October 2017 at 16:58, Norman Gaywood <ngayw...@une.edu.au> wrote:

> Looking at Andrew Shitov's new "Using Perl6" book and was playing around
> with his "94. Parallel file processing" and came up with the following (I
> think nice) example.
>
> # There is a thread to populate $dir-channel by reading filenames in a
> directory with dir()
> # and $N worker threads to read the filenames from the $dir-channel.
>
> use v6;
>
> sub MAIN( $dir = ".", :$N = 4 ) {
>
> my $dir-channel = Channel.new();
> my $dir-read = start {
> $dir-channel.send( $_ ) for dir $dir;
> close $dir-channel;
> }
>
> my @workers = (^$N).map: {
> start {
> while my $file = $dir-channel.receive() {
> say $file.path;
> }
> CATCH {
> when X::Channel::ReceiveOnClosed { .resume }
> }
> }
> }
>
> await $dir-read, @workers;
> }
>
>
> --
> 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 <(02)%206773%202412>  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
>



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


Is Haskell the right language for teaching FP. No!

2017-10-16 Thread Norman Gaywood
Someone should mention perl6 :-)

http://profsjt.blogspot.com.au/2017/10/is-haskell-right-language-for-teaching.html

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


Re: -f ???

2017-09-28 Thread Norman Gaywood
On 29 September 2017 at 15:10, Brandon Allbery <allber...@gmail.com> wrote:

>
> (And, Norman? It produces a Failure, not a hard exception. You can
> introspect Failures to keep them from getting thrown.)
>

 Yep, that's what I thought I'd said :-) Obviously not clearly.

Another way of looking at it:

$ perl6 -e 'my $f = "eraseme.txt".IO.f;say $f.WHAT'
(Failure)

and you can coerce that to a bool without throwing as other examples in the
thread have shown.

perl6 -e 'my $f = "eraseme.txt".IO.f; say $f.WHAT; say ?$f'
(Failure)
False

Or plain old verbose:

if "eraseme.txt".IO.f {
say "exists";
} else {
say "does not exist";
}

It seems to me it only looks buggy when you are trying to do one liners and
you don't naturally get a boolean context.

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


Re: -f ???

2017-09-28 Thread Norman Gaywood
I was just reading about this!

On 29 September 2017 at 14:53, ToddAndMargo <toddandma...@zoho.com> wrote:

>
> $ perl6 -e 'say "erasxeme.txt".IO.f;'
> Failed to find '/home/linuxutil/erasxeme.txt' while trying to do '.f'
>   in block  at -e line 1
>

When you do:

 "erasxeme.txt".IO.f

It will fail (before the .f even) on the .IO call because "erasxeme.txt"
does not exist. perl6 will then throw an exception when you try to use the
value of that failed call.

So, you need to not "use" the value of the failed .IO call:

if not $f.IO.f { say "$f not found" }

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


Re: mkdir not failing appropriately?

2017-09-18 Thread Norman Gaywood
To answer myself, it's a known bug reported over a year ago :-(

https://rt.perl.org/Public/Bug/Display.html?id=127772

On 18 September 2017 at 16:18, Norman Gaywood <ngayw...@une.edu.au> wrote:

> $ perl6 -v
> This is Rakudo version 2017.07 built on MoarVM version 2017.07
> implementing Perl 6.c.
> $ perl6
> To exit type 'exit' or '^D'
> > '/'.IO.d
> True
> > try { mkdir '/' }
> "/".IO
> > if $! { say "Fail" } else { say "Bazinga" }
> Bazinga
>
> So the  mkdir / would have failed because the dir exists. But it is a .d
> so maybe that's ok.
>
> Lets try mkdir on an existing file that we also have permissions to modify.
>
> > 'afile'.IO.d
> False
> > 'afile'.IO.e
> True
> > try { mkdir 'afile' }
> "afile".IO
> > if $! { say "Fail" } else { say "Bazinga" }
> Bazinga
> > 'afile'.IO.d
> False
> >
>
> Surely that mkdir should fail?
>
> mkdir does fail properly sometimes:
>
> > try { mkdir '/root/noway' }
> Nil
> > if $! { say "Fail" } else { say "Bazinga" }
> Fail
>
> In perl5:
>
>   DB<3> mkdir "afile" or warn "$!\n"
> File exists
>  DB<4> mkdir "/" or warn "$!\n"
> File exists
>  DB<5> mkdir "/root/noway" or warn "$!\n"
> Permission denied
>   DB<6> mkdir "adir" or warn "$!\n"
>
>   DB<7> mkdir "adir" or warn "$!\n"
> File exists
>
> --
> 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 <(02)%206773%202412>  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
>



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


mkdir not failing appropriately?

2017-09-18 Thread Norman Gaywood
$ perl6 -v
This is Rakudo version 2017.07 built on MoarVM version 2017.07
implementing Perl 6.c.
$ perl6
To exit type 'exit' or '^D'
> '/'.IO.d
True
> try { mkdir '/' }
"/".IO
> if $! { say "Fail" } else { say "Bazinga" }
Bazinga

So the  mkdir / would have failed because the dir exists. But it is a .d so
maybe that's ok.

Lets try mkdir on an existing file that we also have permissions to modify.

> 'afile'.IO.d
False
> 'afile'.IO.e
True
> try { mkdir 'afile' }
"afile".IO
> if $! { say "Fail" } else { say "Bazinga" }
Bazinga
> 'afile'.IO.d
False
>

Surely that mkdir should fail?

mkdir does fail properly sometimes:

> try { mkdir '/root/noway' }
Nil
> if $! { say "Fail" } else { say "Bazinga" }
Fail

In perl5:

  DB<3> mkdir "afile" or warn "$!\n"
File exists
 DB<4> mkdir "/" or warn "$!\n"
File exists
 DB<5> mkdir "/root/noway" or warn "$!\n"
Permission denied
  DB<6> mkdir "adir" or warn "$!\n"

  DB<7> mkdir "adir" or warn "$!\n"
File exists

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


rw optional parameters

2017-09-16 Thread Norman Gaywood
I have this:
#!/usr/bin/perl6
use v6;
sub MAIN( :$debug = False, :$verbose = False  ) {
$verbose = True if $debug;
say "verbose={$verbose}, debug={$debug}";
}
$ ./tt.p6
verbose=False, debug=False
$ ./tt.p6 --verbose
verbose=True, debug=False
$ ./tt.p6 --debug
Cannot assign to a readonly variable ($verbose) or a value
  in sub MAIN at ./tt.p6 line 6
  in block  at ./tt.p6 line 4

So $verbose is read-only. I think the compiler could have told me this a
compile time?

I try to fix it:
...
sub MAIN( :$debug = False, :$verbose is rw = False  ) {
...
$ ./tt.p6 --debug
===SORRY!=== Error while compiling /home/ngaywood/./tt.p6
Cannot use 'is rw' on optional parameter '$verbose'.
at /home/ngaywood/./tt.p6:4

Not sure what the neat way of doing this is.

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


Re: What is P6 for P5 `use Term::ReadKey`?

2017-09-13 Thread Norman Gaywood
ument. But the view that the invocant counts as an argument is useful
> here, so let’s use that definition, making the two both unary routines.)
>
> Both routines’ single argument is of type IO::Handle. They also both
> require definedness, but in different ways. The method uses the :D suffix
> we’ve already seen; in effect, that allows $my-handle.getc to work
> provided $my-handle has been set to a defined IO::Handle object. But if
> the variable was declared with my IO::Handle $my-handle; but never
> assigned to, $my-handle.getc will not work; neither will IO::Handle.getc
> (which would work if :D weren’t included in the signature; one way of
> getting “class methods” in Perl 6 is to create methods with :U invocants).
>
> The multisub L2 also requires definedness, but does it in a different way.
> The IO::Handle $fh, by itself, doesn’t rule out an undefined argument
> being assigned to the $fh parameter, but the *default value* expressed by =
> $*ARGFILES ensures that an omitted or undefined argument will cause $fh
> to be assigned the value $*ARGFILES. (The $* notation is used to refer to
> global variables; you can look up the definition of $*ARGFILES
> <https://docs.perl6.org/language/variables#index-entry-%24%2AARGFILES> to
> see it is
>
> An IO::CatHandle that uses @*ARGS as source files, if it contains any
> files, or $*IN otherwise
>
> and you can also look up IO::CatHandle
> <https://docs.perl6.org/type/IO::CatHandle> and $*IN
> <https://docs.perl6.org/language/variables#index-entry-%24%2AIN> in the
> docs if you want to know more).
>
> The point of all this is to not require exhaustive examples to show you
> possible ways of calling getc; you just need to know how to unlock the
> code.
>
> Putting it all together, it tells you that these are valid examples:
>
> my Str $chr = getc($*IN); # insist on STDIN, even if file arguments were 
> given on the command line
> $chr = "/dev/tty".IO.open.getc; # Insist not just on STDIN, but on the POSIX 
> tty
>
> Learning to read the Perl 6 doc <https://docs.perl6.org/> signatures may
> be frustrating at first, but it’s well worth it, and pays dividends.
> ​
>



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


Thread example from evanmiller

2017-09-07 Thread Norman Gaywood
Several weeks ago there was this post:
http://www.evanmiller.org/why-im-learning-perl-6.html

That gave this example of perl6 N:M threads in action:

use v6.d.PREVIEW;

my $channel = Channel.new;

my @ten_tasks = (^10).map: {
start {
my $thread = $*THREAD.id;
await $channel;
say "HOLY MOLEY SOMEONE STOLE MY THREAD" if $thread != $*THREAD.id;
}
}

$channel.send("Ring ring") for ^10;
$channel.close;

await @ten_tasks;


It demonstrates that perl6 will not tie up a thread in the thread pool just
sitting around waiting (I think).

The example is intended to be condensed without any surplus code.
So my question is, is the $channel.close required? Leave it out and the
code still seems to work. Am I missing some subtle point?

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


Re: User defined infix operators and whitespace

2017-08-26 Thread Norman Gaywood
It seems to work without spaces if you choose a symbol that is not
letter-like.

# U+1F3B2 Game Die
sub infix:<> ( Int $num, Int $size ) { [+] (1..$size).roll($num) };
sub prefix:<> ( Int $size ) { 1$size }
say 10;
say 46;

# ⛏ U+26CF Pick
sub infix:<⛏> ( Int $num, Int $size ) { [+] (1..$size).roll($num) };
sub prefix:<⛏> ( Int $size ) { 1⛏$size }
say ⛏10;
say 4⛏6;

# Not working
# ⅆ U+2146 Double-Struck Italic Small D
#sub infix:<ⅆ> ( Int $num, Int $size ) { [+] (1..$size).roll($num) };
#sub prefix:<ⅆ> ( Int $size ) { 1ⅆ$size }
#say ⅆ10;
#say 4ⅆ6;


On 10 August 2017 at 21:16, Simon Proctor <simon.proc...@gmail.com> wrote:

> So I had a crazy little idea. I've played the odd bit of roleplaying in my
> time and wanted to created a 'd' operator.
>
> Quite simple really.
>
> sub infix: ( Int $num, Int $size ) { [+] (1..$size).roll($num) };
>
> sub prefix: ( Int $size ) { 1 d $size }
>
> Gives us 3 d 6 to roll 3 six sided dice or a prefix d 10 for a single 10
> sided dice.
>
> Except... I'd really like to write 3d6 or d10 but the parser barfs.
>
> Am I going to just have to live with that? Or did I miss something
> obvious?
>
> Obviously it's possible to have operators that ignore whitespace (1+1
> works just fine) but is it possibly for user defined ones?
>
> Possibly more serious ones.
>
> Simon
>



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


Bi-directional communication with another process

2017-07-27 Thread Norman Gaywood
>From inside a program I'd like to send some input to the stdin of external
program and read back the stdout.

The example in https://docs.perl6.org/language/ipc under proc comes close
to what I want:

my $echo = run 'echo', 'Hello, world', :out;
my $cat  = run 'cat', '-n', :in($echo.out), :out;
say $cat.out.get;
$cat.out.close();

That works, however what I want however is a single external process, sort
of like:

my $input = q:to/EOS/;
line of text
another line
EOS

my $cat  = run 'cat', '-n', :in($input.print), :out;
my $output = $cat.out.get;
$cat.in.close;
$cat.out.close;

say "done";
say $output;

But that is not correct. I seem to be missing something.


Re: need help with "next"

2017-05-24 Thread Norman Gaywood
On 24 May 2017 at 16:40, Norman Gaywood <ngayw...@une.edu.au> wrote:

>
> However, your code does not look like it will do what you want if you have
>> multiple TASKs
>>
>
>
Yes it does. Sorry ignore me :-)


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


Re: need help with "next"

2017-05-24 Thread Norman Gaywood
On 24 May 2017 at 15:20, ToddAndMargo <toddandma...@zoho.com> wrote:
>
>
> This is what I came up with.  I found that `next` did not serve me
> well, so i just used a tag.
>
> Thank you all for the help.  I had a bit of a time wrapping
> my head around `next` there for a while.
>
> -T
>
> 
> #!/usr/bin/env perl6
>
> use strict;
>
> my @Data = 'Mission D',
>'   Sol Wheat',
>'   Ted Moon',
>'';
> # for @Data -> $Line { say "$Line"; }
>
> my $TaskTag = 0;
> for @Data -> $Line {
>if $Line.contains( "TASK type" ) { $TaskTag = 1; }
>
>if $Line.contains( "NAME type" ) {
>   ( my $Name = $Line) ~~ s/.*?\>//;
>   $Name ~~ s/\<.*//;
>   say $Name;
>} else { $TaskTag = 0; }
>
> }
> 
>

I'm a rank beginner p6 programmer so I'm sure my code can be improved.

However, your code does not look like it will do what you want if you have
multiple TASKs

What about something like:
my @Data =
 'Mission D',
   '   Sol Wheat',
   '   Ted Moon',
 '',
 'Mission C',
   '   Jim Kirk',
   '   Mr Spock',
 '',
;

my $in-TASK = "";

for @Data -> $Line {
if $Line.contains( "TASK type" ) {
$Line ~~ m/ 'TASK' .*? '>' $=( .* ) /;
$in-TASK = $;
next;
}
if $Line.contains( "/TASK" ) {
    $in-TASK = "";
next;
}
if $in-TASK ne "" && $Line.contains( "NAME type" ) {
$Line ~~ m/ 'NAME' .*? '>' $=( .*? ) '<' /;
say $in-TASK, $;
}
}


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


Re: How do I remove N elements

2017-03-21 Thread Norman Gaywood
On 21 March 2017 at 15:39, ToddAndMargo <toddandma...@zoho.com> wrote:

> from the beginning of an array?
>

untested but same as perl5:

splice @list, 0, $N;

https://docs.perl6.org/routine/splice



> I know about shift, but that is one at a time.  I suppose I
> could do a loo[, but it would be nice to do it all at once.
>
>
> Many thanks,
> -T
>



-- 
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 <(02)%206773%202412>  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