Re: classes and objects questions

2020-12-15 Thread WFB
JJ may be right about the OO thing, but it makes the
> tutorial pretty much useless.  How "class" and "object"
> *relate* to Raku needs to be explained.
>

When we are talking about describing Classes and Objects in a few words,
then I agree. Searching on the web reveals lots of tutorials for Java, C#
and so on with at least a few words about what classes and objects are.


>
> "The best is the enemy of the good".  It is better to
> slum it a bit and make the tutorial useful. JJ will
> hate it, but he will live.
>
I don't think JJ hates useful tutorials. But he has to find a balance. Look
in the Raku/doc repository
. Every week ~15
commits. And most of them on Sunday. Of course you can spend all day and
make the classtut perfect, at least what is your understanding of perfect.
But there is a lot more to be documented and maintained. You have to find a
level of detail that provides information for all readers and to have only
a limited amount of time and resources. That is JJ trying to do.
You are trying to shape the documentation for your needs. Sometimes the
best documentation is not your documentation.
In this case adding links for the Variables and a few sentences about
classes and objects would probably not hurt but I would listen to the
arguments JJ has. Because he knows the big pictures.

Best

>
> -T
>


Re: classes and objects questions

2020-12-14 Thread WFB
Hi ToddAndMargo,

Thanks for the effort to improve the Raku docs. However, this is a Raku not
OO (Object Oriented
) related
tutorial. As JJ already pointed out, these pages are to show the reader how
you get things done in Raku, not what OO or other programming concepts are.
There are probably thousands of OO books around and can teach you what a
class is and why you need them. See the Wikipedia link I linked above for
example. That's not in the scope of this tutorial.

The parts you are missing are already there, but unfortunately not linked.
You can find them in the Raku documentation:  =>
, $!
 and $.

:$ stands for a named parameter
 and
can be also found in the documentation.
^$ is used for ranges and is also already
there.

So the information you are missing is already there. You could argue that
the links are missing and I would agree with you. But again this tutorial
is for Raku classes not OO concept, Pairs, named parameters or ranges.

I hope that helped,
Wolfgang



On Tue, 15 Dec 2020 at 05:28, ToddAndMargo via perl6-users <
perl6-users@perl.org> wrote:

> On 12/14/20 5:24 PM, Aureliano Guedes wrote:
> > That's why, as a community-developed language (including docs) I'd like
> > to suggest to you help to improve the docs.
> > This way, when I have - with some lucky - free time, I may learn with
> > you and all others that wrote these docs.
>
> Hi Aureliano,
>
> I absolutely adore Raku.  But the docs are truly awful.
> They do not start out simple and build to the complex.
> They throw terms out without defining them.  They use
> things in examples that are require advanced level of
> knowledge to understand, and so on and so forth.
> They have broken virtually rule of technical writing.
> The docs are simply refreshers for those that already
> know what they are doing and do not need them.
>
> I have tried several times to contribute to and get
> the docs improved.  I have been told I am providing
> too much detail or just get ignored.  So I have
> stopped.  The culture of the "docs" is not something
> I can change.
>
> I would absolute love to see some kind of contributed
> docs portal that any user could pick out a subject and
> write on it with the ability for others to correct
> mistakes or add content.
>
> Once I get Classes and Object figured out, I will
> write my own documentation of the subject.  If I
> think it is good enough to share (some of my technical
> writing stinks too), I will post it back here.
>
> For starters, I need to have the definition of
> "class" and "object".  Then I need their rules.
>
> -T
>


Re: Access violation when creating class instance

2020-06-25 Thread WFB
Not reproducible with raku star 2020.05.1 \o/
Thanks for the help

On Thu, 25 Jun 2020 at 09:23, WFB  wrote:

> Uh, thanks Will!!
>
> On Thu, 25 Jun 2020 at 01:16, Will Coleda  wrote:
>
>> The download page requires an update. You can get 2020.05.1 here:
>>
>> https://rakudo.org/downloads/star/
>>
>> On Wed, Jun 24, 2020 at 6:11 AM WFB  wrote:
>> >
>> > Thanks JJ,
>> >
>> > I am using Rakudostar on Windows and 2020.01 is the current released
>> version so far.
>> > I will try to reduce the code a bit more but it is just one class
>> definition together with an instantiation. Not sure I can pack that in a
>> one liner, but will try.
>> >
>> > The access violation comes probably from C code handling some Windows
>> stuff.
>> >
>> > On Wed, 24 Jun 2020 at 10:13, JJ Merelo  wrote:
>> >>
>> >>
>> >>
>> >> El mié., 24 jun. 2020 a las 10:05, WFB ()
>> escribió:
>> >>>
>> >>> Hi all,
>> >>>
>> >>> I have an access violation on Windows for one of my classes and think
>> it is a bug, but not entirely sure about that.
>> >>>
>> >>> Every now and then creating a class instance ended my script with
>> error:
>> >>> Process finished with exit code -1073741819 (0xC005)
>> >>>
>> >>> The class looks like that:
>> >>>
>> >>> class KnowledgeKeeper::Note {
>> >>> has $.title is required;
>> >>> has $.data is required;
>> >>> has @.tags;
>> >>> has @.attachments;
>> >>> has DateTime $.creation-date = DateTime.now;
>> >>> has DateTime $.modification-date = DateTime.now;
>> >>> }
>> >>>
>> >>> I first recognized it when a test just ended without dieing. That
>> happens about in 50% of the test runs.
>> >>> But I could reproduce it with just a simple line in a script:
>> >>>
>> >>> #!/usr/bin/env perl6
>> >>> use KnowledgeKeeper::Note;
>> >>>
>> >>> my $note = KnowledgeKeeper::Note.new(title => "dasd", data =>
>> "adsad");
>> >>> say "OK";
>> >>>
>> >>> With this script it is not failing that much but at least
>> reproducible:
>> >>>
>> >>> PS C:\dev\repos\KnowledgeKeeper> raku -Ilib .\bin\test.p6
>>OK
>> >>> PS C:\dev\repos\KnowledgeKeeper> raku -Ilib .\bin\test.p6
>>OK
>> >>> PS C:\dev\repos\KnowledgeKeeper> raku -Ilib .\bin\test.p6
>>OK
>> >>> PS C:\dev\repos\KnowledgeKeeper> raku -Ilib .\bin\test.p6
>>OK
>> >>> PS C:\dev\repos\KnowledgeKeeper> raku -Ilib .\bin\test.p6
>>OK
>> >>> PS C:\dev\repos\KnowledgeKeeper> raku -Ilib .\bin\test.p6
>>OK
>> >>> PS C:\dev\repos\KnowledgeKeeper> raku -Ilib .\bin\test.p6
>>OK
>> >>> PS C:\dev\repos\KnowledgeKeeper> raku -Ilib .\bin\test.p6
>>OK
>> >>> PS C:\dev\repos\KnowledgeKeeper> raku -Ilib .\bin\test.p6
>>OK
>> >>> PS C:\dev\repos\KnowledgeKeeper> raku -Ilib .\bin\test.p6
>>OK
>> >>> PS C:\dev\repos\KnowledgeKeeper> raku -Ilib .\bin\test.p6
>>OK
>> >>> PS C:\dev\repos\KnowledgeKeeper> raku -Ilib .\bin\test.p6
>>OK
>> >>> PS C:\dev\repos\KnowledgeKeeper> raku -Ilib .\bin\test.p6
>>OK
>> >>> PS C:\dev\repos\KnowledgeKeeper> raku -Ilib .\bin\test.p6
>>OK
>> >>> PS C:\dev\repos\KnowledgeKeeper> raku -Ilib .\bin\test.p6
>>OK
>> >>> PS C:\dev\repos\KnowledgeKeeper> raku -Ilib .\bin\test.p6
>>OK
>> >>> PS C:\dev\repos\KnowledgeKeeper> raku -Ilib .\bin\test.p6
>>OK
>> >>> PS C:\dev\repos\KnowledgeKeeper> raku -Ilib .\bin\test.p6
>>   PS C:\dev\repos\KnowledgeKeeper>
>> $LastExitCode
>> -1073741819
>> >>>
>> >>> OS: Windows 10 1909 x64
>> >>> Raku: This is Rakudo version 2020.01 built on MoarVM version
>> 2020.01.1 implementing Perl 6.d.
>> >>>
>> >>> Should I file a bug?
>> >>
>> >>
>> >> Definitely, yes. Please check first if it's still the same problem
>> with the latest released version. Also, try to golf it down to the minimal
>> amount of code that still produces the same result. Does the LastExitCode
>> make any sense?
>> >>
>> >> --
>> >> JJ
>>
>


Re: Access violation when creating class instance

2020-06-25 Thread WFB
Uh, thanks Will!!

On Thu, 25 Jun 2020 at 01:16, Will Coleda  wrote:

> The download page requires an update. You can get 2020.05.1 here:
>
> https://rakudo.org/downloads/star/
>
> On Wed, Jun 24, 2020 at 6:11 AM WFB  wrote:
> >
> > Thanks JJ,
> >
> > I am using Rakudostar on Windows and 2020.01 is the current released
> version so far.
> > I will try to reduce the code a bit more but it is just one class
> definition together with an instantiation. Not sure I can pack that in a
> one liner, but will try.
> >
> > The access violation comes probably from C code handling some Windows
> stuff.
> >
> > On Wed, 24 Jun 2020 at 10:13, JJ Merelo  wrote:
> >>
> >>
> >>
> >> El mié., 24 jun. 2020 a las 10:05, WFB ()
> escribió:
> >>>
> >>> Hi all,
> >>>
> >>> I have an access violation on Windows for one of my classes and think
> it is a bug, but not entirely sure about that.
> >>>
> >>> Every now and then creating a class instance ended my script with
> error:
> >>> Process finished with exit code -1073741819 (0xC005)
> >>>
> >>> The class looks like that:
> >>>
> >>> class KnowledgeKeeper::Note {
> >>> has $.title is required;
> >>> has $.data is required;
> >>> has @.tags;
> >>> has @.attachments;
> >>> has DateTime $.creation-date = DateTime.now;
> >>> has DateTime $.modification-date = DateTime.now;
> >>> }
> >>>
> >>> I first recognized it when a test just ended without dieing. That
> happens about in 50% of the test runs.
> >>> But I could reproduce it with just a simple line in a script:
> >>>
> >>> #!/usr/bin/env perl6
> >>> use KnowledgeKeeper::Note;
> >>>
> >>> my $note = KnowledgeKeeper::Note.new(title => "dasd", data => "adsad");
> >>> say "OK";
> >>>
> >>> With this script it is not failing that much but at least reproducible:
> >>>
> >>> PS C:\dev\repos\KnowledgeKeeper> raku -Ilib .\bin\test.p6
>  OK
> >>> PS C:\dev\repos\KnowledgeKeeper> raku -Ilib .\bin\test.p6
>  OK
> >>> PS C:\dev\repos\KnowledgeKeeper> raku -Ilib .\bin\test.p6
>  OK
> >>> PS C:\dev\repos\KnowledgeKeeper> raku -Ilib .\bin\test.p6
>  OK
> >>> PS C:\dev\repos\KnowledgeKeeper> raku -Ilib .\bin\test.p6
>  OK
> >>> PS C:\dev\repos\KnowledgeKeeper> raku -Ilib .\bin\test.p6
>  OK
> >>> PS C:\dev\repos\KnowledgeKeeper> raku -Ilib .\bin\test.p6
>  OK
> >>> PS C:\dev\repos\KnowledgeKeeper> raku -Ilib .\bin\test.p6
>  OK
> >>> PS C:\dev\repos\KnowledgeKeeper> raku -Ilib .\bin\test.p6
>  OK
> >>> PS C:\dev\repos\KnowledgeKeeper> raku -Ilib .\bin\test.p6
>  OK
> >>> PS C:\dev\repos\KnowledgeKeeper> raku -Ilib .\bin\test.p6
>  OK
> >>> PS C:\dev\repos\KnowledgeKeeper> raku -Ilib .\bin\test.p6
>  OK
> >>> PS C:\dev\repos\KnowledgeKeeper> raku -Ilib .\bin\test.p6
>  OK
> >>> PS C:\dev\repos\KnowledgeKeeper> raku -Ilib .\bin\test.p6
>  OK
> >>> PS C:\dev\repos\KnowledgeKeeper> raku -Ilib .\bin\test.p6
>  OK
> >>> PS C:\dev\repos\KnowledgeKeeper> raku -Ilib .\bin\test.p6
>  OK
> >>> PS C:\dev\repos\KnowledgeKeeper> raku -Ilib .\bin\test.p6
>  OK
> >>> PS C:\dev\repos\KnowledgeKeeper> raku -Ilib .\bin\test.p6
> PS C:\dev\repos\KnowledgeKeeper>
> $LastExitCode
> -1073741819
> >>>
> >>> OS: Windows 10 1909 x64
> >>> Raku: This is Rakudo version 2020.01 built on MoarVM version 2020.01.1
> implementing Perl 6.d.
> >>>
> >>> Should I file a bug?
> >>
> >>
> >> Definitely, yes. Please check first if it's still the same problem with
> the latest released version. Also, try to golf it down to the minimal
> amount of code that still produces the same result. Does the LastExitCode
> make any sense?
> >>
> >> --
> >> JJ
>


Re: Access violation when creating class instance

2020-06-24 Thread WFB
Thanks JJ,

I am using Rakudostar on Windows and 2020.01 is the current released
version so far.
I will try to reduce the code a bit more but it is just one class
definition together with an instantiation. Not sure I can pack that in a
one liner, but will try.

The access violation comes probably from C code handling some Windows
stuff.

On Wed, 24 Jun 2020 at 10:13, JJ Merelo  wrote:

>
>
> El mié., 24 jun. 2020 a las 10:05, WFB ()
> escribió:
>
>> Hi all,
>>
>> I have an access violation on Windows for one of my classes and think it
>> is a bug, but not entirely sure about that.
>>
>> Every now and then creating a class instance ended my script with error:
>> Process finished with exit code -1073741819 (0xC005)
>>
>> The class looks like that:
>>
>> class KnowledgeKeeper::Note {
>> has $.title is required;
>> has $.data is required;
>> has @.tags;
>> has @.attachments;
>> has DateTime $.creation-date = DateTime.now;
>> has DateTime $.modification-date = DateTime.now;
>> }
>>
>> I first recognized it when a test just ended without dieing. That happens
>> about in 50% of the test runs.
>> But I could reproduce it with just a simple line in a script:
>>
>> #!/usr/bin/env perl6
>> use KnowledgeKeeper::Note;
>>
>> my $note = KnowledgeKeeper::Note.new(title => "dasd", data => "adsad");
>> say "OK";
>>
>> With this script it is not failing that much but at least reproducible:
>>
>> PS C:\dev\repos\KnowledgeKeeper> raku -Ilib .\bin\test.p6
>>   OK
>> PS C:\dev\repos\KnowledgeKeeper> raku -Ilib .\bin\test.p6
>>   OK
>> PS C:\dev\repos\KnowledgeKeeper> raku -Ilib .\bin\test.p6
>>   OK
>> PS C:\dev\repos\KnowledgeKeeper> raku -Ilib .\bin\test.p6
>>   OK
>> PS C:\dev\repos\KnowledgeKeeper> raku -Ilib .\bin\test.p6
>>   OK
>> PS C:\dev\repos\KnowledgeKeeper> raku -Ilib .\bin\test.p6
>>   OK
>> PS C:\dev\repos\KnowledgeKeeper> raku -Ilib .\bin\test.p6
>>   OK
>> PS C:\dev\repos\KnowledgeKeeper> raku -Ilib .\bin\test.p6
>>   OK
>> PS C:\dev\repos\KnowledgeKeeper> raku -Ilib .\bin\test.p6
>>   OK
>> PS C:\dev\repos\KnowledgeKeeper> raku -Ilib .\bin\test.p6
>>   OK
>> PS C:\dev\repos\KnowledgeKeeper> raku -Ilib .\bin\test.p6
>>   OK
>> PS C:\dev\repos\KnowledgeKeeper> raku -Ilib .\bin\test.p6
>>   OK
>> PS C:\dev\repos\KnowledgeKeeper> raku -Ilib .\bin\test.p6
>>   OK
>> PS C:\dev\repos\KnowledgeKeeper> raku -Ilib .\bin\test.p6
>>   OK
>> PS C:\dev\repos\KnowledgeKeeper> raku -Ilib .\bin\test.p6
>>   OK
>> PS C:\dev\repos\KnowledgeKeeper> raku -Ilib .\bin\test.p6
>>   OK
>> PS C:\dev\repos\KnowledgeKeeper> raku -Ilib .\bin\test.p6
>>   OK
>> PS C:\dev\repos\KnowledgeKeeper> raku -Ilib .\bin\test.p6
>>  PS C:\dev\repos\KnowledgeKeeper>
>> $LastExitCode
>>-1073741819
>>
>> OS: Windows 10 1909 x64
>> Raku: This is Rakudo version 2020.01 built on MoarVM version 2020.01.1
>> implementing Perl 6.d.
>>
>> Should I file a bug?
>>
>
> Definitely, yes. Please check first if it's still the same problem with
> the latest released version. Also, try to golf it down to the minimal
> amount of code that still produces the same result. Does the LastExitCode
> make any sense?
>
> --
> JJ
>


Access violation when creating class instance

2020-06-24 Thread WFB
Hi all,

I have an access violation on Windows for one of my classes and think it is
a bug, but not entirely sure about that.

Every now and then creating a class instance ended my script with error:
Process finished with exit code -1073741819 (0xC005)

The class looks like that:

class KnowledgeKeeper::Note {
has $.title is required;
has $.data is required;
has @.tags;
has @.attachments;
has DateTime $.creation-date = DateTime.now;
has DateTime $.modification-date = DateTime.now;
}

I first recognized it when a test just ended without dieing. That happens
about in 50% of the test runs.
But I could reproduce it with just a simple line in a script:

#!/usr/bin/env perl6
use KnowledgeKeeper::Note;

my $note = KnowledgeKeeper::Note.new(title => "dasd", data => "adsad");
say "OK";

With this script it is not failing that much but at least reproducible:

PS C:\dev\repos\KnowledgeKeeper> raku -Ilib .\bin\test.p6
OK
PS C:\dev\repos\KnowledgeKeeper> raku -Ilib .\bin\test.p6
OK
PS C:\dev\repos\KnowledgeKeeper> raku -Ilib .\bin\test.p6
OK
PS C:\dev\repos\KnowledgeKeeper> raku -Ilib .\bin\test.p6
OK
PS C:\dev\repos\KnowledgeKeeper> raku -Ilib .\bin\test.p6
OK
PS C:\dev\repos\KnowledgeKeeper> raku -Ilib .\bin\test.p6
OK
PS C:\dev\repos\KnowledgeKeeper> raku -Ilib .\bin\test.p6
OK
PS C:\dev\repos\KnowledgeKeeper> raku -Ilib .\bin\test.p6
OK
PS C:\dev\repos\KnowledgeKeeper> raku -Ilib .\bin\test.p6
OK
PS C:\dev\repos\KnowledgeKeeper> raku -Ilib .\bin\test.p6
OK
PS C:\dev\repos\KnowledgeKeeper> raku -Ilib .\bin\test.p6
OK
PS C:\dev\repos\KnowledgeKeeper> raku -Ilib .\bin\test.p6
OK
PS C:\dev\repos\KnowledgeKeeper> raku -Ilib .\bin\test.p6
OK
PS C:\dev\repos\KnowledgeKeeper> raku -Ilib .\bin\test.p6
OK
PS C:\dev\repos\KnowledgeKeeper> raku -Ilib .\bin\test.p6
OK
PS C:\dev\repos\KnowledgeKeeper> raku -Ilib .\bin\test.p6
OK
PS C:\dev\repos\KnowledgeKeeper> raku -Ilib .\bin\test.p6
OK
PS C:\dev\repos\KnowledgeKeeper> raku -Ilib .\bin\test.p6
   PS C:\dev\repos\KnowledgeKeeper>
$LastExitCode
   -1073741819

OS: Windows 10 1909 x64
Raku: This is Rakudo version 2020.01 built on MoarVM version 2020.01.1
implementing Perl 6.d.

Should I file a bug?
Thanks,
Wolfgang


Re: fill in form

2020-05-12 Thread WFB
Years ago I played around with qt and GTK::Simple. It works fine, but the
installation process on Windows is poor, to say at least.
It might be not better, but you could use the PowerShell to show a GUI and
store something in a txt file you then parse.

On Tue, 12 May 2020 at 10:22, ToddAndMargo via perl6-users <
perl6-users@perl.org> wrote:

> On 2020-05-11 17:14, ToddAndMargo via perl6-users wrote:
> > On 2020-05-11 15:47, ToddAndMargo via perl6-users wrote:
> >> Hi All,
> >>
> >> I want to create a fill in form in Windows: city,
> >> state, etc., you fill in the data.
> >>
> >> Is there some library out there for that?
> >>
> >> Any words of wisdom?
> >>
> >> Many thanks,
> >> -T
> >
> >
> > GTK::Simple does work in Window, but I am at a loss
> > for an example of a fill in form.
>
> Found this:
>
> https://glade.gnome.org/
>
> I have some reading to do!
>
> Says it works with Perl too.  Five I presume.
>
> -T
>


Raku -npe command line usage

2020-05-08 Thread WFB
Hi,

I am trying to write an one-liner to go through all lines in a logfile and
look for an certain key word, store the line and sort them before printing
them out.

My approach was:
raku -ne "BEGIN {my @i }; @i.push($_); if $_ ~~ /^WARN/; END { @i.sort.say
}"
That does not work because @i does not exist in the if clause. I tried our
@i as well with no luck.

How can I store data that can be accessed in the END phaser? Or is there
another way to archive it? TIMTOWTDI^^

One hint I found was the variable $ and @ respectively. But those variables
are created for each line new...


I did not found a help or examples for -npe except raku -h. Is there more
helpful stuff somewhere in doc.raku.org? If so I could'nt find it.

Thanks,
Wolfgang


Re: printf question

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


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

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


Re: printf question

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

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

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

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


Re: Bug to report: cardinal called an integer

2020-01-12 Thread WFB
Hi Todd,

For years, I have been playing around with programming stuff. I never
stumbled across the term "cardinal". Its obvious that I am not an native
English speaker and it does not hurt to learn new stuff. But, you makes it
harder to understand your problems if you not use the common jargon.

Regards,
Wolfgang

On Mon, 13 Jan 2020 at 05:03, Darren Duncan  wrote:

> On 2020-01-09 10:10 a.m., ToddAndMargo via perl6-users wrote:
> > A bug to report:
> >
> > $ p6 'my uint32 $c; $c = "ABC";'
> > This type cannot unbox to a native integer: P6opaque, Str
> >in block  at -e line 1
> >
> > "uint32" is not an "integer".  It is a cardinal.  If
> > they really want to use the word "integer" for cardinal,
> > they should change the wording to "unsigned integer".
> >
> > Picky, picky, picky
>
> ToddAndMargo, you are wrong on this.
>
> A uint32 is NOT specifically a cardinal.
>
> At best you can say it can be characterized by a cardinal or be isomorphic
> to one.
>
> A uint32 is just as much an ordinal as a cardinal, so insisting on calling
> it a
> cardinal means the type can't be used as an ordinal, or a variety of other
> things.
>
> Calling this an unsigned integer (u int) is much more accurate as it
> doesn't
> presume a particular semantics such as that we are storing a count rather
> than a
> position for example, it says what we actually know, and no more.
>
> You are also wrong on saying that the values one can store in a uint32 are
> not
> integers; they definitely ARE integers.  Every cardinal is an integer.
>
> If you want to be precise, calling a uint32 an "unsigned integer" or
> "cardinal"
> is inaccurate in the same way that calling it an "integer" is.  In either
> case,
> the variable can only hold a proper subset of either type, not all of
> them.  If
> you're calling integer wrong then one will have to call the type something
> like
> "integers in the range 0..^2**32".
>
> -- Darren Duncan
>


Re: int and Str in sub declaration question

2020-01-08 Thread WFB
For the sake of readability you might want use a subset:
https://docs.raku.org/language/typesystem#subset

On Thu, 9 Jan 2020 at 08:13, WFB  wrote:

> Hi, Todd,
>
> If I understand your question right, then you mean something like that:
>
> sub do-soemthing($value where { .WHAT ~~ Str || .WHAT ~~ Int }) {}
>
> https://docs.raku.org/type/Signature#index-entry-where_clause
>
> Regards
>
> On Thu, 9 Jan 2020 at 03:58, ToddAndMargo via perl6-users <
> perl6-users@perl.org> wrote:
>
>> Hi All,
>>
>> In a sub declaration, is there a way to constrain
>> a variable to only an "int32" or a "Str" (I want both)?
>> Or do I have to put up with the other types of "Any"?
>>
>> Many thanks,
>> -T
>>
>


Re: int and Str in sub declaration question

2020-01-08 Thread WFB
Hi, Todd,

If I understand your question right, then you mean something like that:

sub do-soemthing($value where { .WHAT ~~ Str || .WHAT ~~ Int }) {}

https://docs.raku.org/type/Signature#index-entry-where_clause

Regards

On Thu, 9 Jan 2020 at 03:58, ToddAndMargo via perl6-users <
perl6-users@perl.org> wrote:

> Hi All,
>
> In a sub declaration, is there a way to constrain
> a variable to only an "int32" or a "Str" (I want both)?
> Or do I have to put up with the other types of "Any"?
>
> Many thanks,
> -T
>


Re: type?

2020-01-08 Thread WFB
Hi Todd,

dd or .WHAT will give you that information.

dd $i;
say $i.WHAT;

Greetings


On Thu, 9 Jan 2020 at 03:58, ToddAndMargo via perl6-users <
perl6-users@perl.org> wrote:

> Hi All,
>
>  Is there a way to ask a variable what "type" it is?
>
> Many thanks,
> -T
>


Re: Request for Enhancement: Native Call error

2020-01-07 Thread WFB
Hi Todd,

I think RegQueryValueExW is not the best choice for this to get the job
done. Back in the $work with a Windows box, I looked around and found the
RegGetValueW method:
https://docs.microsoft.com/en-us/windows/win32/api/winreg/nf-winreg-reggetvaluew

This method accept a type. No need to use an array with fixed size for the
return data.

Greetings
Wolf

On Fri, 3 Jan 2020 at 20:24, ToddAndMargo via perl6-users <
perl6-users@perl.org> wrote:

> >> On Wed, 1 Jan 2020 at 03:48, ToddAndMargo via perl6-users
> >> mailto:perl6-users@perl.org>> wrote:
> >>
> >> Hi All,
> >>
> >> Request for Enhancement: Native Call error
> >>
> >> perl6 -I. -e "use WinReg :WinReadRegKey; say WinReadRegKey(
> >> HKEY_LOCAL_MACHINE,
> >> Q[SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\system],
> >> Q[EnableLUA] );"
> >>
> >> Native call expected argument that references a native integer, but
> got
> >> P6int in method CALL-ME at
> >>
>  C:\rakudo\share\perl6\sources\947BDAB9F96E0E5FCCB383124F923A6BF6F8D76B
> >> (NativeCall) line 587 in sub WinReadRegKey at
> >> K:\Windows\NtUtil\WinReg.pm6 (WinReg) line 177 in block  at -e
> >> line 1
> >>
> >>
> >> "references a native integer, but got P6int" is NOT REALLY HELPFUL.
> >> Would you please tell me which one threw this error?
> >>
> >>
> >> Many thanks,
> >> -T
>
> On 2020-01-01 07:06, WFB wrote:
> > Hi Todd,
> > Sounds like in WinReg.pm6 line 177 is a definition like :
> >   sub RegOpenKeyExW( DWORD, WCHARS, DWORD, DWORD, DWORD is rw) is
> > native("Kernel32.dll") returns DWORD { * };
> > and you put a "my $i = 0" variable instead of "my int32 $i = 0" in it
> > somewhere.
> >
> > Greetings,
> > Wolf
> >
> Hi Wolf,
>
> I did figure it out.  I would just like the error message
> to be a little more helpful.
>
> sub RegQueryValueExW( DWORD, WCHARS, DWORD, DWORD, CArray[BYTE] is
> rw, DWORD is rw ) is native( "Kernel32.dll" ) is symbol(
> "RegQueryValueExW" ) returns DWORD { * };
>
> $RtnCode = RegQueryValueExW( $Handle, $lpValueName, 0, $lpType,
> $lpData, $lpcbData );
>
> -T
>


Re: Request for Enhancement: Native Call error

2020-01-01 Thread WFB
Hi Todd,
Sounds like in WinReg.pm6 line 177 is a definition like :
 sub RegOpenKeyExW( DWORD, WCHARS, DWORD, DWORD, DWORD is rw) is
native("Kernel32.dll") returns DWORD { * };
and you put a "my $i = 0" variable instead of "my int32 $i = 0" in it
somewhere.

Greetings,
Wolf

On Wed, 1 Jan 2020 at 03:48, ToddAndMargo via perl6-users <
perl6-users@perl.org> wrote:

> Hi All,
>
> Request for Enhancement: Native Call error
>
> perl6 -I. -e "use WinReg :WinReadRegKey; say WinReadRegKey(
> HKEY_LOCAL_MACHINE,
> Q[SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\system],
> Q[EnableLUA] );"
>
> Native call expected argument that references a native integer, but got
> P6int in method CALL-ME at
> C:\rakudo\share\perl6\sources\947BDAB9F96E0E5FCCB383124F923A6BF6F8D76B
> (NativeCall) line 587 in sub WinReadRegKey at
> K:\Windows\NtUtil\WinReg.pm6 (WinReg) line 177 in block  at -e line 1
>
>
> "references a native integer, but got P6int" is NOT REALLY HELPFUL.
> Would you please tell me which one threw this error?
>
>
> Many thanks,
> -T
>


Re: null and native call question

2019-12-29 Thread WFB
Hi Todd,
I am curious, what was the problem?
I tried 0 in the first place and the script died. Though it has something
to do with the 0 but obviously it has not.

On Sun, 29 Dec 2019 at 10:31, ToddAndMargo via perl6-users <
perl6-users@perl.org> wrote:

> On 2019-12-29 00:28, ToddAndMargo via perl6-users wrote:
> >>> On Fri, Dec 27, 2019 at 6:06 AM ToddAndMargo via perl6-users
> >>> mailto:perl6-users@perl.org>> wrote:
> >>>
> >>> Hi All,
> >>>
> >>> https://docs.perl6.org/language/nativecall
> >>>
> >>>"As you may have predicted by now, a NULL pointer
> >>>is represented by the type object of the struct type."
> >>>
> >>>
> >>>
> https://docs.microsoft.com/en-us/windows/win32/api/winreg/nf-winreg-regqueryvalueexw
> >>>
> >>>
> >>>C++
> >>>LSTATUS RegQueryValueExW(
> >>>  HKEYhKey,
> >>>  LPCWSTR lpValueName,
> >>>  LPDWORD lpReserved,
> >>>  LPDWORD lpType,
> >>>  LPBYTE  lpData,
> >>>  LPDWORD lpcbData
> >>>);
> >>>
> >>>lpReserved
> >>>This parameter is reserved and must be NULL.
> >>>
> >>> With "native", how do I satisfy the "NULL" requirement?
> >>>
> >>> constant WCHAR   := uint16;
> >>>
> >>> constant DWORD   := int32;
> >>>
> >>>
> >>> sub RegQueryValueExW( DWORD, WCHARS, DWORD, DWORD, DWORD is rw,
> >>> DWORD is
> >>> rw ) is native("Kernel32.dll") returns DWORD { * };
> >>>
> >>> $RtnCode = RegQueryValueExW( $Handle, $lpValueName, int32,
> >>> REG_DWORD,
> >>> $lpData, $lpcbData );
> >>>
> >>> "int32" returns:
> >>>
> >>>   Cannot unbox a type object (int32) to int in method
> >>>   CALL-ME at C:\rakudo\share\perl6\sources
> >>> \947BDAB9F96E0E5FCCB383124F9
> >>>   23A6BF6F8D76B (NativeCall) line 587
> >>>
> >>>
> >>> Many thanks,
> >>> -T
> >>>
> >
> > On 2019-12-27 06:10, Brad Gilbert wrote:
> >> A Null pointer is just a pointer that points to the address 0.
> >>
> >> So if you are dealing with it as an integer it will be 0.
>
> Hi Brad,
>
> Disregard my last post.  I found a booboo somewhere else.
> You were correct about the zero.
>
> Thank you!
>
> -T
>


Re: how do I read registry key?

2019-12-27 Thread WFB
Hi Todd,

According to this:
https://docs.microsoft.com/en-us/windows/win32/debug/system-error-codes--0-499-
Return code 161 means: ERROR_BAD_PATHNAME.
Changing your code fixed that:
 my Str   $SubKey =
'SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Policies\\System';
 my   $lpValueName = wstr('EnableLUA');

Then the return code of the RegQueryValueExW is 87. According to the page
above, that means ERROR_INVALID_PARAMETER.
Because of that I looked at the RegQueryValueExW help page you linked and
noticed that it says:

lpReserved

This parameter is reserved and must be *NULL*.

In your code there is a 1 given. Unfortunately, just a 0 does not helped.
Here, I have no idea how a NULL is given.


Regards,

Wolf


On Fri, 27 Dec 2019 at 08:22, WFB  wrote:

> I would love to look into that, however, my son needs all my free time and
> I do have very little knowledge about NativeCall.
> I hope I will find time in the next days to learn more of this stuff, but
> I will not much help :-(
>
>
> On Fri, 27 Dec 2019 at 07:31, ToddAndMargo via perl6-users <
> perl6-users@perl.org> wrote:
>
>> This is how far I have gotten:
>>
>> Note that is I use a "0" in
>>
>> $RtnCode = RegQueryValueExW( HKEY_LOCAL_MACHINE, $lpValueName, 1,
>> REG_DWORD, $lpData, $lpcbData );
>>
>> The program dies with no return code.
>>
>> -T
>>
>>
>>
>>  K:\Windows\NtUtil>perl6 -I. -e "use WinMount :GetLUA; say
>> GetLUA();"
>>  RegOpenKeyExW
>>  RegOpenKeyExW   RtnCode 161
>>
>>  RegQueryValueExW
>>  1
>>  2
>>  RegQueryValueExW   RtnCode 87
>>  lpData pointer 0
>>  lpcbData data length 0
>>
>>  RegCloseKey
>>  RegCloseKey   RtnCode 6
>>
>>  True
>>
>>
>>
>>
>>
>>  # unit module WinMount;
>>  # WinMount.pm6
>>
>>  #`{
>>
>> Utilities to mount and dismound drive partitions
>> Note: LUA must be unset (0x) for mount to function
>> prpoperly
>>
>> raku -I. -c WinMount.pm6
>>
>>  }
>>
>>  use NativeCall;
>>  use WinPopUps :WinMsg;
>>
>>
>>  # Reference to types and values:
>> http://dsource.org/projects/tango/ticket/820
>>
>>  constant BYTE:= uint8;
>>  constant WCHAR   := uint16;
>>  constant DWORD   := int32;
>>  constant REGSAM  := int32;
>>  constant WCHARS  := CArray[WCHAR];
>>  constant BYTES   := CArray[BYTE];
>>
>>  constant HKEY_CURRENT_USER  = 0x8001;
>>  constant HKEY_LOCAL_MACHINE = 0x8002;
>>  constant KEY_QUERY_VALUE   = 1;
>>  constant ERROR_SUCCESS = 0; # Yeah, I know. The Win-Api
>> uses 0 for success and other values to indicate errors
>>  constant REG_SZ = 1;
>>
>>  constant KEY_READ  = 0x20019;
>>  constant KEY_SET_VALUE = 0x0002;
>>  constant REG_DWORD = 0x0004;
>>
>>
>>
>>  sub to-c-str( Str $str ) returns CArray[WCHAR]  is export(
>> :to-c-str ) {
>> my @str := CArray[WCHAR].new;
>> for ( $str.comb ).kv -> $i, $char { @str[$i] = $char.ord; }
>> @str[ $str.chars ] = 0;
>> @str;
>>  }
>>
>>
>>  sub wstr( Str $str ) returns WCHARS  is export( :wstr ) {
>>  CArray[WCHAR].new( $str.comb.map: *.ord )
>>  }
>>
>>
>>  sub GetLUA() is export( :GetLUA ) {
>>
>>  #`{
>>
>>  Returns the LUA value in the registry to True (0x0001) or
>> False (0x)
>>
>>
>>
>> [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System]
>>"EnableLUA"=dword:
>>
>>  https://docs.perl6.org/language/nativecall
>>
>>  }
>>
>> my Str $SubName = &?ROUTINE.name;
>> my Str $OS  = $*KERNEL.name;
>> if not $OS eq "win32" { say "Sorry, $SubName only work in
>> Windows."; exit; }
>>
>> my Bool  $LUA = True;
>> my   $RtnCode;
>>
>> my Str   $SubKey =
>> '\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System';
>> my Str   $Key = $SubKey ~ '\EnableLUA';
>>
>> 

Re: how do I read registry key?

2019-12-26 Thread WFB
I would love to look into that, however, my son needs all my free time and
I do have very little knowledge about NativeCall.
I hope I will find time in the next days to learn more of this stuff, but I
will not much help :-(


On Fri, 27 Dec 2019 at 07:31, ToddAndMargo via perl6-users <
perl6-users@perl.org> wrote:

> This is how far I have gotten:
>
> Note that is I use a "0" in
>
> $RtnCode = RegQueryValueExW( HKEY_LOCAL_MACHINE, $lpValueName, 1,
> REG_DWORD, $lpData, $lpcbData );
>
> The program dies with no return code.
>
> -T
>
>
>
>  K:\Windows\NtUtil>perl6 -I. -e "use WinMount :GetLUA; say
> GetLUA();"
>  RegOpenKeyExW
>  RegOpenKeyExW   RtnCode 161
>
>  RegQueryValueExW
>  1
>  2
>  RegQueryValueExW   RtnCode 87
>  lpData pointer 0
>  lpcbData data length 0
>
>  RegCloseKey
>  RegCloseKey   RtnCode 6
>
>  True
>
>
>
>
>
>  # unit module WinMount;
>  # WinMount.pm6
>
>  #`{
>
> Utilities to mount and dismound drive partitions
> Note: LUA must be unset (0x) for mount to function
> prpoperly
>
> raku -I. -c WinMount.pm6
>
>  }
>
>  use NativeCall;
>  use WinPopUps :WinMsg;
>
>
>  # Reference to types and values:
> http://dsource.org/projects/tango/ticket/820
>
>  constant BYTE:= uint8;
>  constant WCHAR   := uint16;
>  constant DWORD   := int32;
>  constant REGSAM  := int32;
>  constant WCHARS  := CArray[WCHAR];
>  constant BYTES   := CArray[BYTE];
>
>  constant HKEY_CURRENT_USER  = 0x8001;
>  constant HKEY_LOCAL_MACHINE = 0x8002;
>  constant KEY_QUERY_VALUE   = 1;
>  constant ERROR_SUCCESS = 0; # Yeah, I know. The Win-Api
> uses 0 for success and other values to indicate errors
>  constant REG_SZ = 1;
>
>  constant KEY_READ  = 0x20019;
>  constant KEY_SET_VALUE = 0x0002;
>  constant REG_DWORD = 0x0004;
>
>
>
>  sub to-c-str( Str $str ) returns CArray[WCHAR]  is export(
> :to-c-str ) {
> my @str := CArray[WCHAR].new;
> for ( $str.comb ).kv -> $i, $char { @str[$i] = $char.ord; }
> @str[ $str.chars ] = 0;
> @str;
>  }
>
>
>  sub wstr( Str $str ) returns WCHARS  is export( :wstr ) {
>  CArray[WCHAR].new( $str.comb.map: *.ord )
>  }
>
>
>  sub GetLUA() is export( :GetLUA ) {
>
>  #`{
>
>  Returns the LUA value in the registry to True (0x0001) or
> False (0x)
>
>
>
> [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System]
>"EnableLUA"=dword:
>
>  https://docs.perl6.org/language/nativecall
>
>  }
>
> my Str $SubName = &?ROUTINE.name;
> my Str $OS  = $*KERNEL.name;
> if not $OS eq "win32" { say "Sorry, $SubName only work in
> Windows."; exit; }
>
> my Bool  $LUA = True;
> my   $RtnCode;
>
> my Str   $SubKey =
> '\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System';
> my Str   $Key = $SubKey ~ '\EnableLUA';
>
> my   $lpSubKey= wstr( $SubKey );
> my   $lpValueName = wstr( $Key );
> # my $lpSubKey= CArray[uint8].new($Key.encode.list);
> # my $lpValueName = CArray[uint8].new($SubKey.encode.list);
>
>
> my int32 $Handle;
> my int32 $ulOptions = 0;
> my int32 $lpData;
> my int32 $lpcbData;
>
>
>  #`{
>  Open the key:
>
>
> https://docs.microsoft.com/en-us/windows/win32/api/winreg/nf-winreg-regopenkeyexw
>
>
> https://docs.microsoft.com/en-us/windows/win32/sysinfo/registry-key-security-and-access-rights
>  C++
>  LSTATUS RegOpenKeyExW(
> HKEYhKey,  # Hive name (HKEY_LOCAL_MACHINE)
> LPCWSTR lpSubKey,  # path to the
> key(/SOFTWARE/Microsoft/Windows/CurrentVersion/Policies/System/EnableLUA)
> DWORD   ulOptions, # 0
> REGSAM  samDesired,# KEY_READ (0x20019),
> KEY_SET_VALUE (0x0002)
> PHKEY   phkResult  # A pointer to a variable that
> receives a handle to the opened key
>  );
>  }
> say "RegOpenKeyExW";
> sub RegOpenKeyExW( DWORD, WCHARS, DWORD, DWORD, DWORD is rw)
> is native("Kernel32.dll") returns DWORD { * };
> $RtnCode = RegOpenKeyExW( HKEY_LOCAL_MACHINE, $lpSubKey,
> $ulOptions, KEY_READ, $Handle );
> say "RegOpenKeyExW   RtnCode $RtnCode\n";
>
>
>
>  #`{
>  Read the key:
>  use RegQueryValueExW if you know key and value name
>
>
> https://docs.microsoft.com/en-us/windows/win32/api/winreg/nf-winreg-regqueryvalueexw
>  

Re: My pop ups for windows module

2019-12-26 Thread WFB
Hi Todd,
I refactored your code a bit to make it a bit more readable IMHO. Thinking
on publish it on modules.raku.org if you are not interested to do so.

#`{
   Reference:

https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-messagebox

https://stackoverflow.com/questions/59105696/how-can-i-create-pop-up-windows-for-perl6-in-windows
}

use NativeCall;

enum Icons (
MB_ICONEXCLAMATION   => 0x0030,
MB_ICONWARNING   => 0x0030,
MB_ICONINFORMATION   => 0x0040,
MB_ICONASTERISK  => 0x0040,
MB_ICONQUESTION  => 0x0020,
MB_ICONSTOP  => 0x0010,
MB_ICONERROR => 0x0010,
MB_ICONHAND  => 0x0010
);

enum Buttons (
MB_ABORTRETRYIGNORE  => 0x0002,
MB_CANCELTRYCONTINUE => 0x0006,
MB_HELP  => 0x4000,
MB_OK=> 0x,
MB_OKCANCEL  => 0x0001,
MB_RETRYCANCEL   => 0x0005,
MB_YESNO => 0x0004,
MB_YESNOCANCEL   => 0x0003
);

enum MessageBoxReturn (
DABORT =>  3,
IDCANCEL   =>  2,
IDCONTINUE => 11,
IDIGNORE   =>  5,
IDNO   =>  7,
IDOK   =>  1,
IDRETRY=>  4,
IDTRYAGAIN => 10,
IDYES  =>  6
);

constant WCHAR  = uint16;
constant INT= int32;
constant UINT   = uint32;
constant HANDLE = Pointer[void];
constant LPWCTSTR   = CArray[WCHAR];

sub MessageBoxW( HANDLE, LPWCTSTR, LPWCTSTR, UINT ) is
native('user32') returns INT { * };

sub to-c-str( Str $str ) returns CArray[WCHAR]  {
my @str := CArray[WCHAR].new;
for ( $str.comb ).kv -> $i, $char { @str[$i] = $char.ord; }
@str[ $str.chars ] = 0;
@str;
}

sub MessageBox(Str $title, Str $message, Icons $icon =
Icons::MB_ICONINFORMATION, Buttons $button = Buttons::MB_OK) returns
MessageBoxReturn is export
{
   my Str $SubName = &?ROUTINE.name;
my Str $OS  = $*KERNEL.name;

if not $OS eq "win32" { say "Sorry, $SubName only work in Windows.";
exit; }

MessageBoxReturn(MessageBoxW( my $handle, to-c-str( $message ),
to-c-str( $title ), $icon +| $button ));
}


On Sat, 7 Dec 2019 at 13:36, Tom Browder  wrote:

> On Sat, Dec 7, 2019 at 05:41 ToddAndMargo via perl6-users <
> perl6-users@perl.org> wrote:
>
>> Hi All,
>>
>> I wrote and extensive module for pop up in Windows.
>
>
> Todd, you need to publish your module to the Raku module ecosystem. Many
> people, including myself, want to see an easily-installable module with at
> least some basic tests to give strangers confidence that it will not blow
> up. Instructions are in the docs, and there are helper modules to get you
> started.
>
> I'll send you specific doc references later when I get a chance, but it's
> probably better for you to dig around the doc site a bit more on your own.
> Hint: in the search box, enter 'module'.
>
> -Tom
>
>
>>
>> It does not contain a time out option.  Maybe some day I
>> will work on the timer function.
>>
>> Thank you all for helping me with various parts of this!
>>
>> There are basically two subs to import
>>  WinMsg  and  WinPopUp
>>
>> Here are some one liners to test it with:
>>
>> perl6 -e "use lib '.'; use WinPopUps :WinPopUp; say WinPopUp( 'Super
>> Duper Title', 'What? You were expecting something witty?',
>> 'Information', 'Ok'  );"
>>
>> perl6 -e "use lib '.'; use WinPopUps :WinPopUp; say WinPopUp( 'Super
>> Duper Title', 'What? You were expecting something witty?', 'Question',
>> 'YesNoCancel' );
>>
>> perl6 -e "use lib '.'; use WinPopUps :WinPopUp, :WinMsg; WinMsg( 'Super
>> Duper Title', 'What? You were expecting something witty?' );"
>>
>> Let me know if you find any booboo's.
>>
>> -T
>>
>>
>> 
>> # unit module WinPopUps;
>> # WinMsg.pm6
>>
>> #`{
>>Reference:
>>
>>
>> https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-messagebox
>>
>>
>> https://stackoverflow.com/questions/59105696/how-can-i-create-pop-up-windows-for-perl6-in-windows
>> }
>>
>> use NativeCall;
>>
>> sub WinPopUp( Str $TitleStr,
>>Str $MessageStr,
>>Str $Icons where   * ~~ "Exclamation" |
>>"Warning" |
>>"Information" |
>>"Asterisk"|
>>"Question"|
>>"Stop"|
>>"Error"   |
>>"Hand",
>>Str $Buttons where * ~~ "AbortRetryIgnore"|
>>"CancelTryAgainContinue"  |
>>"Help"|
>>

Re: how do I read registry key?

2019-12-25 Thread WFB
On Wed, 25 Dec 2019 at 23:10, ToddAndMargo via perl6-users <
perl6-users@perl.org> wrote:

> Hi All,
>
> Windows
>
>
> https://docs.microsoft.com/en-us/windows/win32/sysinfo/retrieving-data-from-the-registry
>
> How do I use this to read retrieve a value of a registry key?
>
> Many thanks,
> -T
>

Hi Todd,

Two things comes to mind for solving this. First, you use the Windows
Commandline command REG together with "run". See REG /? for more
information.
Or second, use NativeCall to use the Windows API calls similar to your
MessageBox module.
Your link shows the needed API calls.

BTW, hat would be also a great module for pushing to
https://modules.raku.org/.

Greetings,
Wolf


Re: Multibyte string in Windows command line

2018-09-13 Thread WFB
Never mind. .lines gives back Str and thus .encode is needed...
Thanks again

On Fri, 14 Sep 2018 at 06:20, WFB  wrote:

> @Andreas Thanks, I was thinking to do that with regex by myself, but that
> would be a ugly workaround and only as a last resort.
>
> @Brad: Cool, thanks, I got the errors as well. But did not come up with
> your solution. One question, though:
> >> for $installer.out.lines.map(*.encode('latin1').decode('utf16')) ->
> $line {
> Why .encode? I would assume the IO::Handle is allready given back latin-1
> because of the :enc<"latin-1"> in the Run command.
>
> On Thu, 13 Sep 2018 at 18:20, Brad Gilbert  wrote:
>
>> On Thu, Sep 13, 2018 at 7:22 AM WFB  wrote:
>> >
>> > Hi all,
>> >
>> > My perl6 runs an executable and prints its output. This output is
>> printed as multibyte string. I assume the executable gives back a multibyte
>> string and perl6 interpret its as one byte string for whatever reasons.
>> > I tried Run with different encodings like windows-1251, utf16 and so
>> on. No luck.
>> >
>> > The string I get looks like that:
>> > S e t t i n g   u p   f o l d e r   C : \ U s e r s \ w o l f
>> > Hex:
>> > 53 00 65 00 74 00 74 00 69 00 6E 00 67 00 20 00 75 00 70 00 20 00 66 00
>> 6F 00 6C 00 64 00 65 00 72 00 20 00 43 00 3A 00 5C 00 55 00 73 00 65 00
>> >
>> > Here my program:
>> >
>> > my $installer = run $install-file, :out;
>> > for $installer.out.lines -> $line {
>> > say $line;
>> > }
>> >
>> > Any idea whats wrong here. A WIndows issue or do I something wrong?
>> >
>>
>> Windows uses UTF16 encoding by default (which you see here), while
>> Perl 6 uses UTF8 by default.
>>
>> You should be able to fix it by setting the encoding
>> (Note that it should probably be set with :encoding, but that
>> doesn't work currently)
>>
>> run $install-file, :out, :enc
>>
>> Though I currently get an error from that.
>>
>> Streaming decode NYI for encoding 4
>>
>> Also I'm sure I should be able to set it after that line, but it also
>> produces an error
>>
>> > my $installer = run $install-file, :out;
>> > $installer.out.encoding('utf16');
>> Cannot assign to an immutable value
>>
>> ---
>>
>> A work around is to use 'latin1' (almost binary) and use `.encode.decode`
>>
>> my $installer = run $install-file, :out, :enc;
>> for $installer.out.lines.map(*.encode('latin1').decode('utf16')) ->
>> $line {
>> say $line;
>> }
>>
>


Re: Multibyte string in Windows command line

2018-09-13 Thread WFB
@Andreas Thanks, I was thinking to do that with regex by myself, but that
would be a ugly workaround and only as a last resort.

@Brad: Cool, thanks, I got the errors as well. But did not come up with
your solution. One question, though:
>> for $installer.out.lines.map(*.encode('latin1').decode('utf16')) ->
$line {
Why .encode? I would assume the IO::Handle is allready given back latin-1
because of the :enc<"latin-1"> in the Run command.

On Thu, 13 Sep 2018 at 18:20, Brad Gilbert  wrote:

> On Thu, Sep 13, 2018 at 7:22 AM WFB  wrote:
> >
> > Hi all,
> >
> > My perl6 runs an executable and prints its output. This output is
> printed as multibyte string. I assume the executable gives back a multibyte
> string and perl6 interpret its as one byte string for whatever reasons.
> > I tried Run with different encodings like windows-1251, utf16 and so on.
> No luck.
> >
> > The string I get looks like that:
> > S e t t i n g   u p   f o l d e r   C : \ U s e r s \ w o l f
> > Hex:
> > 53 00 65 00 74 00 74 00 69 00 6E 00 67 00 20 00 75 00 70 00 20 00 66 00
> 6F 00 6C 00 64 00 65 00 72 00 20 00 43 00 3A 00 5C 00 55 00 73 00 65 00
> >
> > Here my program:
> >
> > my $installer = run $install-file, :out;
> > for $installer.out.lines -> $line {
> > say $line;
> > }
> >
> > Any idea whats wrong here. A WIndows issue or do I something wrong?
> >
>
> Windows uses UTF16 encoding by default (which you see here), while
> Perl 6 uses UTF8 by default.
>
> You should be able to fix it by setting the encoding
> (Note that it should probably be set with :encoding, but that
> doesn't work currently)
>
> run $install-file, :out, :enc
>
> Though I currently get an error from that.
>
> Streaming decode NYI for encoding 4
>
> Also I'm sure I should be able to set it after that line, but it also
> produces an error
>
> > my $installer = run $install-file, :out;
> > $installer.out.encoding('utf16');
> Cannot assign to an immutable value
>
> ---
>
> A work around is to use 'latin1' (almost binary) and use `.encode.decode`
>
> my $installer = run $install-file, :out, :enc;
> for $installer.out.lines.map(*.encode('latin1').decode('utf16')) ->
> $line {
> say $line;
> }
>


Re: Multibyte string in Windows command line

2018-09-13 Thread WFB
Thanks!

Has nothing to do with perl6. Unfortunately, I have no idea how I can "fix"
that.
At least I can Windows blame again ^^

Best,
Wolfgang

On Thu, 13 Sep 2018 at 15:21, 
wrote:

>   Hi Wolfgang,
>
>   that is an Windows issue. You can see that if you pipe the output of
>   your program in a textfile (from within the command interpreter:
> cmd.exe):
>
>   c:\> install.exe > x.txt
>
>   and the 'hex' your x.txt..
>
>   A.
>
>
> On 13.09.18 14:21, WFB wrote:
> > Hi all,
> >
> > My perl6 runs an executable and prints its output. This output is printed
> > as multibyte string. I assume the executable gives back a multibyte
> string
> > and perl6 interpret its as one byte string for whatever reasons.
> > I tried Run with different encodings like windows-1251, utf16 and so on.
> No
> > luck.
> >
> > The string I get looks like that:
> > S e t t i n g   u p   f o l d e r   C : \ U s e r s \ w o l f
> > Hex:
> > 53 00 65 00 74 00 74 00 69 00 6E 00 67 00 20 00 75 00 70 00 20 00 66 00
> 6F
> > 00 6C 00 64 00 65 00 72 00 20 00 43 00 3A 00 5C 00 55 00 73 00 65 00
> >
> > Here my program:
> >
> > my $installer = run $install-file, :out;
> > for $installer.out.lines -> $line {
> > say $line;
> > }
> >
> > Any idea whats wrong here. A WIndows issue or do I something wrong?
> >
> > Thanks for helping,
> > Wolfgang
>
> --
> Andreas Müller - Raum: 35/114b - Tel: 2875
>


Multibyte string in Windows command line

2018-09-13 Thread WFB
Hi all,

My perl6 runs an executable and prints its output. This output is printed
as multibyte string. I assume the executable gives back a multibyte string
and perl6 interpret its as one byte string for whatever reasons.
I tried Run with different encodings like windows-1251, utf16 and so on. No
luck.

The string I get looks like that:
S e t t i n g   u p   f o l d e r   C : \ U s e r s \ w o l f
Hex:
53 00 65 00 74 00 74 00 69 00 6E 00 67 00 20 00 75 00 70 00 20 00 66 00 6F
00 6C 00 64 00 65 00 72 00 20 00 43 00 3A 00 5C 00 55 00 73 00 65 00

Here my program:

my $installer = run $install-file, :out;
for $installer.out.lines -> $line {
say $line;
}

Any idea whats wrong here. A WIndows issue or do I something wrong?

Thanks for helping,
Wolfgang


Re: ctxlexpad needs an MVMContect

2017-08-04 Thread WFB
Well spotted. I totally muss that.
However, that was not the only mistakes I did.
Another problem is to use #  commentaries in grammars. Which causes also
the exception.

Thanks for the help!

On 4 August 2017 at 08:22, yary  wrote:

> Is this line intentional?
>
> token trid {  }
>
>
> it looks like you've defined trid as itself.
>
> And here-
>
> TestCases.parse($line);
> TestSuiteParameters($line);
>
>
> You're calling the parse method for TestCases, but not for
> TestSuiteParameters- for that you're calling a constructor (I think)
>


ctxlexpad needs an MVMContect

2017-08-03 Thread WFB
Hi all,

I am writing a script to compare to text file. More precisely, certain data
is compared not line by line.
To find this information I use grammars.
At the beginning it worked great. But then, my script hangs. Started with
the debugger perl6-debug-m  I got this exception:
Unhandled exception: ctxlexpad needs an MVMContext
   at SETTING::src/core/PseudoStash.pm:48
(C:\rakudo/share/perl6/runtime/CORE.setting.moarvm:)
 from SETTING::src/core/PseudoStash.pm:156
(C:\rakudo/share/perl6/runtime/CORE.setting.moarvm:AT-KEY)
 from SETTING::src/core/hash_slice.pm:6
(C:\rakudo/share/perl6/runtime/CORE.setting.moarvm:postcircumfix:<{ }>)
 from site#sources\3E687CA5BFB386524F923BAC2F986CC3C66BD24F
(Debugger::UI::CommandLine):736  (C:\rakudo\share\perl6\site
\precomp\531476C94944C40F030060AEB60539343668769B.1500922671.09494\3E\3E687CA5BFB386524F923BAC2F986CC3C66BD24F:)
 from site#sources\3E687CA5BFB386524F923BAC2F986CC3C66BD24F
(Debugger::UI::CommandLine):730  (C:\rakudo\share\perl6\site
\precomp\531476C94944C40F030060AEB60539343668769B.1500922671.09494\3E\3E687CA5BFB386524F923BAC2F986CC3C66BD24F:unhandled
)
 from site#sources\3E687CA5BFB386524F923BAC2F986CC3C66BD24F
(Debugger::UI::CommandLine):721  (C:\rakudo\share\perl6\site
\precomp\531476C94944C40F030060AEB60539343668769B.1500922671.09494\3E\3E687CA5BFB386524F923BAC2F986CC3C66BD24F:)
 from gen/moar/Metamodel.nqp:4031
(C:\rakudo\share\nqp\lib/Perl6/Metamodel.moarvm:enter)
 from SETTING::src/core/Routine.pm:85
(C:\rakudo/share/perl6/runtime/CORE.setting.moarvm:CALL-ME)
 from gen/moar/BOOTSTRAP.nqp:3001
(C:\rakudo/share/nqp/lib/Perl6/BOOTSTRAP.moarvm:)
 from gen\moar\stage2\NQPHLL.nqp:1740
(C:\rakudo\share\nqp\lib/NQPHLL.moarvm:command_eval)
 from src/Perl6/Compiler.nqp:42
(C:\rakudo\share\nqp\lib/Perl6/Compiler.moarvm:command_eval)
 from gen\moar\stage2\NQPHLL.nqp:1677
(C:\rakudo\share\nqp\lib/NQPHLL.moarvm:command_line)
 from gen/moar/perl6-debug.nqp:509
(C:\rakudo\share\perl6\runtime\perl6-debug.moarvm:MAIN)
 from gen/moar/perl6-debug.nqp:439
(C:\rakudo\share\perl6\runtime\perl6-debug.moarvm:)
 from :1  (C:\rakudo\share\perl6\runtime\perl6-debug.moarvm:)
 from :1
(C:\rakudo\share\perl6\runtime\perl6-debug.moarvm:)

I tried to find the reason for that. I think it has something to do with
the grammar, but I do not know what could be the problem:

use v6;

grammar Base {
token nodash { <-[-]>* }# everything from begining to the first -.
token dash { '-' }  # the - itself.
token id { '{' <[A..Z 0..9 -]>+ '}' }   # a string starting with {
containing A-Z, 0-9 and - and ending with }.
}

grammar TestCases  {
# test case looks like this:
# 09:13:52: DEBUG (FetchTestRunDataSQL:895) -
{CC3CF1E4-ED49-4885-A327-1B506FFC18A6}
{01D2E4A7-5B6D-4968-82FA-0089838940AD} VMware: Stop All Running VM Images
token TOP {   \s+  \s+   }
token nodash { <-[-]>* }# everything from begining to the first -.
token dash { '-' }  # the - itself.
token id { '{' <[A..Z 0..9 -]>+ '}' }   # a string starting with {
containing A-Z, 0-9 and - and ending with }.
token tcid {  } # the first id. In this case the test case
id.
token tsid {  } # the second id. In this case the test
suite id.
token noparam { <-[$ @]>+ } # everything except $ or @.
}

grammar TestSuiteParameters   {
# Testmemberid TestRunID SearchPattern Replacement
#09:13:53: DEBUG (FetchTestRunDataSQL:173) -
{21E6F3A8-B8FD-42E0-9464-D91BDBD8A3EA}
{C9416326-27F6-41C7-847A-5669694389F0}$SNAPSHOTNAME$$VMSNAPSHOTNAME$
token TOP {   \s+  \s+  \s+ 
\s+  }
token nodash { <-[-]>* }# everything from begining to the first -.
token dash { '-' }  # the - itself.
token id { '{' <[A..Z 0..9 -]>+ '}' }   # a string starting with {
containing A-Z, 0-9 and - and ending with }.
token tmid {  }
token trid {  }
token searchpattern { <[$]> \w <[$]> }
token replacement { .* }
}

my $line = '09:13:52: DEBUG (FetchTestRunDataSQL:895) -
{CC3CF1E4-ED49-4885-A327-1B506FFC18A6}
{01D2E4A7-5B6D-4968-82FA-0089838940AD} VMware: Stop All Running VM Images';

TestCases.parse($line);
TestSuiteParameters($line);

I am working on Windows 10 with perl6:
This is Rakudo version 2017.07 built on MoarVM version 2017.07
implementing Perl 6.c.

Could someone tell me, whether I am the problem here or did I find a bug?

Thanks in advanced,
Wolf