Re: ps?

2020-11-22 Thread Peter Pentchev
On Sat, Nov 14, 2020 at 03:29:13PM -0800, ToddAndMargo via perl6-users wrote:
> On 2020-11-13 18:26, Curt Tilmes wrote:
> > On Fri, Nov 13, 2020 at 9:03 PM ToddAndMargo via perl6-users
> >  wrote:
> > > Fedora 33
> > > 
> > > I know I can get this information from a system
> > > call to "ps", but is there a way to tell if a
> > > program in running from Raku?
> > 
> > Running ps is probably as good as anything, but in linux you could
> > always just poke around under /proc,
> > e.g. Loop over /proc/*/cmdline and look for it.
> > 
> 
> Follow up:
> 
>$PsStr = qqx ( ps ax );
>if $PsStr.contains( "gnucash" )  {
>   PrintGreen( "GnuCash is running\n\n" );
>} else {
>   # qqx ( gnucash );
>   my $pA = Proc::Async.new( "/usr/bin/gnucash" );
>   $pA.start;
>   PrintGreen( "GnuCash started\n\n" );
>}

If the reason you want to run ps is to check whether a specific program
is running, I would very strongly suggest using the pgrep utility and
checking its exit code. There are many advantages to using pgrep over
trying to parse the output of ps, except for the case when you invoke ps
with a very, very specific set of options and columns, but... that's
pretty much equivalent to running pgrep anyway ;)

G'luck,
Peter

-- 
Peter Pentchev  r...@ringlet.net r...@debian.org p...@storpool.com
PGP key:http://people.FreeBSD.org/~roam/roam.key.asc
Key fingerprint 2EE7 A7A5 17FC 124C F115  C354 651E EFB0 2527 DF13


signature.asc
Description: PGP signature


Re: I need help finding a class for a method

2020-06-08 Thread Peter Pentchev
On Mon, Jun 08, 2020 at 04:01:41PM -0700, ToddAndMargo via perl6-users wrote:
> On 2020-06-08 15:35, Peter Pentchev wrote:
> > On Mon, Jun 08, 2020 at 03:15:36PM -0700, ToddAndMargo via perl6-users 
> > wrote:
> > > On 2020-06-08 15:02, Peter Pentchev wrote:
> > > > On Mon, Jun 08, 2020 at 02:57:58PM -0700, ToddAndMargo via perl6-users 
> > > > wrote:
> > > > > On 2020-06-08 14:54, Peter Pentchev wrote:
> > > > > > On Mon, Jun 08, 2020 at 02:48:48PM -0700, ToddAndMargo via 
> > > > > > perl6-users wrote:
> > > > > > > On 2020-06-08 13:55, Richard Hainsworth wrote:
> > > > > > [snip]
> > > > > > > > The opening bracket for class Informing is on (or about) line 
> > > > > > > > 10 and the
> > > > > > > > closing in at about line 630, with a comment 'end of Informing 
> > > > > > > > class'
> > > > > > > > 
> > > > > > > > Richard
> > > > > > > 
> > > > > > > Hi Richard,
> > > > > > > 
> > > > > > > Ah Ha!  and 626's bracket is not blue.  Geany
> > > > > > > does that some times.
> > > > > > > 
> > > > > > > 
> > > > > > > 9:  class Informing {
> > > > > > > 626:} # end of Informing class
> > > > > > > 
> > > > > > > Okay now.  I missed this because of line 8:
> > > > > > > 
> > > > > > > 8: =comment code for the inform dialog box
> > > > > > > 9:   class Informing {
> > > > > > >has $!app;
> > > > > > >has Bool $!reinit = True;
> > > > > > >has $!inf-lable;
> > > > > > >has $!box;
> > > > > > >has $!btn-box;
> > > > > > >has $!deleted_supply;
> > > > > > >has $!title;
> > > > > > >has $!position;
> > > > > > >has $!timer-lable;
> > > > > > >has @!buttons;
> > > > > > >has @!entries;
> > > > > > >has %.data = {};
> > > > > > >has $.response;
> > > > > > >has Supply $!sup = self.g-timeout(1000);
> > > > > > >has Tap $!tap;
> > > > > > >has Int $!timer = 10;
> > > > > > >has Bool $!show-countdown = True;
> > > > > > > 27: has Str $.text is rw = "Say  > > > > > > color=\"green\">something > > > > > > color=\"red\">
> > > > > > > beautiful";
> > > > > > > 28: 
> > > > > > > 
> > > > > > > Everything from line 8 to line 27 is a "comment".  The
> > > > > > > comment does not terminate until the first blank line,
> > > > > > > which is 28.
> > > > > > > 
> > > > > > > Seems to me the comment rules are being violated here.
> > > > > > > The comment does not terminate until the first blank
> > > > > > > line.
> > > > > > > 
> > > > > > > What am I missing, again.
> > > > > > > 
> > > > > > > :'(
> > > > > > 
> > > > > > OK, that is weird. I do not know why your editor is showing you 
> > > > > > that.
> > > > > > https://github.com/finanalyst/p6-inform/blob/master/lib/Informative.pm6
> > > > > > says that the "=comment" line is line 8, then there is a blank line 
> > > > > > 9,
> > > > > > and then there is a "class Informing {" on line 10.
> > > > > > 
> > > > > > G'luck,
> > > > > > Peter
> > > > > 
> > > > > 
> > > > > Poop!!!  (Not my actual word and not an admission that
> > > > > I cuss.)
> > > > > 
> > > > > Richard has a new one out, so I am going to get the new
> > > > > one ASAP
> > > > > 
> > > > > Thank you.  I though I was going nuts.
> > > > 
&g

Re: I need help finding a class for a method

2020-06-08 Thread Peter Pentchev
On Mon, Jun 08, 2020 at 03:15:36PM -0700, ToddAndMargo via perl6-users wrote:
> On 2020-06-08 15:02, Peter Pentchev wrote:
> > On Mon, Jun 08, 2020 at 02:57:58PM -0700, ToddAndMargo via perl6-users 
> > wrote:
> > > On 2020-06-08 14:54, Peter Pentchev wrote:
> > > > On Mon, Jun 08, 2020 at 02:48:48PM -0700, ToddAndMargo via perl6-users 
> > > > wrote:
> > > > > On 2020-06-08 13:55, Richard Hainsworth wrote:
> > > > [snip]
> > > > > > The opening bracket for class Informing is on (or about) line 10 
> > > > > > and the
> > > > > > closing in at about line 630, with a comment 'end of Informing 
> > > > > > class'
> > > > > > 
> > > > > > Richard
> > > > > 
> > > > > Hi Richard,
> > > > > 
> > > > > Ah Ha!  and 626's bracket is not blue.  Geany
> > > > > does that some times.
> > > > > 
> > > > > 
> > > > > 9:  class Informing {
> > > > > 626:} # end of Informing class
> > > > > 
> > > > > Okay now.  I missed this because of line 8:
> > > > > 
> > > > > 8: =comment code for the inform dialog box
> > > > > 9:   class Informing {
> > > > >   has $!app;
> > > > >   has Bool $!reinit = True;
> > > > >   has $!inf-lable;
> > > > >   has $!box;
> > > > >   has $!btn-box;
> > > > >   has $!deleted_supply;
> > > > >   has $!title;
> > > > >   has $!position;
> > > > >   has $!timer-lable;
> > > > >   has @!buttons;
> > > > >   has @!entries;
> > > > >   has %.data = {};
> > > > >   has $.response;
> > > > >   has Supply $!sup = self.g-timeout(1000);
> > > > >   has Tap $!tap;
> > > > >   has Int $!timer = 10;
> > > > >   has Bool $!show-countdown = True;
> > > > > 27: has Str $.text is rw = "Say  > > > > color=\"green\">something
> > > > > beautiful";
> > > > > 28: 
> > > > > 
> > > > > Everything from line 8 to line 27 is a "comment".  The
> > > > > comment does not terminate until the first blank line,
> > > > > which is 28.
> > > > > 
> > > > > Seems to me the comment rules are being violated here.
> > > > > The comment does not terminate until the first blank
> > > > > line.
> > > > > 
> > > > > What am I missing, again.
> > > > > 
> > > > > :'(
> > > > 
> > > > OK, that is weird. I do not know why your editor is showing you that.
> > > > https://github.com/finanalyst/p6-inform/blob/master/lib/Informative.pm6
> > > > says that the "=comment" line is line 8, then there is a blank line 9,
> > > > and then there is a "class Informing {" on line 10.
> > > > 
> > > > G'luck,
> > > > Peter
> > > 
> > > 
> > > Poop!!!  (Not my actual word and not an admission that
> > > I cuss.)
> > > 
> > > Richard has a new one out, so I am going to get the new
> > > one ASAP
> > > 
> > > Thank you.  I though I was going nuts.
> > 
> > Eh, well...
> > https://github.com/finanalyst/p6-inform/blame/master/lib/Informative.pm6
> > ...says that this blank line has been there for the past four years,
> > actually longer than both the comment line above it and the current
> > state of the class line below it :)
> 
> Eye balling it shows it clearly there.
> 
> 
> > I'd start to wonder if it is possible that you deleted that line by
> > mistake. I *know* I've done that. I know I did it this week, and it's
> > only Monday :)
> 
> Not a chance the third or forth time at it.  It is a
> clipboard issue.  The secondary clipboard is a little
> weird in Fedora 32.
> 
> Hmm, I wonder about the primary clipboard.  No, screwed
> up in the primary clipboard too.

Wait. So you're copying and pasting the code?

I'd say do something like "dnf install git" and then

  git clone https://github.com/finanalyst/p6-inform.git

That way you'll get a p6-inform directory that will contain exactly what
Richard uploaded to his GitHub repository.

And if you need to later copy the code to your own file, either use
the "cp" command to start a whole new file, the same as another one in
the beginning, and then edit it to your liking, or use your editor to
copy certain lines to another file.

G'luck,
Peter

-- 
Peter Pentchev  r...@ringlet.net r...@debian.org p...@storpool.com
PGP key:http://people.FreeBSD.org/~roam/roam.key.asc
Key fingerprint 2EE7 A7A5 17FC 124C F115  C354 651E EFB0 2527 DF13


signature.asc
Description: PGP signature


Re: I need help finding a class for a method

2020-06-08 Thread Peter Pentchev
On Mon, Jun 08, 2020 at 02:57:58PM -0700, ToddAndMargo via perl6-users wrote:
> On 2020-06-08 14:54, Peter Pentchev wrote:
> > On Mon, Jun 08, 2020 at 02:48:48PM -0700, ToddAndMargo via perl6-users 
> > wrote:
> > > On 2020-06-08 13:55, Richard Hainsworth wrote:
> > [snip]
> > > > The opening bracket for class Informing is on (or about) line 10 and the
> > > > closing in at about line 630, with a comment 'end of Informing class'
> > > > 
> > > > Richard
> > > 
> > > Hi Richard,
> > > 
> > > Ah Ha!  and 626's bracket is not blue.  Geany
> > > does that some times.
> > > 
> > > 
> > > 9:  class Informing {
> > > 626:} # end of Informing class
> > > 
> > > Okay now.  I missed this because of line 8:
> > > 
> > > 8: =comment code for the inform dialog box
> > > 9:   class Informing {
> > >  has $!app;
> > >  has Bool $!reinit = True;
> > >  has $!inf-lable;
> > >  has $!box;
> > >  has $!btn-box;
> > >  has $!deleted_supply;
> > >  has $!title;
> > >  has $!position;
> > >  has $!timer-lable;
> > >  has @!buttons;
> > >  has @!entries;
> > >  has %.data = {};
> > >  has $.response;
> > >  has Supply $!sup = self.g-timeout(1000);
> > >  has Tap $!tap;
> > >  has Int $!timer = 10;
> > >  has Bool $!show-countdown = True;
> > > 27: has Str $.text is rw = "Say  > > color=\"green\">something
> > > beautiful";
> > > 28: 
> > > 
> > > Everything from line 8 to line 27 is a "comment".  The
> > > comment does not terminate until the first blank line,
> > > which is 28.
> > > 
> > > Seems to me the comment rules are being violated here.
> > > The comment does not terminate until the first blank
> > > line.
> > > 
> > > What am I missing, again.
> > > 
> > > :'(
> > 
> > OK, that is weird. I do not know why your editor is showing you that.
> > https://github.com/finanalyst/p6-inform/blob/master/lib/Informative.pm6
> > says that the "=comment" line is line 8, then there is a blank line 9,
> > and then there is a "class Informing {" on line 10.
> > 
> > G'luck,
> > Peter
> 
> 
> Poop!!!  (Not my actual word and not an admission that
> I cuss.)
> 
> Richard has a new one out, so I am going to get the new
> one ASAP
> 
> Thank you.  I though I was going nuts.

Eh, well...
https://github.com/finanalyst/p6-inform/blame/master/lib/Informative.pm6
...says that this blank line has been there for the past four years,
actually longer than both the comment line above it and the current
state of the class line below it :)

I'd start to wonder if it is possible that you deleted that line by
mistake. I *know* I've done that. I know I did it this week, and it's
only Monday :)

G'luck,
Peter

-- 
Peter Pentchev  r...@ringlet.net r...@debian.org p...@storpool.com
PGP key:http://people.FreeBSD.org/~roam/roam.key.asc
Key fingerprint 2EE7 A7A5 17FC 124C F115  C354 651E EFB0 2527 DF13


signature.asc
Description: PGP signature


Re: I need help finding a class for a method

2020-06-08 Thread Peter Pentchev
On Mon, Jun 08, 2020 at 02:48:48PM -0700, ToddAndMargo via perl6-users wrote:
> On 2020-06-08 13:55, Richard Hainsworth wrote:
[snip]
> > The opening bracket for class Informing is on (or about) line 10 and the
> > closing in at about line 630, with a comment 'end of Informing class'
> > 
> > Richard
> 
> Hi Richard,
> 
> Ah Ha!  and 626's bracket is not blue.  Geany
> does that some times.
> 
> 
> 9:  class Informing {
> 626:} # end of Informing class
> 
> Okay now.  I missed this because of line 8:
> 
> 8: =comment code for the inform dialog box
> 9:   class Informing {
> has $!app;
> has Bool $!reinit = True;
> has $!inf-lable;
> has $!box;
> has $!btn-box;
> has $!deleted_supply;
> has $!title;
> has $!position;
> has $!timer-lable;
> has @!buttons;
> has @!entries;
> has %.data = {};
> has $.response;
> has Supply $!sup = self.g-timeout(1000);
> has Tap $!tap;
> has Int $!timer = 10;
> has Bool $!show-countdown = True;
> 27: has Str $.text is rw = "Say  color=\"green\">something
> beautiful";
> 28: 
> 
> Everything from line 8 to line 27 is a "comment".  The
> comment does not terminate until the first blank line,
> which is 28.
> 
> Seems to me the comment rules are being violated here.
> The comment does not terminate until the first blank
> line.
> 
> What am I missing, again.
> 
> :'(

OK, that is weird. I do not know why your editor is showing you that.
https://github.com/finanalyst/p6-inform/blob/master/lib/Informative.pm6
says that the "=comment" line is line 8, then there is a blank line 9,
and then there is a "class Informing {" on line 10.

G'luck,
Peter

-- 
Peter Pentchev  r...@ringlet.net r...@debian.org p...@storpool.com
PGP key:http://people.FreeBSD.org/~roam/roam.key.asc
Key fingerprint 2EE7 A7A5 17FC 124C F115  C354 651E EFB0 2527 DF13


signature.asc
Description: PGP signature


Re: question about the multi in method

2020-06-08 Thread Peter Pentchev
On Mon, Jun 08, 2020 at 02:39:10PM -0700, ToddAndMargo via perl6-users wrote:
> On 2020-06-08 14:12, Peter Pentchev wrote:
> > On Mon, Jun 08, 2020 at 01:28:34PM -0700, ToddAndMargo via perl6-users 
> > wrote:
> > > On 2020-06-08 02:45, Richard Hainsworth wrote:
> > > > Ok Todd, let me have a go at this issue.
> > > > 
> > > >   From what I understand, you see 'multi' and think 'there are more than
> > > > one', which leads to the question 'where are they?'
> > > > 
> > > > My understanding of 'multi' is 'there COULD be more than one', which
> > > > leads to the question 'are there any?'
> > > > 
> > > > This is actually a very powerful aspect of Raku.
> > > > 
> > > > There are (as has been stated in this thread) four types of which  multi
> > > > = 'could be more than one' and only = 'only one' .
> > > > 
> > > > If the developer wrote 'only sub' then, no one else could write a sub
> > > > with that name. For a developer of a program or a module, that might be
> > > > OK, because it's unlikely anyone else would need/want to use that name.
> > > > But for a compiler, the probability is reversed. Someone will want to
> > > > use it. That is why in many other languages there are 'reserved words'
> > > > which you are not allowed to use.
> > > > 
> > > > In Raku, if you develop a new type, for example say a quodion, and you
> > > > want to 'add' quodions, then you CAN use + because it can be overloaded.
> > > > It is defined as a multi.
> > > > 
> > > > Or in your most overused example 'needle' can be rewritten to take a
> > > > quodion, which may yield a spectrum of results because that's what
> > > > quodions are for.
> > > > 
> > > > Since needle is defined as a 'multi', if you write a 'needle' method for
> > > > quodions, the needle for strings STILL exists, and Raku will correctly
> > > > call the method you wrote for quodions if a quodion is implied, but call
> > > > the default needle if a string (or any other type) is used.
> > > > 
> > > > Since you have developed the quodion method entirely for your paid
> > > > subscribers, the module is NOT available to the public, so you wont tell
> > > > anyone about it. So it doesn't have to be in the documentation.
> > > > 
> > > > Is this making any sense to you?
> > > > 
> > > > Richard
> > > 
> > > 
> > > Hi Richard,
> > > 
> > > You are perfectly clear and beautifully well written.
> > > You did make me look up "quodion".
> > > 
> > > :-)
> > > 
> > > And I am feeling guilty because I did already know all
> > > this and it looks like you spent a considerable amount of
> > > time getting into my head to formulate an answer that
> > > was perfect for me.
> > > 
> > > Here is the thing.  I have no objecting to the developer
> > > calling something a "multi" or an "only" depending on his
> > > needs.  That is entirely "HIS" call, "NOT" mine.
> > > 
> > > And I hope the above statement ends all the well meaning,
> > > helpful folks who are trying the re-explain the concept
> > > to me.  I got it a LONG time ago.
> > > 
> > > My objection is when there actually exists more than
> > > one and they are not experimental or otherwise hidden
> > > for some reason and are truly, actually part of the
> > > distribution, then they also should be documented.
> > > Updates to the documentation should be part of
> > > the code check in process, and in all probability, are.
> > > 
> > > So, basically what I am saying is when multiples are
> > > there and are open to the public, than it should be
> > > documented.  In this situation, why would the
> > > developer want his hard work hidden?
> > 
> > OK, let me try to give you another example. If I'm too long-winded,
> > there will be an abstract at the end :)
> > 
> > Say somebody is writing a library that should serve as the standard
> > library for the C language. Now, there is a published, adopted standard
> > for the C language that all C compilers and C standard libraries
> > follow[1].
> > 
> > Now, the C language standard says that there may be more than one
> > library - one called "libc" as "the 

Re: question about the multi in method

2020-06-08 Thread Peter Pentchev
hey make it internal to the "libc" library, so your programs
can't see it. Right? Everything's fine, there is an internal function
that nobody can access.

So the next thing they do is turn to the maths library, and they realize
that they have to write a trunc() function, and the lightbulb comes on:
they have *already written* a function that rounds a real number down,
but for various reasons that *only matter to the author of the library*,
not to the users of the library, that function needs to live in the
"libc" library, not in the "libm" library.

OK, but they do not want to do the work twice, they do not want to have
the same code in both libraries, do they? So they want to make the
trunc() function in the maths library call the printf_trunc() function
in the standard C library. But... but that means... that means that
printf_trunc() may no longer be internal - it *must* be exposed, at least
to the maths library, and the way the C language works[3], this means
that *any* program that uses the standard C library can now see
the printf_trunc() function. That means that anybody who takes the time
to look at the source of the library can figure out that there is such
a function and, if they feel adventurous, they may actually call it in
their own program.

But! and this is the important point. THEY DO NOT WANT TO.

The author of a program - not the author of the library! - but the
author of a program that uses that library, that is you, that is me,
this author *does not want* to call a function that is not defined in
the C standard. This author - you and me - can guess that this function
is probably an internal one used by some of the other libraries
developed along with the standard C library. But they don't need to
guess: they KNOW, from reading the documentation, that this function is
NOT part of the specification of the C language. Moreover, they KNOW, by
reading the documentation of the "libc" library, that this function is
NOT listed there.

So, even though you and I can see the printf_trunc() function, we never
want to call it.

There is a very important reason for that: it is a function that is
written solely for the needs of the maths library, and if tomorrow the
next version of the maths library needs this function to operate in
another way, maybe add another argument, maybe drop an argument because
something is handled elsewhere, the C library's printf_trunc() function
*will change*. And if you or I had used it in our programs, our programs
would break.

Then, if we go to the author of the library and complain about using the
printf_trunc() function that is not in the specification of the C
language and that is not listed in the documentation of the "libc"
library... the author would say, and I quote, "Huh?!" They would say,
"Wait... *why* are you using this function? How do you know about... no,
wait, nevermind how you know about it... *why* are you using a function
that is neither part of the language specification, nor listed in the
documentation of this implementation of the language?"

So, you see, the hard work of the author of the library is not hidden.
It is there for us to see in the printf() function from "libc" and in
the trunc() function from "libm". Every time we use one of these
well-known and well-documented functions, we make use of the hard work
of the author. We do not need to call the internal function to do that.

So, to recap:
- there are two libraries, "libc" and "libm"
- "libc" has a function that wants to round numbers down
- "libm" must have a function that wants to round numbers down
- the common function to be used by both libraries has to be placed in
  "libc", but it needs to be visible so that "libm" can use it
- somebody curious enough can look into the sources of "libc" and see
  this function
- but this somebody must realize that this is an internal, undocumented
  function that serves some purpose for the combination of "libc" and
  "libm" and that is *not* supposed to be used by anything outside these
  two libraries
- so this somebody will shrug it off, say "hey, there's some kind of
  implementation detail, there's some kind of internal function, okay,
  forget about it"

Hope that helps!

G'luck,
Peter

[1] ...and to everyone who cringed at that statement... sorry! :)
Let's go with that for now and push the pain away :)

[2] ...and to everyone who cringed at *that* statement... sorry! :)

[3] ...let's go with "the C language" here, not get into details about
compilers and linkers and foreign functions and stuff

-- 
Peter Pentchev  r...@ringlet.net r...@debian.org p...@storpool.com
PGP key:http://people.FreeBSD.org/~roam/roam.key.asc
Key fingerprint 2EE7 A7A5 17FC 124C F115  C354 651E EFB0 2527 DF13


signature.asc
Description: PGP signature


Re: question about the multi in method

2020-06-08 Thread Peter Pentchev
On Mon, Jun 08, 2020 at 10:45:21AM +0100, Richard Hainsworth wrote:
> Ok Todd, let me have a go at this issue.

Thank you, Richard, for your help. I apologize to Todd and to everyone
on the list for my outburst in my last e-mail.

G'luck,
Peter

-- 
Peter Pentchev  r...@ringlet.net r...@debian.org p...@storpool.com
PGP key:http://people.FreeBSD.org/~roam/roam.key.asc
Key fingerprint 2EE7 A7A5 17FC 124C F115  C354 651E EFB0 2527 DF13


signature.asc
Description: PGP signature


Re: question about the multi in method

2020-06-08 Thread Peter Pentchev
On Mon, Jun 08, 2020 at 12:12:07AM -0700, ToddAndMargo via perl6-users wrote:
> On 2020-06-07 22:39, Peter Pentchev wrote:
> > I thought I explained that. The Rakudo developers are*never*  finished
> > with the development of some methods. Somebody*will*  want to extend
> > them in their own module. The Rakudo developers*want*  to declare some
> > methods as "multi" to allow the Rakudo users to write Raku programs that
> > extend some existing classes to make them do interesting things.
> 
> You did and I understood it.  Your explanation was well
> though out/
> 
> What you missed was my point that the developers have a
> process for checking in new code.  Part of that process
> is updating the documentation.  That is the proper
> time for documentation to be updated.  The purpose of
> the documentation is not to keep places open for unicorns.
> 
> Now you are absolutely correct that the software is NEVER finished.  But
> Raku is not a "daily" release to the public.
> They exist, but are not released to the general public.
> Raku has releases.  When the new release his, the
> documentation need to match the release.  It is
> all part of the check in process.

Nothing. Needs. To be. Updated.

For the last time. The methods are "multi" for two reasons:
- to allow other parts of Rakudo to use them *internally*
- to allow *module authors* and *application writers* like you and me
  to extend them in our own classes

Both of these are very valid reasons to declare some methods as "multi".

Nothing needs to change in the documentation.

> > What did you learn from going to Github? That you may call
> > .starts-with() without the :i or :m parameters? Was that not written in
> > the documentation? Or that you may call .starts-with() with a $needle
> > being Cool and not Str? Again, was that not written in the
> > documentation? So what did you learn from going to Github that was not
> > in the documentation?
> 
> Nothing I remember.  But that was not my point.

What is your point then? What *exactly* is lacking in the documetation
of the Str.starts-with() method, *and why*? Examples, please.
And no, *don't* say "the internal method without the :i and :m" without
explaining *why* you want it to be "documented".

G'luck,
Peter

-- 
Peter Pentchev  r...@ringlet.net r...@debian.org p...@storpool.com
PGP key:http://people.FreeBSD.org/~roam/roam.key.asc
Key fingerprint 2EE7 A7A5 17FC 124C F115  C354 651E EFB0 2527 DF13


signature.asc
Description: PGP signature


Re: question about the multi in method

2020-06-07 Thread Peter Pentchev
On Sun, Jun 07, 2020 at 07:07:29PM -0700, ToddAndMargo via perl6-users wrote:
> On 2020-06-07 14:20, Peter Pentchev wrote:
> > On Sun, Jun 07, 2020 at 12:28:33PM -0700, ToddAndMargo via perl6-users 
> > wrote:
> > > On 2020-06-07 08:19, Peter Pentchev wrote:
> > > > On Sun, Jun 07, 2020 at 09:04:45AM -0500, Brad Gilbert wrote:
> > > > > On Sun, Jun 7, 2020 at 3:15 AM ToddAndMargo via perl6-users <
> > > > > perl6-us...@perl.org> wrote:
> > > > > 
> > > > > > Hi All,
> > > > > > 
> > > > > > Dumb question:
> > > > > > 
> > > > > > Does the "multi" in "multi method" mean there
> > > > > > is more than one way to address a method?
> > > > > > 
> > > > > > Or, are the all methods "multi methods".
> > > > > > 
> > > > > > If not and the method is a multi, should not the
> > > > > > documentation show all (more than one) the ways of
> > > > > > addressing a multi method?
> > > > > 
> > > > > There are four different types of a function. (both method and sub)
> > > > > 
> > > > > - `multi`
> > > > > - `proto`
> > > > > - `only`
> > > > > - `anon`
> > > > > 
> > [snip]
> > > > 
> > > > Please note that I'm not criticizing the documentation,
> > > 
> > > That is all right.  I will take up that job.  I am
> > > about to zinger it pretty good.
> > > 
> > > > automatically
> > > > generated or not, or the efforts of everyone involved in producing it :)
> > > > I am under the impression that it is, at least to some extent,
> > > > automatically generated, so I'm genuinely curious what is it about
> > > > the .starts-with() method that has caused it to lose its Cool :)
> > > > 
> > > > ...and, of course, it may turn out that Todd meant something completely
> > > > different in this particular message and I hijacked the thread...
> > > > 
> > > > G'luck,
> > > > Peter
> > > > 
> > > 
> > > 
> > > Hi Peter,
> > > 
> > > Pretty close.
> > > 
> > > I do believe Brad answered the question.  There are
> > > multiple and only and some other types.
> > > 
> > > The reason why I ask is that I find the documentation
> > > frustrating.   Here is an example of a method I
> > > have NO trouble with and use all the time:
> > > 
> > > https://docs.raku.org/type/Mu#method_defined
> > > 
> > >Declared as
> > >   multi method defined(   --> Bool:D)
> > >Returns False on a type object, and True otherwise.
> > > 
> > > It shows one method, but clearly defines it as a
> > > "multi method".  If it is indeed a multiple,
> > > where are the other crypto lines?  Or is it a
> > > misprint and there is only one crypto line as
> > > it is indeed an "only".
> > > 
> > > So I asked, are they ALL multi's.  And the answer is "no".
> > > 
> > > Now when I opened a bug report on one of them:
> > > 
> > >   Where is the multi in starts-with?
> > >   https://github.com/Raku/doc/issues/3456
> > > 
> > > JJ closed the ticket with the following answer:
> > > 
> > >   Let me see how I explain this. It's a bit like
> > >   the American party primaries. Anyone can run,
> > >   right? Only in some cases (mainly when the incumbent
> > >   is there), nobody else bothers to. In this case, a
> > >   multi shows the possibility of declaring other
> > >   routines with the same name and different signature,
> > >   unlike only which says "Nope, you can't".
> > 
> > This is actually very, very common in object-oriented programming.
> > You create a new class, you have a couple of methods that you know will
> > be useful to others, so you declare them as multi in Raku or, say,
> > virtual in C++. Then you add a couple of other methods, and you stop and
> > think "hm, okay, so right now I don't have a need to use this method in
> > another way or override it in another class, but what it does is pretty
> > general, easily extensible, so, yeah, it is very much possible that
> > tomorrow I (

Re: question about the multi in method

2020-06-07 Thread Peter Pentchev
On Mon, Jun 08, 2020 at 12:20:03AM +0300, Peter Pentchev wrote:
> On Sun, Jun 07, 2020 at 12:28:33PM -0700, ToddAndMargo via perl6-users wrote:
> > On 2020-06-07 08:19, Peter Pentchev wrote:
> > > On Sun, Jun 07, 2020 at 09:04:45AM -0500, Brad Gilbert wrote:
> > > > On Sun, Jun 7, 2020 at 3:15 AM ToddAndMargo via perl6-users <
> > > > perl6-us...@perl.org> wrote:
> > > > 
> > > > > Hi All,
> > > > > 
> > > > > Dumb question:
> > > > > 
> > > > > Does the "multi" in "multi method" mean there
> > > > > is more than one way to address a method?
> > > > > 
> > > > > Or, are the all methods "multi methods".
> > > > > 
> > > > > If not and the method is a multi, should not the
> > > > > documentation show all (more than one) the ways of
> > > > > addressing a multi method?
> > > > 
> > > > There are four different types of a function. (both method and sub)
> > > > 
> > > > - `multi`
> > > > - `proto`
> > > > - `only`
> > > > - `anon`
> > > > 
> [snip]
> > > 
> > > Please note that I'm not criticizing the documentation,
> > 
> > That is all right.  I will take up that job.  I am
> > about to zinger it pretty good.
> > 
> > > automatically
> > > generated or not, or the efforts of everyone involved in producing it :)
> > > I am under the impression that it is, at least to some extent,
> > > automatically generated, so I'm genuinely curious what is it about
> > > the .starts-with() method that has caused it to lose its Cool :)
> > > 
> > > ...and, of course, it may turn out that Todd meant something completely
> > > different in this particular message and I hijacked the thread...
> > > 
> > > G'luck,
> > > Peter
> > > 
> > 
> > 
> > Hi Peter,
> > 
> > Pretty close.
> > 
> > I do believe Brad answered the question.  There are
> > multiple and only and some other types.
> > 
> > The reason why I ask is that I find the documentation
> > frustrating.   Here is an example of a method I
> > have NO trouble with and use all the time:
> > 
> > https://docs.raku.org/type/Mu#method_defined
> > 
> >   Declared as
> >  multi method defined(   --> Bool:D)
> >   Returns False on a type object, and True otherwise.
> > 
> > It shows one method, but clearly defines it as a
> > "multi method".  If it is indeed a multiple,
> > where are the other crypto lines?  Or is it a
> > misprint and there is only one crypto line as
> > it is indeed an "only".
> > 
> > So I asked, are they ALL multi's.  And the answer is "no".
> > 
> > Now when I opened a bug report on one of them:
> > 
> >  Where is the multi in starts-with?
> >  https://github.com/Raku/doc/issues/3456
> > 
> > JJ closed the ticket with the following answer:
> > 
> >  Let me see how I explain this. It's a bit like
> >  the American party primaries. Anyone can run,
> >  right? Only in some cases (mainly when the incumbent
> >  is there), nobody else bothers to. In this case, a
> >  multi shows the possibility of declaring other
> >  routines with the same name and different signature,
> >  unlike only which says "Nope, you can't".
> 
> This is actually very, very common in object-oriented programming.
> You create a new class, you have a couple of methods that you know will
> be useful to others, so you declare them as multi in Raku or, say,
> virtual in C++. Then you add a couple of other methods, and you stop and
> think "hm, okay, so right now I don't have a need to use this method in
> another way or override it in another class, but what it does is pretty
> general, easily extensible, so, yeah, it is very much possible that
> tomorrow I (or somebody else) will need to redefine or extend it" - and
> that's why you put a "multi" on a method that *right now* has no real
> use for it, but it will have one tomorrow.
> 
> I do not have an example in mind right now, but I bet that if I look
> through some of the modules found at https://modules.raku.org/ I can
> find classes that redefine or extend some really basic methods in
> Raku's base classes. This is only possible because the developers of
> Raku decided to declare them as "multi" even though t

Re: Is thre a way to do an "if" on "use lib"?

2020-06-07 Thread Peter Pentchev
On Sun, Jun 07, 2020 at 05:33:43PM -0400, Will Coleda wrote:
> On Sun, Jun 7, 2020 at 4:53 PM Peter Pentchev  wrote:
> >
> > On Sun, Jun 07, 2020 at 12:32:09PM -0700, ToddAndMargo via perl6-users 
> > wrote:
> > > On 2020-06-07 02:32, Peter Pentchev wrote:
> > >
> > > > BEGIN {
> > > > $path = 'lib1'.IO.d ?? 'lib1' !! 'lib2';
> > > > }
> > >
> > > Does the final "}" close the BEGIN?
> >
> > Well, there is an opening { after "BEGIN", so, yes.
> >
> > More precisely, it closes the block that is to be executed early.
> >
> > > > $path = 'lib1'.IO.d ?? 'lib1' !! 'lib2';
> > >
> > > Hi Peter,
> > >
> > > Would you explain what the ?? and !! are
> > > doing in the above?
> >
> > https://docs.raku.org/language/operators#infix_??_!!
> 
> the URL with literal !! in it didn't work for me, but this does:
> https://docs.raku.org/language/operators#infix_??_%21%21

Ah, but of course. Aren't Web standards and browsers great. I did copy
and paste it from the location bar, and I did not stop to think about
it, since I foolishly trusted that my browser would actually copy
a usable URL.

Thanks.

G'luck,
Peter

-- 
Peter Pentchev  r...@ringlet.net r...@debian.org p...@storpool.com
PGP key:http://people.FreeBSD.org/~roam/roam.key.asc
Key fingerprint 2EE7 A7A5 17FC 124C F115  C354 651E EFB0 2527 DF13


signature.asc
Description: PGP signature


Re: Is thre a way to do an "if" on "use lib"?

2020-06-07 Thread Peter Pentchev
On Mon, Jun 08, 2020 at 12:26:42AM +0300, Peter Pentchev wrote:
> On Mon, Jun 08, 2020 at 12:21:22AM +0300, Peter Pentchev wrote:
> > On Sun, Jun 07, 2020 at 01:57:11PM -0700, ToddAndMargo via perl6-users 
> > wrote:
> > > On 2020-06-07 13:53, Peter Pentchev wrote:
> > > > $path = 'lib1'.IO.d ?? 'lib1' !! 'lib2';
> > > 
> > > Got it!  Thank you!
> > > 
> > > I am not seeing the above enter the proper syntax:
> > > 
> > > 'lib1', 'lib2' etc.
> > > 
> > > Where is the comma?  How are the single quotes entered?
> > 
> > I don't understand what you are asking. The above checks whether
> > a directory exists and, depending on the result of this check, assigns
> > one of two values to a variable. I don't know what comma you are talking
> > about.
> 
> Wait, I think I got it. You're asking about the line underneath, the one
> that you did not quote in this message, the line that says:
> 
>   use lib $path;
> 
> "use lib" expects you to pass a string (or more strings). 'c:/NtUtil' is
> a string.  $path is a variable that holds a string. "use lib $path"
> calls "use lib" and passes to it the string in the variable $path.

So to be a bit more clear, in your case you have a path that you always
need to pass ('c:/something') and another one that you want to pass only
if it exists. OK, so maybe something like:

my @path;

BEGIN { 
for ('K:/NtUtil', 'X:/NtUtil') -> $candidate {
    push @path, $candidate if $candidate.IO.d;
}
push @path, 'C:/NtUtil';
}   

use lib @path;

Maybe something like that will work for you.

G'luck,
Peter

-- 
Peter Pentchev  r...@ringlet.net r...@debian.org p...@storpool.com
PGP key:http://people.FreeBSD.org/~roam/roam.key.asc
Key fingerprint 2EE7 A7A5 17FC 124C F115  C354 651E EFB0 2527 DF13


signature.asc
Description: PGP signature


Re: Is thre a way to do an "if" on "use lib"?

2020-06-07 Thread Peter Pentchev
On Mon, Jun 08, 2020 at 12:21:22AM +0300, Peter Pentchev wrote:
> On Sun, Jun 07, 2020 at 01:57:11PM -0700, ToddAndMargo via perl6-users wrote:
> > On 2020-06-07 13:53, Peter Pentchev wrote:
> > > $path = 'lib1'.IO.d ?? 'lib1' !! 'lib2';
> > 
> > Got it!  Thank you!
> > 
> > I am not seeing the above enter the proper syntax:
> > 
> > 'lib1', 'lib2' etc.
> > 
> > Where is the comma?  How are the single quotes entered?
> 
> I don't understand what you are asking. The above checks whether
> a directory exists and, depending on the result of this check, assigns
> one of two values to a variable. I don't know what comma you are talking
> about.

Wait, I think I got it. You're asking about the line underneath, the one
that you did not quote in this message, the line that says:

  use lib $path;

"use lib" expects you to pass a string (or more strings). 'c:/NtUtil' is
a string.  $path is a variable that holds a string. "use lib $path"
calls "use lib" and passes to it the string in the variable $path.

G'luck,
Peter

-- 
Peter Pentchev  r...@ringlet.net r...@debian.org p...@storpool.com
PGP key:http://people.FreeBSD.org/~roam/roam.key.asc
Key fingerprint 2EE7 A7A5 17FC 124C F115  C354 651E EFB0 2527 DF13


signature.asc
Description: PGP signature


Re: Is thre a way to do an "if" on "use lib"?

2020-06-07 Thread Peter Pentchev
On Sun, Jun 07, 2020 at 01:57:11PM -0700, ToddAndMargo via perl6-users wrote:
> On 2020-06-07 13:53, Peter Pentchev wrote:
> > $path = 'lib1'.IO.d ?? 'lib1' !! 'lib2';
> 
> Got it!  Thank you!
> 
> I am not seeing the above enter the proper syntax:
> 
> 'lib1', 'lib2' etc.
> 
> Where is the comma?  How are the single quotes entered?

I don't understand what you are asking. The above checks whether
a directory exists and, depending on the result of this check, assigns
one of two values to a variable. I don't know what comma you are talking
about.

G'luck,
Peter

-- 
Peter Pentchev  r...@ringlet.net r...@debian.org p...@storpool.com
PGP key:http://people.FreeBSD.org/~roam/roam.key.asc
Key fingerprint 2EE7 A7A5 17FC 124C F115  C354 651E EFB0 2527 DF13


signature.asc
Description: PGP signature


Re: question about the multi in method

2020-06-07 Thread Peter Pentchev
On Sun, Jun 07, 2020 at 12:28:33PM -0700, ToddAndMargo via perl6-users wrote:
> On 2020-06-07 08:19, Peter Pentchev wrote:
> > On Sun, Jun 07, 2020 at 09:04:45AM -0500, Brad Gilbert wrote:
> > > On Sun, Jun 7, 2020 at 3:15 AM ToddAndMargo via perl6-users <
> > > perl6-us...@perl.org> wrote:
> > > 
> > > > Hi All,
> > > > 
> > > > Dumb question:
> > > > 
> > > > Does the "multi" in "multi method" mean there
> > > > is more than one way to address a method?
> > > > 
> > > > Or, are the all methods "multi methods".
> > > > 
> > > > If not and the method is a multi, should not the
> > > > documentation show all (more than one) the ways of
> > > > addressing a multi method?
> > > 
> > > There are four different types of a function. (both method and sub)
> > > 
> > > - `multi`
> > > - `proto`
> > > - `only`
> > > - `anon`
> > > 
[snip]
> > 
> > Please note that I'm not criticizing the documentation,
> 
> That is all right.  I will take up that job.  I am
> about to zinger it pretty good.
> 
> > automatically
> > generated or not, or the efforts of everyone involved in producing it :)
> > I am under the impression that it is, at least to some extent,
> > automatically generated, so I'm genuinely curious what is it about
> > the .starts-with() method that has caused it to lose its Cool :)
> > 
> > ...and, of course, it may turn out that Todd meant something completely
> > different in this particular message and I hijacked the thread...
> > 
> > G'luck,
> > Peter
> > 
> 
> 
> Hi Peter,
> 
> Pretty close.
> 
> I do believe Brad answered the question.  There are
> multiple and only and some other types.
> 
> The reason why I ask is that I find the documentation
> frustrating.   Here is an example of a method I
> have NO trouble with and use all the time:
> 
> https://docs.raku.org/type/Mu#method_defined
> 
>   Declared as
>  multi method defined(   --> Bool:D)
>   Returns False on a type object, and True otherwise.
> 
> It shows one method, but clearly defines it as a
> "multi method".  If it is indeed a multiple,
> where are the other crypto lines?  Or is it a
> misprint and there is only one crypto line as
> it is indeed an "only".
> 
> So I asked, are they ALL multi's.  And the answer is "no".
> 
> Now when I opened a bug report on one of them:
> 
>  Where is the multi in starts-with?
>  https://github.com/Raku/doc/issues/3456
> 
> JJ closed the ticket with the following answer:
> 
>  Let me see how I explain this. It's a bit like
>  the American party primaries. Anyone can run,
>  right? Only in some cases (mainly when the incumbent
>  is there), nobody else bothers to. In this case, a
>  multi shows the possibility of declaring other
>  routines with the same name and different signature,
>  unlike only which says "Nope, you can't".

This is actually very, very common in object-oriented programming.
You create a new class, you have a couple of methods that you know will
be useful to others, so you declare them as multi in Raku or, say,
virtual in C++. Then you add a couple of other methods, and you stop and
think "hm, okay, so right now I don't have a need to use this method in
another way or override it in another class, but what it does is pretty
general, easily extensible, so, yeah, it is very much possible that
tomorrow I (or somebody else) will need to redefine or extend it" - and
that's why you put a "multi" on a method that *right now* has no real
use for it, but it will have one tomorrow.

I do not have an example in mind right now, but I bet that if I look
through some of the modules found at https://modules.raku.org/ I can
find classes that redefine or extend some really basic methods in
Raku's base classes. This is only possible because the developers of
Raku decided to declare them as "multi" even though they had no
immediate use for that right at that moment.

>  As a matter of fact, there are several of them.
> 
> https://github.com/rakudo/rakudo/search?q=%22method+starts-with%22_q=%22method+starts-with%22
>  However, in this case we made the call of putting
>  them in a single definition, since the existence
>  of different ones is simply an implementation
>  detail.
> 
> So JJ confirmed that the method was indeed a multi method
> but that he WOULD NOT include the other definitions
> as it is an "implementati

Re: Is thre a way to do an "if" on "use lib"?

2020-06-07 Thread Peter Pentchev
On Sun, Jun 07, 2020 at 12:32:09PM -0700, ToddAndMargo via perl6-users wrote:
> On 2020-06-07 02:32, Peter Pentchev wrote:
> 
> > BEGIN {
> > $path = 'lib1'.IO.d ?? 'lib1' !! 'lib2';
> > }
> 
> Does the final "}" close the BEGIN?

Well, there is an opening { after "BEGIN", so, yes.

More precisely, it closes the block that is to be executed early.

> > $path = 'lib1'.IO.d ?? 'lib1' !! 'lib2';
> 
> Hi Peter,
> 
> Would you explain what the ?? and !! are
> doing in the above?

https://docs.raku.org/language/operators#infix_??_!!

G'luck,
Peter

-- 
Peter Pentchev  r...@ringlet.net r...@debian.org p...@storpool.com
PGP key:http://people.FreeBSD.org/~roam/roam.key.asc
Key fingerprint 2EE7 A7A5 17FC 124C F115  C354 651E EFB0 2527 DF13


signature.asc
Description: PGP signature


Re: I need a GTK pop up with time out

2020-06-07 Thread Peter Pentchev
On Sun, Jun 07, 2020 at 04:45:16PM +0100, Richard Hainsworth wrote:
> Todd
> 
> I'm answering this question in the main list to explain some shortcuts.
> 
> Just to make sure it all works (if Windows will accept GTK), copy the
> program from the Readme to a script file and run it with raku.
> 
> Playing around with it should make things clear.
> 
> On 07/06/2020 07:16, ToddAndMargo via perl6-users wrote:
[snip]
> > 7) why is there no "show-countdown"?
> 
> There is! `:show-countdown` is named parameter to the method 'show', and an
> example is shown.
> 
> By default `:show-countdown` is True, so there is no need to set it if you
> want a countdown. If you dont want a count-down shown, then you need to set
> `:!show-countdown` , which in itself is a shortcut for
> `show-countdown(True)` . This was one of the examples.

Just a minor point: ITYM "a shortcut for show_countdown(False)" :)

> Those shortcuts are becoming fairly common raku idioms. I didn't think it
> would be necessary to document them.

G'luck,
Peter

-- 
Peter Pentchev  r...@ringlet.net r...@debian.org p...@storpool.com
PGP key:http://people.FreeBSD.org/~roam/roam.key.asc
Key fingerprint 2EE7 A7A5 17FC 124C F115  C354 651E EFB0 2527 DF13


signature.asc
Description: PGP signature


Re: question about the multi in method

2020-06-07 Thread Peter Pentchev
On Sun, Jun 07, 2020 at 06:19:29PM +0300, Peter Pentchev wrote:
> On Sun, Jun 07, 2020 at 09:04:45AM -0500, Brad Gilbert wrote:
> > On Sun, Jun 7, 2020 at 3:15 AM ToddAndMargo via perl6-users <
> > perl6-us...@perl.org> wrote:
> > 
> > > Hi All,
> > >
> > > Dumb question:
> > >
> > > Does the "multi" in "multi method" mean there
> > > is more than one way to address a method?
> > >
> > > Or, are the all methods "multi methods".
> > >
> > > If not and the method is a multi, should not the
> > > documentation show all (more than one) the ways of
> > > addressing a multi method?
> > 
> > There are four different types of a function. (both method and sub)
> > 
> > - `multi`
> > - `proto`
> > - `only`
> > - `anon`
> > 
> > A `proto` function is mainly just to declare there will be multiple
> > functions with same name.
> > `multi` is short for "multiple", meaning more than one.
> > `only` is the default, it means there is only one.
> > `anon` is for creating a lambda. (You only need it if you give the function
> > a name.)
> > 
> > Again this applies to both subs and methods.
> > (Also `regex`, `token`, and `rule`. As they are just special methods.)
> > 
> > only sub foo (){}
> > only sub foo (1){} # ERROR: redeclaration
> > # note that `only` is optional, as it is the default.
> > 
> > proto sub bar (|){*}
> > multi sub bar (){}
> > multi sub bar (1){}
> > # note that defining a `proto` function is optional
> > 
> > my $var = anon sub baz (){ 'fuzz' };
> > say baz(); # ERROR: can't find a sub named `baz`
> > say $var(); # fuzz
> > say $var.name; # baz
> 
> I believe, though I'm not sure, that Todd may be referring to one of
> the questions that came up in a longish recent thread, namely the fact
> that the documentation of Str.starts-with() seems to only document it as
> a Str method, while Raku seems to disagree:
> 
> [roam@straylight ~]$ raku -e 'my Str $x; $x.starts-with("a")'
> Cannot resolve caller starts-with(Str:U: Str:D); none of these signatures 
> match:
> (Cool:D: Cool:D $needle, :i(:$ignorecase)!, :m(:$ignoremark), *%_ --> 
> Bool)
> (Cool:D: Cool:D $needle, :m(:$ignoremark)!, *%_ --> Bool)
> (Cool:D: Cool:D $needle, *%_ --> Bool)
> (Str:D: Str:D $needle, :i(:$ignorecase)!, :m(:$ignoremark), *%_ --> Bool)
> (Str:D: Str:D $needle, :m(:$ignoremark)!, *%_ --> Bool)
> (Str:D: Str:D $needle, *%_ --> Bool)
>   in block  at -e line 1
> 
> [roam@straylight ~]$
> 
> So it seems that Cool has a .starts-with() method too, and this is borne
> out by a further experiment:
> 
> [roam@straylight ~]$ raku -e 'my Cool $x; $x.starts-with("a")'
> Cannot resolve caller starts-with(Cool:U: Str:D); none of these signatures 
> match:
> (Cool:D: Cool:D $needle, :i(:$ignorecase)!, :m(:$ignoremark), *%_ --> 
> Bool)
> (Cool:D: Cool:D $needle, :m(:$ignoremark)!, *%_ --> Bool)
> (Cool:D: Cool:D $needle, *%_ --> Bool)
>   in block  at -e line 1
> 
> [roam@straylight ~]$
> 
> So the truth is that I do not fully understand why the documentation
> does not list .starts-with() as a method for Cool as well as Str: in
> https://docs.raku.org/routine.html "starts-with" is listed as "from
> Str", while there are other methods that are listed as "from Cool, Str",
> e.g. "subst".
> 
> Now, yeah, I understand that Str.starts-with() defines a coercion for
> its $needle argument that means that Cool.starts-with() will never be
> called for an invocant that is either a Str or of any type derived from
> Str, no matter what $needle is - if it is from another Cool-derived
> type, it will be coerced to Str and Str.starts-with() will be called.
> However, should the documentation not mention that another type derived
> from Cool will also have a .starts-with() method?
> 
> Please note that I'm not criticizing the documentation, automatically
> generated or not, or the efforts of everyone involved in producing it :)
> I am under the impression that it is, at least to some extent,
> automatically generated, so I'm genuinely curious what is it about
> the .starts-with() method that has caused it to lose its Cool :)
> 
> ...and, of course, it may turn out that Todd meant something completely
> different in this particular message and I hijacked the thread...

Ah nevermind, I figured it out. Stupid me!

That *is* what Cool does!

That is the whole purpose Cool - to

Re: question about the multi in method

2020-06-07 Thread Peter Pentchev
On Sun, Jun 07, 2020 at 09:04:45AM -0500, Brad Gilbert wrote:
> On Sun, Jun 7, 2020 at 3:15 AM ToddAndMargo via perl6-users <
> perl6-us...@perl.org> wrote:
> 
> > Hi All,
> >
> > Dumb question:
> >
> > Does the "multi" in "multi method" mean there
> > is more than one way to address a method?
> >
> > Or, are the all methods "multi methods".
> >
> > If not and the method is a multi, should not the
> > documentation show all (more than one) the ways of
> > addressing a multi method?
> 
> There are four different types of a function. (both method and sub)
> 
> - `multi`
> - `proto`
> - `only`
> - `anon`
> 
> A `proto` function is mainly just to declare there will be multiple
> functions with same name.
> `multi` is short for "multiple", meaning more than one.
> `only` is the default, it means there is only one.
> `anon` is for creating a lambda. (You only need it if you give the function
> a name.)
> 
> Again this applies to both subs and methods.
> (Also `regex`, `token`, and `rule`. As they are just special methods.)
> 
> only sub foo (){}
> only sub foo (1){} # ERROR: redeclaration
> # note that `only` is optional, as it is the default.
> 
> proto sub bar (|){*}
> multi sub bar (){}
> multi sub bar (1){}
> # note that defining a `proto` function is optional
> 
> my $var = anon sub baz (){ 'fuzz' };
> say baz(); # ERROR: can't find a sub named `baz`
> say $var(); # fuzz
> say $var.name; # baz

I believe, though I'm not sure, that Todd may be referring to one of
the questions that came up in a longish recent thread, namely the fact
that the documentation of Str.starts-with() seems to only document it as
a Str method, while Raku seems to disagree:

[roam@straylight ~]$ raku -e 'my Str $x; $x.starts-with("a")'
Cannot resolve caller starts-with(Str:U: Str:D); none of these signatures match:
(Cool:D: Cool:D $needle, :i(:$ignorecase)!, :m(:$ignoremark), *%_ --> Bool)
(Cool:D: Cool:D $needle, :m(:$ignoremark)!, *%_ --> Bool)
(Cool:D: Cool:D $needle, *%_ --> Bool)
(Str:D: Str:D $needle, :i(:$ignorecase)!, :m(:$ignoremark), *%_ --> Bool)
(Str:D: Str:D $needle, :m(:$ignoremark)!, *%_ --> Bool)
(Str:D: Str:D $needle, *%_ --> Bool)
  in block  at -e line 1

[roam@straylight ~]$

So it seems that Cool has a .starts-with() method too, and this is borne
out by a further experiment:

[roam@straylight ~]$ raku -e 'my Cool $x; $x.starts-with("a")'
Cannot resolve caller starts-with(Cool:U: Str:D); none of these signatures 
match:
(Cool:D: Cool:D $needle, :i(:$ignorecase)!, :m(:$ignoremark), *%_ --> Bool)
(Cool:D: Cool:D $needle, :m(:$ignoremark)!, *%_ --> Bool)
(Cool:D: Cool:D $needle, *%_ --> Bool)
  in block  at -e line 1

[roam@straylight ~]$

So the truth is that I do not fully understand why the documentation
does not list .starts-with() as a method for Cool as well as Str: in
https://docs.raku.org/routine.html "starts-with" is listed as "from
Str", while there are other methods that are listed as "from Cool, Str",
e.g. "subst".

Now, yeah, I understand that Str.starts-with() defines a coercion for
its $needle argument that means that Cool.starts-with() will never be
called for an invocant that is either a Str or of any type derived from
Str, no matter what $needle is - if it is from another Cool-derived
type, it will be coerced to Str and Str.starts-with() will be called.
However, should the documentation not mention that another type derived
from Cool will also have a .starts-with() method?

Please note that I'm not criticizing the documentation, automatically
generated or not, or the efforts of everyone involved in producing it :)
I am under the impression that it is, at least to some extent,
automatically generated, so I'm genuinely curious what is it about
the .starts-with() method that has caused it to lose its Cool :)

...and, of course, it may turn out that Todd meant something completely
different in this particular message and I hijacked the thread...

G'luck,
Peter

-- 
Peter Pentchev  r...@ringlet.net r...@debian.org p...@storpool.com
PGP key:http://people.FreeBSD.org/~roam/roam.key.asc
Key fingerprint 2EE7 A7A5 17FC 124C F115  C354 651E EFB0 2527 DF13


signature.asc
Description: PGP signature


Re: Is thre a way to do an "if" on "use lib"?

2020-06-07 Thread Peter Pentchev
On Sun, Jun 07, 2020 at 11:37:43AM +0200, JJ Merelo wrote:
> El dom., 7 jun. 2020 a las 11:32, Peter Pentchev ()
> escribió:
> 
> > On Sun, Jun 07, 2020 at 12:28:36AM -0700, ToddAndMargo via perl6-users
> > wrote:
> > > Hi All,
> > >
> > > Is there a way to do an "if" on "use lib", so
> > > I do not have to keep commenting these back and forth?
> > >
> > > # use lib 'C:/NtUtil', '.';
> > > use lib 'C:/NtUtil', '.', 'K:/NtUtil';
> >
> > "use lib" is evaluated quite early in the program's execution, so to do
> > any interesting things with it, you will need to use a BEGIN phaser
> > (similar to what you might know as a BEGIN block in Perl):
> >
> > =
> > #!/usr/bin/env raku
> >
> > use v6.d;
> >
> > my $path;
> >
> > BEGIN {
> > $path = 'lib1'.IO.d ?? 'lib1' !! 'lib2';
> > }
> >
> > use lib $path;
> >
> > use Foo;
> >
> > Foo.new.hello;
> > =
> >
> > Hope that helps!
> >
> > G'luck,
> > Peter
> >
> > --
> > Peter Pentchev  r...@ringlet.net r...@debian.org p...@storpool.com
> > PGP key:http://people.FreeBSD.org/~roam/roam.key.asc
> > Key fingerprint 2EE7 A7A5 17FC 124C F115  C354 651E EFB0 2527 DF13
> >
> 
> Also, you can simply issue different -I arguments when you invoke the
> script; you can put that in a shell or whatever script
> 
> raku -Imy/lib script
> 
> for your own lib
> 
> raku -Iother/lib script
> 
> for other
> 
> (or Windows equivalent). No need to use Raku to change the path, actually.

True, true :)

"Wait, let's take a step back; what are you *really* trying to do?" is
something that my coworkers have learned to expect when they come to me
with a question :) Thanks for calling me out on the same thing here!

G'luck,
Peter

-- 
Peter Pentchev  r...@ringlet.net r...@debian.org p...@storpool.com
PGP key:http://people.FreeBSD.org/~roam/roam.key.asc
Key fingerprint 2EE7 A7A5 17FC 124C F115  C354 651E EFB0 2527 DF13


signature.asc
Description: PGP signature


Re: changing name of module

2020-06-07 Thread Peter Pentchev
On Sun, Jun 07, 2020 at 02:28:08PM +0100, Richard Hainsworth wrote:
> On 07/06/2020 13:31, Parrot Raiser wrote:
> > Create an updated version, perhaps with an "rk" prefix, (preserving
> > any text alignment, since "p6" and "rk" are the same length), then
> > change the "pk" version simply to invoke the "rk"?
> > 
> > Existing code should continue to work, albeit nanoseconds slower,
> > while new code can be culturally consistent.
> 
> Why nanoseconds slower? (I won't notice them, but why would a name change
> slow things?)
> 
> If alignment is not a concern, then p6 and raku are equivalent?

I believe the idea is that two modules are installed on the user's
machine: the renamed rk-* one and a single-line p6-* shim that only
imports the rk-* one. Thus, other programs that use the p6-* name will
load that first, then load the rk-* one, hence the nanoseconds delay.

G'luck,
Peter

-- 
Peter Pentchev  r...@ringlet.net r...@debian.org p...@storpool.com
PGP key:http://people.FreeBSD.org/~roam/roam.key.asc
Key fingerprint 2EE7 A7A5 17FC 124C F115  C354 651E EFB0 2527 DF13


signature.asc
Description: PGP signature


Re: Is thre a way to do an "if" on "use lib"?

2020-06-07 Thread Peter Pentchev
On Sun, Jun 07, 2020 at 12:28:36AM -0700, ToddAndMargo via perl6-users wrote:
> Hi All,
> 
> Is there a way to do an "if" on "use lib", so
> I do not have to keep commenting these back and forth?
> 
> # use lib 'C:/NtUtil', '.';
> use lib 'C:/NtUtil', '.', 'K:/NtUtil';

"use lib" is evaluated quite early in the program's execution, so to do
any interesting things with it, you will need to use a BEGIN phaser
(similar to what you might know as a BEGIN block in Perl):

=
#!/usr/bin/env raku

use v6.d;

my $path;

BEGIN {
$path = 'lib1'.IO.d ?? 'lib1' !! 'lib2';
}

use lib $path;

use Foo;

Foo.new.hello;
=====

Hope that helps!

G'luck,
Peter

-- 
Peter Pentchev  r...@ringlet.net r...@debian.org p...@storpool.com
PGP key:http://people.FreeBSD.org/~roam/roam.key.asc
Key fingerprint 2EE7 A7A5 17FC 124C F115  C354 651E EFB0 2527 DF13


signature.asc
Description: PGP signature


Re: Had a weird symptom calling raku

2020-06-05 Thread Peter Pentchev
On Fri, Jun 05, 2020 at 11:32:20AM -0700, ToddAndMargo via perl6-users wrote:
> Hi All,
> 
> Windows 10 Pro
> 
> raku -v
> This is Rakudo version 2020.05.1 built on MoarVM version
> 2020.05 implementing Raku 6.d.
> 
> I had a weird symptom calling Raku from Cobian Backup.
> A black box popped up, delayed about two seconds,
> then died.  The only writing was the flashing cursor.
> 
> Running the program directly from a shell showed
> that I had a directory in "lib" that did not
> exist on the customer's machine:
> 
> use lib 'K:/NtUtil', 'C:/NtUtil', '.';
> 
> Edited out the missing directory and happy camping returned.

What is the window title of that "black box"? Is it possible that it is
a command prompt that is actually your program, and that it took longer
to run because of something like trying to access a network drive or
something? (note: I have not run Windows in about ten years, I have no
idea how it behaves when you try to access a drive letter that does not
correspond to a currently mapped device or share).

> use lib 'C:/NtUtil', '.';
> 
> I thought for a moment that Raku could not be called
> from Cobian.  Had one of those "ah poop" moments
> 
> 
> -T
> 
> 'K:/NtUtil' is the network drive I program my various
> Windows virtual machines from.   Since the shell I
> use is in that directory, "." will suffice.

G'luck,
Peter

-- 
Peter Pentchev  r...@ringlet.net r...@debian.org p...@storpool.com
PGP key:http://people.FreeBSD.org/~roam/roam.key.asc
Key fingerprint 2EE7 A7A5 17FC 124C F115  C354 651E EFB0 2527 DF13


signature.asc
Description: PGP signature


Re: I reproduced one of the errors!

2020-06-04 Thread Peter Pentchev
On Wed, Jun 03, 2020 at 07:00:53PM -0700, ToddAndMargo via perl6-users wrote:
> On 2020-06-03 02:21, Peter Pentchev wrote:
> > On Wed, Jun 03, 2020 at 01:06:33AM -0700, ToddAndMargo via perl6-users 
> > wrote:
> > > On 2020-06-02 22:15, Peter Pentchev wrote:
> > > > On Tue, Jun 02, 2020 at 07:39:16PM -0700, ToddAndMargo via perl6-users 
> > > > wrote:
> > > > > On 2020-06-01 23:02, Peter Pentchev wrote:
> > > > > > https://docs.raku.org/language/classtut
> > > > > 
> > > > > Error 522 Ray ID: 59d609616954eb79 • 2020-06-03 02:38:12 UTC
> > > > > Connection timed out
> > > > > 
> > > > > Poop!
> > > > 
> > > > This is usually some kind of temporary error - something broke down
> > > > between your computer and the server. Try again later, it might work.
> > > > (it's the Raku docs site, you've used it before, you know it usually
> > > > works :)
> > > > 
> > > > G'luck,
> > > > Peter
> > > > 
> > > 
> > > Hi Peter,
> > > 
> > > It is working now.  Thank you.
> > > 
> > > You would happen to know of a tutorial.  Me and
> > > the documents ... well, lets say they are not
> > > written with the same outcome in mind as perldocs.
> > > 
> > > Is there a way to write a methods as I would write
> > > a sub and avoiding the class thing?
> > 
> > OK, now I really have to ask, just like other people have.
> > 
> > What exactly do you mean by "method"?
> > 
> > G'luck,
> > Peter
> > 
> 
> > say "AbCd".lc
> abcd
> 
> lc would be the method:
> multi method lc(Str:D: --> Str:D)

Right. So apart from the & trick that Fernando Santagata showed you (but
see below, it's not really calling a method) and that is neat but has
its drawbacks (like for instance you cannot ask an object if it .can()
do a specific method), you want to call a method on an object.

In general, and the point of this subthread is, methods are not
standalone subroutines; they are defined as part of the whole "variables
have types, those types are called classes, each class defines
the methods that you may call on its variables" object-oriented
programming thing. When you say "method", this is what people think
you're talking about, because, well, this is what "method" kind of means
when one uses it in a conversation about computer programming,
especially when talking about a language with a class-, role-, and
inheritance-based type system.

The trick that Fernando showed you is not really calling a method;
it is a cute way of the Raku syntax to specify the first argument when
calling a subroutine. The subroutine is not a method, it does not show
up in .can() or .^methods or .HOW or any of the way to ask a variable
what methods it supports. Yes, it is possible to define a multi sub that
does different things when called on different types of first argument,
but it is still not a method, it is a subroutine.

A method is something that is tied to a class. For a quick overview of
classes, methods, and the main ideas of object-oriented programming, try
https://www.freecodecamp.org/news/object-oriented-programming-concepts-21bb035f7260/
Also, take another look at https://docs.raku.org/language/classtut -
especially the part "Starting with a class" and onwards.

G'luck,
Peter

-- 
Peter Pentchev  r...@ringlet.net r...@debian.org p...@storpool.com
PGP key:http://people.FreeBSD.org/~roam/roam.key.asc
Key fingerprint 2EE7 A7A5 17FC 124C F115  C354 651E EFB0 2527 DF13


signature.asc
Description: PGP signature


Re: I reproduced one of the errors!

2020-06-03 Thread Peter Pentchev
On Wed, Jun 03, 2020 at 01:12:41PM +0300, Veesh Goldman wrote:
> On Wed, Jun 3, 2020, 12:22 Peter Pentchev  wrote:
> 
> > On Wed, Jun 03, 2020 at 01:06:33AM -0700, ToddAndMargo via perl6-users
> > wrote:
> > > On 2020-06-02 22:15, Peter Pentchev wrote:
> > > > On Tue, Jun 02, 2020 at 07:39:16PM -0700, ToddAndMargo via perl6-users
> > wrote:
> > > > > On 2020-06-01 23:02, Peter Pentchev wrote:
> > > > > > https://docs.raku.org/language/classtut
> > > > >
> > > > > Error 522 Ray ID: 59d609616954eb79 • 2020-06-03 02:38:12 UTC
> > > > > Connection timed out
> > > > >
> > > > > Poop!
> > > >
> > > > This is usually some kind of temporary error - something broke down
> > > > between your computer and the server. Try again later, it might work.
> > > > (it's the Raku docs site, you've used it before, you know it usually
> > > > works :)
> > > >
> > > > G'luck,
> > > > Peter
> > > >
> > >
> > > Hi Peter,
> > >
> > > It is working now.  Thank you.
> > >
> > > You would happen to know of a tutorial.  Me and
> > > the documents ... well, lets say they are not
> > > written with the same outcome in mind as perldocs.
> > >
> > > Is there a way to write a methods as I would write
> > > a sub and avoiding the class thing?
> >
> > OK, now I really have to ask, just like other people have.
> >
> > What exactly do you mean by "method"?
> 
> I assume he means a multi method.

Um, that would be kind of recursive, that would still require knowledge
of what a method is. Better to let Todd explain what is meant by
"method" in these messages.

G'luck,
Peter

-- 
Peter Pentchev  r...@ringlet.net r...@debian.org p...@storpool.com
PGP key:http://people.FreeBSD.org/~roam/roam.key.asc
Key fingerprint 2EE7 A7A5 17FC 124C F115  C354 651E EFB0 2527 DF13


signature.asc
Description: PGP signature


Re: I reproduced one of the errors!

2020-06-03 Thread Peter Pentchev
On Wed, Jun 03, 2020 at 01:06:33AM -0700, ToddAndMargo via perl6-users wrote:
> On 2020-06-02 22:15, Peter Pentchev wrote:
> > On Tue, Jun 02, 2020 at 07:39:16PM -0700, ToddAndMargo via perl6-users 
> > wrote:
> > > On 2020-06-01 23:02, Peter Pentchev wrote:
> > > > https://docs.raku.org/language/classtut
> > > 
> > > Error 522 Ray ID: 59d609616954eb79 • 2020-06-03 02:38:12 UTC
> > > Connection timed out
> > > 
> > > Poop!
> > 
> > This is usually some kind of temporary error - something broke down
> > between your computer and the server. Try again later, it might work.
> > (it's the Raku docs site, you've used it before, you know it usually
> > works :)
> > 
> > G'luck,
> > Peter
> > 
> 
> Hi Peter,
> 
> It is working now.  Thank you.
> 
> You would happen to know of a tutorial.  Me and
> the documents ... well, lets say they are not
> written with the same outcome in mind as perldocs.
> 
> Is there a way to write a methods as I would write
> a sub and avoiding the class thing?

OK, now I really have to ask, just like other people have.

What exactly do you mean by "method"?

G'luck,
Peter

-- 
Peter Pentchev  r...@ringlet.net r...@debian.org p...@storpool.com
PGP key:http://people.FreeBSD.org/~roam/roam.key.asc
Key fingerprint 2EE7 A7A5 17FC 124C F115  C354 651E EFB0 2527 DF13


signature.asc
Description: PGP signature


Re: I reproduced one of the errors!

2020-06-02 Thread Peter Pentchev
On Tue, Jun 02, 2020 at 07:39:16PM -0700, ToddAndMargo via perl6-users wrote:
> On 2020-06-01 23:02, Peter Pentchev wrote:
> > https://docs.raku.org/language/classtut
> 
> Error 522 Ray ID: 59d609616954eb79 • 2020-06-03 02:38:12 UTC
> Connection timed out
> 
> Poop!

This is usually some kind of temporary error - something broke down
between your computer and the server. Try again later, it might work.
(it's the Raku docs site, you've used it before, you know it usually
works :)

G'luck,
Peter

-- 
Peter Pentchev  r...@ringlet.net r...@debian.org p...@storpool.com
PGP key:http://people.FreeBSD.org/~roam/roam.key.asc
Key fingerprint 2EE7 A7A5 17FC 124C F115  C354 651E EFB0 2527 DF13


signature.asc
Description: PGP signature


Re: I reproduced one of the errors!

2020-06-02 Thread Peter Pentchev
On Tue, Jun 02, 2020 at 09:34:30PM +0300, Peter Pentchev wrote:
> On Tue, Jun 02, 2020 at 11:41:31AM -0400, Parrot Raiser wrote:
> > I suspect that "methods" were originally distinguished from
> > "subroutines" because it made the rain-dance about the new cure for
> > all civilisation's ills and the heartbreak of psoriasis,
> > Object-Oriented Programming,  look more impressive. After one has seen
> > a few programming religions launched, the similarities blur the
> > differences.  Profundity through obscurity always helps the marketing,
> > because it slows the recognition.
> 
> That... is only if you look at methods purely from an imperative and
> procedural programming perspective :) Once you start thinking about
> message passing or events, things get a little weirder :)

...not to mention that methods do, of course, provide a level of
abstraction that is difficult to achieve with unbound subroutines.
I imagine that you use that every day in Raku programming, either with
smart-matching (the ACCEPTS method is kind of useful there), or with
checking whether lists or arrays are empty (the .Bool method is kind of
useful there), or with outputting values in easy-to-read format
(the .gist method is kind of useful there). All of these would be...
kind of unwieldy to do with subroutines that are not bound to any
object, but have to check what they are called at every step.

> > Subroutines are blocks of code that can be used anywhere within a
> > scope that may be global or local. Methods are a subset of subroutines
> > that can only be used within a particular scope on particular kinds of
> > things.
> 
> ...or so it is in procedural languages, which have their orientation
> towards procedures (another name for subroutines) encoded right there in
> the designation :)
> 
> But that's a wholly different topic, we've abused this thread's subject
> too much already, so I'll stop now :)

G'luck,
Peter

-- 
Peter Pentchev  r...@ringlet.net r...@debian.org p...@storpool.com
PGP key:http://people.FreeBSD.org/~roam/roam.key.asc
Key fingerprint 2EE7 A7A5 17FC 124C F115  C354 651E EFB0 2527 DF13


signature.asc
Description: PGP signature


Re: I reproduced one of the errors!

2020-06-02 Thread Peter Pentchev
On Tue, Jun 02, 2020 at 11:41:31AM -0400, Parrot Raiser wrote:
> I suspect that "methods" were originally distinguished from
> "subroutines" because it made the rain-dance about the new cure for
> all civilisation's ills and the heartbreak of psoriasis,
> Object-Oriented Programming,  look more impressive. After one has seen
> a few programming religions launched, the similarities blur the
> differences.  Profundity through obscurity always helps the marketing,
> because it slows the recognition.

That... is only if you look at methods purely from an imperative and
procedural programming perspective :) Once you start thinking about
message passing or events, things get a little weirder :)

> Subroutines are blocks of code that can be used anywhere within a
> scope that may be global or local. Methods are a subset of subroutines
> that can only be used within a particular scope on particular kinds of
> things.

...or so it is in procedural languages, which have their orientation
towards procedures (another name for subroutines) encoded right there in
the designation :)

But that's a wholly different topic, we've abused this thread's subject
too much already, so I'll stop now :)

G'luck,
Peter

-- 
Peter Pentchev  r...@ringlet.net r...@debian.org p...@storpool.com
PGP key:http://people.FreeBSD.org/~roam/roam.key.asc
Key fingerprint 2EE7 A7A5 17FC 124C F115  C354 651E EFB0 2527 DF13


signature.asc
Description: PGP signature


Re: I reproduced one of the errors!

2020-06-02 Thread Peter Pentchev
On Tue, Jun 02, 2020 at 08:52:37AM +0300, Peter Pentchev wrote:
> On Mon, Jun 01, 2020 at 01:36:19PM -0700, ToddAndMargo via perl6-users wrote:
[snip]
> > A follow up question:
> > 
> > Is there a booboo in the documentation here?
> > 
> > https://docs.raku.org/routine/starts-with
> > multi method starts-with(Str:D: Str(Cool) $needle, :i(:$ignorecase),
> > :m(:$ignoremark) --> Bool:D)
> > 
> > It says "multi method" but only shows one method.
> > Did they leave something out?
> 
> Mmm, and this is where we come to the original error message :)
> It says that there is a "starts-with()" method in the Str class that
> accepts a "$needle" parameter of the Str:D type, but then (or, rather,
> before that) it says that there is a "starts-with()" method in the Cool
> class that accepts a "$neddle" parameter of the Cool:D type. Since Str
> is derived from Cool, when you call a method on Str Raku will also look
> for this method in Cool. Since the two methods accept parameters of
> different types, they (or at least the method in the child class Str)
> have to be declared as multi methods so Raku knows that a type mismatch
> on the first one that it found does not mean that it should stop
> looking.
> 
> But, hm, why the documentation of the starts-with() method on the page
> that you linked to does not mention that it is also present in Cool is
> indeed an interesting question. Moreover, even the list of methods at
> https://docs.raku.org/routine-method.html says "method starts-with()
> from Str", while other methods such as subst() are listed as "from Cool,
> Str", etc. I honestly don't know what the difference is, I expect it is
> because of some internal details of the implementation of the Str
> method, but I won't be able to look it in the source right now. Maybe
> somebody else could shed some light on that?

OK, so I have a theory. Is it possible that this is because
Str.starts-with() has a coercion of its $needle parameter from Cool, so
whatever is building the documentation deduces (correctly) that
Cool.starts-with() will never be invoked on anything that is Str or is
derived from Str? Still, should the documentation not, well, document
that any class derived from Cool has a starts-with() method?

G'luck,
Peter

-- 
Peter Pentchev  r...@ringlet.net r...@debian.org p...@storpool.com
PGP key:http://people.FreeBSD.org/~roam/roam.key.asc
Key fingerprint 2EE7 A7A5 17FC 124C F115  C354 651E EFB0 2527 DF13


signature.asc
Description: PGP signature


Re: I reproduced one of the errors!

2020-06-02 Thread Peter Pentchev
On Mon, Jun 01, 2020 at 01:38:48PM -0700, ToddAndMargo via perl6-users wrote:
> On 2020-06-01 02:21, Peter Pentchev wrote:
> > class Thing {
> > multi method do-things(Int:D $value) {
> > say "A thing can do things with an integer: $value";
> > }
> > 
> > multi method do-things(Rational:D $value) {
> > say "A thing can do things with a rational number: $value";
> > }
> > }
> 
> Hi Peter,
> 
> I have asked this question before.  Is it possible for
> me to create my own methods.  The answer came back as
> "no".
> 
> Did you just demonstrate for me how to create my own
> methods?

Is it possible that you asked whether you could add your own methods to
an already-existing class, like add a "meows()" method to the Str class
that would return the number of occurrences of the substring "meow"?
Because in that case the answer is "in most cases, no, except for some
weirdness that may lead to weird things if it is used in weird ways".

You *can* define your *own* classes and once you define a class, it is
kind of assumed that you will define methods for that class. There is
something like a tutorial (not a reference) at
https://docs.raku.org/language/classtut (note that it starts with
an example that may not be easy to understand right off the bat, but
then in the "Starting with class" section and onwards it explains what
was used in that example point by point).

You can also extend other classes, especially ones that you have
defined. Now there are exceptions: there are some system classes that it
is not easy to extend except using some of the weirdness that
I mentioned in the first paragraph, and I really will not go into that
here.

You can also add roles to most classes using the "does" and "but"
keywords. This is explained in more detail at
https://docs.raku.org/language/typesystem#role but bear in mind that
adding roles to existing classes may cause some already-written code to
behave in unexpected ways and cause difficult-to-find mistakes, so it's
better to either add a role to a specific object or to define a new
class that says "I'm just like that original class, but I also have that
role". Of course, there are always exceptions; there are a few cases
when the so-called "monkey-patching" technique may be put to good use,
and Raku will allow you to that if you really want to, but it really
often leads to difficult-to-find mistakes.

G'luck,
Peter

-- 
Peter Pentchev  r...@ringlet.net r...@debian.org p...@storpool.com
PGP key:http://people.FreeBSD.org/~roam/roam.key.asc
Key fingerprint 2EE7 A7A5 17FC 124C F115  C354 651E EFB0 2527 DF13


signature.asc
Description: PGP signature


Re: I reproduced one of the errors!

2020-06-01 Thread Peter Pentchev
On Mon, Jun 01, 2020 at 01:36:19PM -0700, ToddAndMargo via perl6-users wrote:
> On 2020-06-01 02:21, Peter Pentchev wrote:
> > On Mon, Jun 01, 2020 at 01:15:23AM -0700, ToddAndMargo via perl6-users 
> > wrote:
> > > On 2020-05-31 17:13, Peter Pentchev wrote:
> > > > On Mon, Jun 01, 2020 at 03:12:05AM +0300, Peter Pentchev wrote:
> > > > > On Sun, May 31, 2020 at 04:29:55PM -0700, ToddAndMargo via 
> > > > > perl6-users wrote:
> > > > > > On 2020-05-31 04:58, Peter Pentchev wrote:
> > > > > > > > > So my beef is when you feed these guys an undefined
> > > > > > > > > variable, that they needs to tell you it requires
> > > > > > > > > a "defined" variable.  Not a bunch of useless rubbish.
> > > > > > > > > For example (useless rubbish):
> > > > > > > And also... I thought I mentioned this before. You want a more 
> > > > > > > clear
> > > > > > > error message for*one*  *single*  specific case of a "can't find 
> > > > > > > this
> > > > > > > method, did you mean one of these?" error message. I tried to 
> > > > > > > explain
> > > > > > > that this error message is one that is displayed in many cases, 
> > > > > > > not only
> > > > > > > for "you passed an undefined thing, I want a defined thing"; in my
> > > > > > > opinion, it is actually quite helpful in that it actually lists
> > > > > > > the candidates in a "did you mean one of these?" style.
> > > > > > > 
> > > > > > > You want it to be clear if you pass an undefined value where a 
> > > > > > > defined
> > > > > > > value was expected; that would mean that somebody would have to 
> > > > > > > write
> > > > > > > the code to make it check whether it is this very specific case 
> > > > > > > and then
> > > > > > > that code would have to be maintained for years and years. 
> > > > > > > Tomorrow
> > > > > > > you'll say "but can't it give me a more clear message when I pass 
> > > > > > > an
> > > > > > > integer and it expected a string?" and the day after tomorrow 
> > > > > > > you'll say
> > > > > > > "but can't it give me a more clear message when I pass a string 
> > > > > > > and it
> > > > > > > expected a function?".
> > > > > > > 
> > > > > > > The error message says "you passed an object of this type, and I 
> > > > > > > can't
> > > > > > > find this method for this type; here are a couple of types that 
> > > > > > > have
> > > > > > > this method, did you mean one of these?"  It tells you what the 
> > > > > > > types
> > > > > > > are, and it doesn't have to have thousands of special cases. It 
> > > > > > > tells
> > > > > > > you what the types are.
> > > > > > 
> > > > > > Hi  Peter,
> > > > > > 
> > > > > > I like that you in-line and bottom post.  You are a lot
> > > > > > easier to follow.
> > > > > > 
> > > > > > I think are talking at cross purposes.  Let me give an
> > > > > > example:
> > > > > > 
> > > > > > Q: is a "cow" a "Plant"?
> > > > > > A: a "cow" in not a hazel nut
> > > > > > A: a "cow" in not a radish
> > > > > > A: a "cow" in not a carrot
> > > > > > A: a "cow" in not a cabbage
> > > > > > ...
> > > > > > 
> > > > > > Are all of the answers a correct?
> > > > > > Yes.. Evey answer is completely correct.
> > > > > > 
> > > > > > Are any of the answers helpful?
> > > > > > No
> > > > > 
> > > > > Right. So, once again, just as I said, you are only interested in one 
> > > > > of
> > > > > the answers - "Str:U is not a Str:D, you want a Str:D". However, how
> > > > > should

Re: I reproduced one of the errors!

2020-06-01 Thread Peter Pentchev
On Mon, Jun 01, 2020 at 12:26:16PM +0300, Peter Pentchev wrote:
> On Mon, Jun 01, 2020 at 12:21:37PM +0300, Peter Pentchev wrote:
> > On Mon, Jun 01, 2020 at 01:15:23AM -0700, ToddAndMargo via perl6-users 
> > wrote:
[snip]
> > > Hi Peter,
> > > 
> > > I screw up A LOT.

And just in case this part isn't clear: this is fine. We all screw up
a lot. After more than thirty years of programming in more than twenty
different languages, I screw up a lot, all day, every day. I mess up
the syntax, I mess up the order of arguments to library functions that
I use all the time, I mess up the operator precedence... hell, just now,
when writing this simple program with the multi methods, first I forgot
that I had to call Thing.new to get an actual object (I tried with
"Thing()"... yeah, yeah, I also write Python, so sue me :)), and then
I forgot that I need to put "multi" there to define a, well, a multi
method :) And don't get me started on the *real* screw-ups I do now and
then, the ones that sometimes cost the company real money :)

So, yes. Screwing up is part of the game. I don't know a single
programmer who does not screw up every day.

I *really*, *really* like the way Raku handles my simple screw-ups.
Yes, it is a bit verbose sometimes, but it always helps me. Yes,
sometimes I have to think a little bit about what it is trying to tell
me, but then the lightbulb comes on and sometimes I learn something new
about the language :)

And yes, I understand how the verbose, detailed, and technical error
messages may seem a bit arcane to newcomers. Unfortunately, this is a
compromise that needs to be made when writing a compiler for a new
language: do you sit down and try to imagine all the ways that newcomers
will screw up, try to detect them, and try to give very, very helpful
messages, or do you give generic, but verbose messages with a lot of
detail? And, yeah, I know, this is another "trust me when I tell you
this" moment: I've dealt with compilers in other languages that have
tried to be very, very helpful, and while it does make things easy in
the beginning, in time you start to make not-so-simple mistakes and
the compiler doesn't *really* understand what you're trying to do... and
then it sends you on a *real* wild-goose chase by giving you an error
message that has *nothing* to do with the actual problem, because it
assumed that you were trying to do something that you were not.

So... yes. The Raku developers chose to go the detailed, verbose,
technical route. I actually like that. It takes some getting used to,
but once you've got some more accumulated knowledge, it *saves time*.

G'luck,
Peter

-- 
Peter Pentchev  r...@ringlet.net r...@debian.org p...@storpool.com
PGP key:http://people.FreeBSD.org/~roam/roam.key.asc
Key fingerprint 2EE7 A7A5 17FC 124C F115  C354 651E EFB0 2527 DF13


signature.asc
Description: PGP signature


Re: I reproduced one of the errors!

2020-06-01 Thread Peter Pentchev
On Mon, Jun 01, 2020 at 12:21:37PM +0300, Peter Pentchev wrote:
> On Mon, Jun 01, 2020 at 01:15:23AM -0700, ToddAndMargo via perl6-users wrote:
> > On 2020-05-31 17:13, Peter Pentchev wrote:
> > > On Mon, Jun 01, 2020 at 03:12:05AM +0300, Peter Pentchev wrote:
> > > > On Sun, May 31, 2020 at 04:29:55PM -0700, ToddAndMargo via perl6-users 
> > > > wrote:
> > > > > On 2020-05-31 04:58, Peter Pentchev wrote:
> > > > > > > > So my beef is when you feed these guys an undefined
> > > > > > > > variable, that they needs to tell you it requires
> > > > > > > > a "defined" variable.  Not a bunch of useless rubbish.
> > > > > > > > For example (useless rubbish):
> > > > > > And also... I thought I mentioned this before. You want a more clear
> > > > > > error message for*one*  *single*  specific case of a "can't find 
> > > > > > this
> > > > > > method, did you mean one of these?" error message. I tried to 
> > > > > > explain
> > > > > > that this error message is one that is displayed in many cases, not 
> > > > > > only
> > > > > > for "you passed an undefined thing, I want a defined thing"; in my
> > > > > > opinion, it is actually quite helpful in that it actually lists
> > > > > > the candidates in a "did you mean one of these?" style.
> > > > > > 
> > > > > > You want it to be clear if you pass an undefined value where a 
> > > > > > defined
> > > > > > value was expected; that would mean that somebody would have to 
> > > > > > write
> > > > > > the code to make it check whether it is this very specific case and 
> > > > > > then
> > > > > > that code would have to be maintained for years and years. Tomorrow
> > > > > > you'll say "but can't it give me a more clear message when I pass an
> > > > > > integer and it expected a string?" and the day after tomorrow 
> > > > > > you'll say
> > > > > > "but can't it give me a more clear message when I pass a string and 
> > > > > > it
> > > > > > expected a function?".
> > > > > > 
> > > > > > The error message says "you passed an object of this type, and I 
> > > > > > can't
> > > > > > find this method for this type; here are a couple of types that have
> > > > > > this method, did you mean one of these?"  It tells you what the 
> > > > > > types
> > > > > > are, and it doesn't have to have thousands of special cases. It 
> > > > > > tells
> > > > > > you what the types are.
> > > > > 
> > > > > Hi  Peter,
> > > > > 
> > > > > I like that you in-line and bottom post.  You are a lot
> > > > > easier to follow.
> > > > > 
> > > > > I think are talking at cross purposes.  Let me give an
> > > > > example:
> > > > > 
> > > > > Q: is a "cow" a "Plant"?
> > > > > A: a "cow" in not a hazel nut
> > > > > A: a "cow" in not a radish
> > > > > A: a "cow" in not a carrot
> > > > > A: a "cow" in not a cabbage
> > > > > ...
> > > > > 
> > > > > Are all of the answers a correct?
> > > > > Yes.. Evey answer is completely correct.
> > > > > 
> > > > > Are any of the answers helpful?
> > > > > No
> > > > 
> > > > Right. So, once again, just as I said, you are only interested in one of
> > > > the answers - "Str:U is not a Str:D, you want a Str:D". However, how
> > > > should Raku know *which* one of the answers you are interested in?
> > > > Tomorrow you may pass an integer to a function that only accepts strings
> > > > and floating-point numbers; should Raku tell you "you must pass a
> > > > string, not an integer" or "you must pass a floating-point number, not
> > > > an integer"? Raku doesn't know which one of those you meant.
> > > 
> > > ...accepts strings *or* floating-point numbers, of course...
> > > 
> > > G'luck,
> > > Peter
> 

Re: I reproduced one of the errors!

2020-06-01 Thread Peter Pentchev
On Mon, Jun 01, 2020 at 01:15:23AM -0700, ToddAndMargo via perl6-users wrote:
> On 2020-05-31 17:13, Peter Pentchev wrote:
> > On Mon, Jun 01, 2020 at 03:12:05AM +0300, Peter Pentchev wrote:
> > > On Sun, May 31, 2020 at 04:29:55PM -0700, ToddAndMargo via perl6-users 
> > > wrote:
> > > > On 2020-05-31 04:58, Peter Pentchev wrote:
> > > > > > > So my beef is when you feed these guys an undefined
> > > > > > > variable, that they needs to tell you it requires
> > > > > > > a "defined" variable.  Not a bunch of useless rubbish.
> > > > > > > For example (useless rubbish):
> > > > > And also... I thought I mentioned this before. You want a more clear
> > > > > error message for*one*  *single*  specific case of a "can't find this
> > > > > method, did you mean one of these?" error message. I tried to explain
> > > > > that this error message is one that is displayed in many cases, not 
> > > > > only
> > > > > for "you passed an undefined thing, I want a defined thing"; in my
> > > > > opinion, it is actually quite helpful in that it actually lists
> > > > > the candidates in a "did you mean one of these?" style.
> > > > > 
> > > > > You want it to be clear if you pass an undefined value where a defined
> > > > > value was expected; that would mean that somebody would have to write
> > > > > the code to make it check whether it is this very specific case and 
> > > > > then
> > > > > that code would have to be maintained for years and years. Tomorrow
> > > > > you'll say "but can't it give me a more clear message when I pass an
> > > > > integer and it expected a string?" and the day after tomorrow you'll 
> > > > > say
> > > > > "but can't it give me a more clear message when I pass a string and it
> > > > > expected a function?".
> > > > > 
> > > > > The error message says "you passed an object of this type, and I can't
> > > > > find this method for this type; here are a couple of types that have
> > > > > this method, did you mean one of these?"  It tells you what the types
> > > > > are, and it doesn't have to have thousands of special cases. It tells
> > > > > you what the types are.
> > > > 
> > > > Hi  Peter,
> > > > 
> > > > I like that you in-line and bottom post.  You are a lot
> > > > easier to follow.
> > > > 
> > > > I think are talking at cross purposes.  Let me give an
> > > > example:
> > > > 
> > > > Q: is a "cow" a "Plant"?
> > > > A: a "cow" in not a hazel nut
> > > > A: a "cow" in not a radish
> > > > A: a "cow" in not a carrot
> > > > A: a "cow" in not a cabbage
> > > > ...
> > > > 
> > > > Are all of the answers a correct?
> > > > Yes.. Evey answer is completely correct.
> > > > 
> > > > Are any of the answers helpful?
> > > > No
> > > 
> > > Right. So, once again, just as I said, you are only interested in one of
> > > the answers - "Str:U is not a Str:D, you want a Str:D". However, how
> > > should Raku know *which* one of the answers you are interested in?
> > > Tomorrow you may pass an integer to a function that only accepts strings
> > > and floating-point numbers; should Raku tell you "you must pass a
> > > string, not an integer" or "you must pass a floating-point number, not
> > > an integer"? Raku doesn't know which one of those you meant.
> > 
> > ...accepts strings *or* floating-point numbers, of course...
> > 
> > G'luck,
> > Peter
> > 
> 
> 
> Hi Peter,
> 
> I screw up A LOT.  When something REQUIRES "Str:D" and I
> send it a "Str:U", I want to be told such.  Not all
> the things it can't do, which I see thrashing around the
> protuberance of the scrubbary.
> 
>  starts-with's invocant requires a defined value (Str:D)
> 
> would be perfect.  Not appreciated is a list of all the
> things it can't do.  This makes me have to BOTH troubleshoot
> my screw up and the everything it can't do error message.
> 
> I think what you are trying to do is help me fix my screw
> ups, which is of course, much appreciate

Re: I reproduced one of the errors!

2020-05-31 Thread Peter Pentchev
On Mon, Jun 01, 2020 at 03:12:05AM +0300, Peter Pentchev wrote:
> On Sun, May 31, 2020 at 04:29:55PM -0700, ToddAndMargo via perl6-users wrote:
> > On 2020-05-31 04:58, Peter Pentchev wrote:
> > > > > So my beef is when you feed these guys an undefined
> > > > > variable, that they needs to tell you it requires
> > > > > a "defined" variable.  Not a bunch of useless rubbish.
> > > > > For example (useless rubbish):
> > > And also... I thought I mentioned this before. You want a more clear
> > > error message for*one*  *single*  specific case of a "can't find this
> > > method, did you mean one of these?" error message. I tried to explain
> > > that this error message is one that is displayed in many cases, not only
> > > for "you passed an undefined thing, I want a defined thing"; in my
> > > opinion, it is actually quite helpful in that it actually lists
> > > the candidates in a "did you mean one of these?" style.
> > > 
> > > You want it to be clear if you pass an undefined value where a defined
> > > value was expected; that would mean that somebody would have to write
> > > the code to make it check whether it is this very specific case and then
> > > that code would have to be maintained for years and years. Tomorrow
> > > you'll say "but can't it give me a more clear message when I pass an
> > > integer and it expected a string?" and the day after tomorrow you'll say
> > > "but can't it give me a more clear message when I pass a string and it
> > > expected a function?".
> > > 
> > > The error message says "you passed an object of this type, and I can't
> > > find this method for this type; here are a couple of types that have
> > > this method, did you mean one of these?"  It tells you what the types
> > > are, and it doesn't have to have thousands of special cases. It tells
> > > you what the types are.
> > 
> > Hi Peter,
> > 
> > I like that you in-line and bottom post.  You are a lot
> > easier to follow.
> > 
> > I think are talking at cross purposes.  Let me give an
> > example:
> > 
> > Q: is a "cow" a "Plant"?
> > A: a "cow" in not a hazel nut
> > A: a "cow" in not a radish
> > A: a "cow" in not a carrot
> > A: a "cow" in not a cabbage
> > ...
> > 
> > Are all of the answers a correct?
> > Yes.. Evey answer is completely correct.
> > 
> > Are any of the answers helpful?
> > No
> 
> Right. So, once again, just as I said, you are only interested in one of
> the answers - "Str:U is not a Str:D, you want a Str:D". However, how
> should Raku know *which* one of the answers you are interested in?
> Tomorrow you may pass an integer to a function that only accepts strings
> and floating-point numbers; should Raku tell you "you must pass a
> string, not an integer" or "you must pass a floating-point number, not
> an integer"? Raku doesn't know which one of those you meant.

...accepts strings *or* floating-point numbers, of course...

G'luck,
Peter

-- 
Peter Pentchev  r...@ringlet.net r...@debian.org p...@storpool.com
PGP key:http://people.FreeBSD.org/~roam/roam.key.asc
Key fingerprint 2EE7 A7A5 17FC 124C F115  C354 651E EFB0 2527 DF13


signature.asc
Description: PGP signature


Re: I reproduced one of the errors!

2020-05-31 Thread Peter Pentchev
On Sun, May 31, 2020 at 04:29:55PM -0700, ToddAndMargo via perl6-users wrote:
> On 2020-05-31 04:58, Peter Pentchev wrote:
> > > > So my beef is when you feed these guys an undefined
> > > > variable, that they needs to tell you it requires
> > > > a "defined" variable.  Not a bunch of useless rubbish.
> > > > For example (useless rubbish):
> > And also... I thought I mentioned this before. You want a more clear
> > error message for*one*  *single*  specific case of a "can't find this
> > method, did you mean one of these?" error message. I tried to explain
> > that this error message is one that is displayed in many cases, not only
> > for "you passed an undefined thing, I want a defined thing"; in my
> > opinion, it is actually quite helpful in that it actually lists
> > the candidates in a "did you mean one of these?" style.
> > 
> > You want it to be clear if you pass an undefined value where a defined
> > value was expected; that would mean that somebody would have to write
> > the code to make it check whether it is this very specific case and then
> > that code would have to be maintained for years and years. Tomorrow
> > you'll say "but can't it give me a more clear message when I pass an
> > integer and it expected a string?" and the day after tomorrow you'll say
> > "but can't it give me a more clear message when I pass a string and it
> > expected a function?".
> > 
> > The error message says "you passed an object of this type, and I can't
> > find this method for this type; here are a couple of types that have
> > this method, did you mean one of these?"  It tells you what the types
> > are, and it doesn't have to have thousands of special cases. It tells
> > you what the types are.
> 
> Hi Peter,
> 
> I like that you in-line and bottom post.  You are a lot
> easier to follow.
> 
> I think are talking at cross purposes.  Let me give an
> example:
> 
> Q: is a "cow" a "Plant"?
> A: a "cow" in not a hazel nut
> A: a "cow" in not a radish
> A: a "cow" in not a carrot
> A: a "cow" in not a cabbage
> ...
> 
> Are all of the answers a correct?
> Yes.. Evey answer is completely correct.
> 
> Are any of the answers helpful?
> No

Right. So, once again, just as I said, you are only interested in one of
the answers - "Str:U is not a Str:D, you want a Str:D". However, how
should Raku know *which* one of the answers you are interested in?
Tomorrow you may pass an integer to a function that only accepts strings
and floating-point numbers; should Raku tell you "you must pass a
string, not an integer" or "you must pass a floating-point number, not
an integer"? Raku doesn't know which one of those you meant.

G'luck,
Peter

-- 
Peter Pentchev  r...@ringlet.net r...@debian.org p...@storpool.com
PGP key:http://people.FreeBSD.org/~roam/roam.key.asc
Key fingerprint 2EE7 A7A5 17FC 124C F115  C354 651E EFB0 2527 DF13


signature.asc
Description: PGP signature


Re: I reproduced one of the errors!

2020-05-31 Thread Peter Pentchev
On Sun, May 31, 2020 at 04:06:28PM -0700, ToddAndMargo via perl6-users wrote:
> On 2020-05-31 12:48, Veesh Goldman wrote:
> > well, literally it would mean something like "a direct result of
> > inability to read is to not understand", which in context should mean if
> > you can't read you won't understand. But I think the point was made.
> 
> 
> Hi Veesh,
> 
> Please help me with my reading skills here.
> 
> https://docs.raku.org/routine/starts-with
> 
> multi method starts-with(Str:D: Str(Cool) $needle, :i(:$ignorecase),
> :m(:$ignoremark) --> Bool:D)
> 
> Does this or does this not state that the "Haystack"
> (invocant) is required to be defined ("Str:D:")?

Yes, it does. Good!

> If I am reading it correctly, is requires a "defined"
> ("D") Haystack (invocant).  Am I misreading something?

No, you're not - or at least, only slightly, see below.

> Running a test, the method DO NOT check for defined:
> 
> p6 'my $x; say $x.starts-with( "1" );'
> No such method 'starts-with' for invocant of type
> 'Any' in block  at -e line 1
> What am I misreading?  Does it say anywhere that the
> Haystack in not defined? Does it way anywhere that I
> violated the requirement that the Haystack be defined?
> 
> And what is "No such method 'starts-with'" suppose to
> mean?  I am staring at the method on right on the manual
> page.  Did the developers forget to include "opens-with"
> on my version of Raku?  Obvious it does not mean what
> it says.  Unless my reading skill really suck.

Try it with something slightly different, give Raku something to
work with :)

[roam@straylight ~]$ raku -e 'my Str $x; $x.starts-with("1")' 
Cannot resolve caller starts-with(Str:U: Str:D); none of these signatures match:
(Cool:D: Cool:D $needle, :i(:$ignorecase)!, :m(:$ignoremark), *%_ --> Bool)
(Cool:D: Cool:D $needle, :m(:$ignoremark)!, *%_ --> Bool)
(Cool:D: Cool:D $needle, *%_ --> Bool)
(Str:D: Str:D $needle, :i(:$ignorecase)!, :m(:$ignoremark), *%_ --> Bool)
(Str:D: Str:D $needle, :m(:$ignoremark)!, *%_ --> Bool)
(Str:D: Str:D $needle, *%_ --> Bool)
  in block  at -e line 1

[roam@straylight ~]$

The difference is that you said "my $x", thus making $x an undefined
variable of the "Any" type (since you did not specify a type), and
I said "my Str $x", thus making $x an undefined string. Once Raku knows
that $x is supposed to be a string, it can look for a .starts-with()
method in the Str class and in all its parent classes - and it finds
some methods in Str and some methods in the class named Cool.

> Also, lets add to my reading comprehension, the Needle:
>`Str(Cool) $needle`
> 
> I do not see "D" or "U" anywhere.  Am I missing something?
> 
> A test:
>  $ p6 'my $x; say "abc".starts-with( $x );'
>  Cannot resolve caller starts-with(Str:D: Any:U);
>  none of these signatures match: ...

Hm, this one is interesting. On the one hand, your test was once again
slightly wrong, once again you should have declared $x to be a Str.
On the other hand, even with the corrected test:

[roam@straylight ~]$ raku -e 'my Str $x; dd "abc".starts-with($x);'
Cannot resolve caller starts-with(Str:D: Str:U); none of these signatures match:
(Cool:D: Cool:D $needle, :i(:$ignorecase)!, :m(:$ignoremark), *%_ --> Bool)
(Cool:D: Cool:D $needle, :m(:$ignoremark)!, *%_ --> Bool)
(Cool:D: Cool:D $needle, *%_ --> Bool)
(Str:D: Str:D $needle, :i(:$ignorecase)!, :m(:$ignoremark), *%_ --> Bool)
(Str:D: Str:D $needle, :m(:$ignoremark)!, *%_ --> Bool)
(Str:D: Str:D $needle, *%_ --> Bool)
  in block  at -e line 1

[roam@straylight ~]$

And here we come to the interesting part: it seems that the
documentation is wrong here, since what Raku says is that the
.starts-with() method of the Str class really wants a `Str:D $needle` -
it does expect its argument to be defined.

> Okay, now it tells me "Any:U" for the needle.  It
> is telling me that I sent it a undefined value.  To
> me, that is a good troubleshooting hint.  Am I
> misreading it?

Well, it's actually telling you that you *passed* an Any:U object :)
Yes, it's telling you that it cannot find a method .starts-with() that
will accept an undefined object of the "Any" type as a parameter,
so, yeah, getting close :)

> Now what I would "like to see" (suggestion, not a demand),
> is the Haystack complain in a similar fashion.  For instance:
> 
> starts-with's invocant requires a defined value (Str:D)
> 
> Have I misread anything?

See above - you'll get this if you declare $x as a Str :)
But, yes, you're making progress, great!

G'luck,
Peter

-- 
Peter Pentchev  r...@ringlet.net r...@debian.org p...@storpool.com
PGP key:http://people.FreeBSD.org/~roam/roam.key.asc
Key fingerprint 2EE7 A7A5 17FC 124C F115  C354 651E EFB0 2527 DF13


signature.asc
Description: PGP signature


Re: I reproduced one of the errors!

2020-05-31 Thread Peter Pentchev
On Sun, May 31, 2020 at 02:53:45PM +0300, Peter Pentchev wrote:
> On Sat, May 30, 2020 at 04:22:56PM -0700, ToddAndMargo via perl6-users wrote:
> > On 2020-05-30 04:19, Peter Pentchev wrote:
> > > On Fri, May 29, 2020 at 04:36:41PM -0700, ToddAndMargo via perl6-users 
> > > wrote:
> > 
> > > > Hi Peter,
> > > > 
> > > > No doubt it is operating as designed.
> > > > 
> > > > It would be a lot more friendly if "Str:U" was
> > > > changed to "Str:D". Oh please!   Oh Please!
> > > 
> > > Sorry, I don't really understand what you mean.  "Str:U" means
> > > an undefined string - that's what you're calling .starts-with() on.
> > > "Str:D" means a defined string - that's what .starts-with() wants to
> > > operate on.  What do you mean "change Str:U to Str:D" - the error
> > > message says "you invoked it on an undefined string, it wants to be
> > > invoked on a defined string", what do you want to change?
> > > 
> > > Now, if you meant "change Str:U to 'an undefined string'", , what
> > > I was trying to explain is that the error message is generic, it covers
> > > any wrong calls of functions on any types... it does not really try to
> > > get into what the types are (it cannot, in the general case for any
> > > other type).
> > > 
> > > G'luck,
> > > Peter
> > > 
> > 
> > 
> > Hi Peter,
> 
> Apologies if what I write further down may come off as a little bit
> brusque. It's just that... see at the end, I'm getting a bit of
> deja vu here :)
> 
> [snip]
> > So my beef is when you feed these guys an undefined
> > variable, that they needs to tell you it requires
> > a "defined" variable.  Not a bunch of useless rubbish.
> > For example (useless rubbish):

And also... I thought I mentioned this before. You want a more clear
error message for *one* *single* specific case of a "can't find this
method, did you mean one of these?" error message. I tried to explain
that this error message is one that is displayed in many cases, not only
for "you passed an undefined thing, I want a defined thing"; in my
opinion, it is actually quite helpful in that it actually lists
the candidates in a "did you mean one of these?" style.

You want it to be clear if you pass an undefined value where a defined
value was expected; that would mean that somebody would have to write
the code to make it check whether it is this very specific case and then
that code would have to be maintained for years and years. Tomorrow
you'll say "but can't it give me a more clear message when I pass an
integer and it expected a string?" and the day after tomorrow you'll say
"but can't it give me a more clear message when I pass a string and it
expected a function?".

The error message says "you passed an object of this type, and I can't
find this method for this type; here are a couple of types that have
this method, did you mean one of these?"  It tells you what the types
are, and it doesn't have to have thousands of special cases. It tells
you what the types are.

> >Cannot resolve caller starts-with(Str:U: Str:D);
> 
> This is not useless rubbish. It says "you tried to call starts-with() on
> something that was an undefined string, and then you passed a defined
> string as a parameter."
> 
> >none of these signatures match
> > 
> >(Cool:D: Cool:D $needle, :i(:$ignorecase)!,
> >:m(:$ignoremark), *%_ --> Bool)
> 
> This is not useless rubbish. It says "you may call starts-with() on
> something that is defined and is of the "Cool" type and pass another
> defined "Cool" thing as a parameter, and then a couple of other
> parameters."
> 
> [snip]
> >(Str:D: Str:D $needle, :i(:$ignorecase)!,
> >:m(:$ignoremark), *%_ --> Bool)
> 
> This is not useless rubbish. It says "you may call starts-with() on
> something that is a defined string, and pass another defined string as a
> parameter, and then maybe a couple of other parameters."
> 
> > And I know, I don't get a vote on the matter.
> 
> It's not that you don't get a vote on the matter. It's that there have
> been several times (let's put it that way) when people have told you
> that to read the Raku documentation and to be able to fully use
> the powers of Raku, it would *really*, *really* help you to figure out
> those pesky signature things.
> 
> G'luck,
> Peter
> 
> -- 
> Peter Pentchev  r...@ringlet.net r...@debian.org p...@storpool.com
> PGP key:http://people.FreeBSD.org/~roam/roam.key.asc
> Key fingerprint 2EE7 A7A5 17FC 124C F115  C354 651E EFB0 2527 DF13



-- 
-- 
Peter Pentchev  r...@ringlet.net r...@debian.org p...@storpool.com
PGP key:http://people.FreeBSD.org/~roam/roam.key.asc
Key fingerprint 2EE7 A7A5 17FC 124C F115  C354 651E EFB0 2527 DF13


signature.asc
Description: PGP signature


Re: I reproduced one of the errors!

2020-05-31 Thread Peter Pentchev
On Sat, May 30, 2020 at 04:22:56PM -0700, ToddAndMargo via perl6-users wrote:
> On 2020-05-30 04:19, Peter Pentchev wrote:
> > On Fri, May 29, 2020 at 04:36:41PM -0700, ToddAndMargo via perl6-users 
> > wrote:
> 
> > > Hi Peter,
> > > 
> > > No doubt it is operating as designed.
> > > 
> > > It would be a lot more friendly if "Str:U" was
> > > changed to "Str:D". Oh please!   Oh Please!
> > 
> > Sorry, I don't really understand what you mean.  "Str:U" means
> > an undefined string - that's what you're calling .starts-with() on.
> > "Str:D" means a defined string - that's what .starts-with() wants to
> > operate on.  What do you mean "change Str:U to Str:D" - the error
> > message says "you invoked it on an undefined string, it wants to be
> > invoked on a defined string", what do you want to change?
> > 
> > Now, if you meant "change Str:U to 'an undefined string'", , what
> > I was trying to explain is that the error message is generic, it covers
> > any wrong calls of functions on any types... it does not really try to
> > get into what the types are (it cannot, in the general case for any
> > other type).
> > 
> > G'luck,
> > Peter
> > 
> 
> 
> Hi Peter,

Apologies if what I write further down may come off as a little bit
brusque. It's just that... see at the end, I'm getting a bit of
deja vu here :)

[snip]
> So my beef is when you feed these guys an undefined
> variable, that they needs to tell you it requires
> a "defined" variable.  Not a bunch of useless rubbish.
> For example (useless rubbish):
> 
>Cannot resolve caller starts-with(Str:U: Str:D);

This is not useless rubbish. It says "you tried to call starts-with() on
something that was an undefined string, and then you passed a defined
string as a parameter."

>none of these signatures match
> 
>(Cool:D: Cool:D $needle, :i(:$ignorecase)!,
>:m(:$ignoremark), *%_ --> Bool)

This is not useless rubbish. It says "you may call starts-with() on
something that is defined and is of the "Cool" type and pass another
defined "Cool" thing as a parameter, and then a couple of other
parameters."

[snip]
>(Str:D: Str:D $needle, :i(:$ignorecase)!,
>:m(:$ignoremark), *%_ --> Bool)

This is not useless rubbish. It says "you may call starts-with() on
something that is a defined string, and pass another defined string as a
parameter, and then maybe a couple of other parameters."

> And I know, I don't get a vote on the matter.

It's not that you don't get a vote on the matter. It's that there have
been several times (let's put it that way) when people have told you
that to read the Raku documentation and to be able to fully use
the powers of Raku, it would *really*, *really* help you to figure out
those pesky signature things.

G'luck,
Peter

-- 
Peter Pentchev  r...@ringlet.net r...@debian.org p...@storpool.com
PGP key:http://people.FreeBSD.org/~roam/roam.key.asc
Key fingerprint 2EE7 A7A5 17FC 124C F115  C354 651E EFB0 2527 DF13


signature.asc
Description: PGP signature


Re: I reproduced one of the errors!

2020-05-30 Thread Peter Pentchev
On Fri, May 29, 2020 at 04:36:41PM -0700, ToddAndMargo via perl6-users wrote:
> On 2020-05-28 06:39, Peter Pentchev wrote:
> > On Wed, May 27, 2020 at 03:12:01PM -0700, ToddAndMargo via perl6-users 
> > wrote:
> > > > On 2020-05-27 14:32, Andy Bach wrote:
> > > > > #!/usr/bin/env raku
> > > > > my Str $x;
> > > > > if $x.starts-with( "[" )  &&
> > > > > $x.contains( "]" )
> > > > > { say "Passed"; } else { say "Failed"; }
> > > > > 
> > > > > K:\Windows\NtUtil>raku Contains.Test.pl6
> > > > > Cannot resolve caller starts-with(Str:U: Str:D); none of these
> > > > > signatures match
> > > > > 
> > > > > (Cool:D: Cool:D $needle, :i(:$ignorecase)!, :m(:$ignoremark), *%_
> > > > > --> Bool)
> > > > > (Cool:D: Cool:D $needle, :m(:$ignoremark)!, *%_ --> Bool)
> > > > > (Cool:D: Cool:D $needle, *%_ --> Bool)
> > > > > (Str:D: Str:D $needle, :i(:$ignorecase)!, :m(:$ignoremark), *%_ -->
> > > > > Bool)
> > > > > (Str:D: Str:D $needle, :m(:$ignoremark)!, *%_ --> Bool)
> > > > > (Str:D: Str:D $needle, *%_ --> Bool)
> > > > > in block  at Contains.Test.pl6 line 3
> > > > > 
> > > > >   > The function should just complain that the variable is not 
> > > > > initialized.
> > > > > 
> > > 
> > > 
> > > > Well, it is:
> > > > Cannot resolve caller starts-with(Str:U: Str:D);
> > > > ...
> > > > in block  at Contains.Test.pl6 line 3
> > > > 
> > > > it says:
> > > > For line 3:
> > > > if $x.starts-with( "[" )
> > > > looking for a possible method 'starts-with' with a signature of 2
> > > > params; an undefined string ('Str:U:') and a defined one ('Str:D:')
> > > > failed - here's the list of the possible signatures raku currently has
> > > > ..."
> > > > 
> > > > I'd not be surprise if you could write your own "starts-with(Str:U:
> > > > Str:D); " method in raku and take care of this.  You could probably even
> > > > have it "say"
> > > > You have an undefined String var in this call, not going to be able to
> > > > do much useful matching against that.  Did you forget to initialize
> > > > something?
> > > 
> > > Hi Andy,
> > > 
> > > The function should just complain that you need to feed it an
> > > initialized value instead of sending you on a wild goose chase,
> > 
> > It does say that you are trying to call "starts-with()" as a method on
> > a value of type Str:U (undefined string), and it cannot find such
> > a method. It also tells you what methods it can find.
> > 
> > It gives the same error message no matter what types the function/method
> > can handle and no matter what type you are trying to call it on.
> >  From that point on Raku kind of expects you to know what Str:U means and
> > that the :U part means "undefined". It would give the same *type* of
> > message if you were trying to call a method that only works on undefined
> > strings and you were trying to call it on a defined string, only then it
> > would say that it can't find such a method for Str:D. In the eyes of
> > Raku, these errors are of the same kind, and it has provided you with
> > the types.
> 
> Hi Peter,
> 
> No doubt it is operating as designed.
> 
> It would be a lot more friendly if "Str:U" was
> changed to "Str:D". Oh please!   Oh Please!

Sorry, I don't really understand what you mean.  "Str:U" means
an undefined string - that's what you're calling .starts-with() on.
"Str:D" means a defined string - that's what .starts-with() wants to
operate on.  What do you mean "change Str:U to Str:D" - the error
message says "you invoked it on an undefined string, it wants to be
invoked on a defined string", what do you want to change?

Now, if you meant "change Str:U to 'an undefined string'", , what
I was trying to explain is that the error message is generic, it covers
any wrong calls of functions on any types... it does not really try to
get into what the types are (it cannot, in the general case for any
other type).

G'luck,
Peter

-- 
Peter Pentchev  r...@ringlet.net r...@debian.org p...@storpool.com
PGP key:http://people.FreeBSD.org/~roam/roam.key.asc
Key fingerprint 2EE7 A7A5 17FC 124C F115  C354 651E EFB0 2527 DF13


signature.asc
Description: PGP signature


Re: I need help with Config:INI

2020-05-30 Thread Peter Pentchev
On Fri, May 29, 2020 at 05:02:15PM -0700, ToddAndMargo via perl6-users wrote:
> Hi All,
> 
> I an not figure out how to read the hash.
> 
> 
> ~~~ ini.test.pl6.ini ~
> # Raku: Confug::INI test INI
> # edit at your own risk
> 
> [Backup paramters]
> target=B:\myDocsBackp\backup1
> partition=BACKUP
> 
> [eMail]
> smtp=smtp.bozo.com
> address=b...@theclown.com
> port=587
> ~~~ /ini.test.pl6.ini ~
> 
> 
> ~~~ ini.test.pl6 ~
> #! /usr/bin/env raku
> 
> #`{
> # zef install Config
> # zef install Config::INI
> 
> 
> 
> https://github.com/tadzik/perl6-Config-INI/blob/master/lib/Config/INI.pm
> line 45 starts documtation
> 
> use Config::INI;
> my %hash = Config::INI::parse_file('config.ini');
> #or
> %hash = Config::INI::parse($file_contents);
> say %hash<_>;
> say %hash;
> 
> This module provides 2 functions: parse() and parse_file(), both taking
> one C argument, where parse_file is just parse(slurp $file).
> Both return a hash which keys are either toplevel keys or a section
> names. For example, the following config file:
> 
> foo=bar
> [section]
> another=thing
> 
> would result in the following hash:
> }
> #   { '_' => { foo => "bar" }, section => { another => "thing" } }
> 
> 
> use Config;
> use Config::INI;
> 
> my Str $IniFile = slurp "ini.test.pl6.ini";
> my %hash = Config::INI::parse($IniFile);
> 
> dd %hash;
> print "\n";
> 
> for %hash.kv -> $key, $value  { print "   hash<$key> = [$value]\n\n"; }
> print "\n";
> ~~~ /ini.test.pl6 ~
> 
> ~ run the test 
> $ ini.test.pl6
> 
> Hash %hash = {"Backup paramters" => ${:partition("BACKUP"),
> :target("B:\\myDocsBackp\\backup1")},
> :eMail(${:address("bozo\@theclown.com"), :port("587"),
> :smtp("smtp.bozo.com")})}
> 
>hash = [partitionBACKUP
> targetB:\myDocsBackp\backup1]
> 
>hash = [address b...@theclown.com
> port  587
> smtp  smtp.bozo.com]
> ~ /run the test 
> 
> 
> How do I read the hash so I get section
> `[eMail]` `smtp`?  (Or any of the other values
> as well.)

If you want that specific value, dd %hash
If some of the keys are in variables, try this:

my $section = "eMail";
my $key = "smtp";
dd %hash{$section}{$key};

So %hash is a hash of hashes: the keys of %hash are the names of
the sections, the values are hashes containing the key/value contents of
the sections. The keys of %hash are the names of the variables
defined in the "eMail" section, the values of %hash are the,
well, values of the things in the "eMail" section.

G'luck,
Peter

-- 
Peter Pentchev  r...@ringlet.net r...@debian.org p...@storpool.com
PGP key:http://people.FreeBSD.org/~roam/roam.key.asc
Key fingerprint 2EE7 A7A5 17FC 124C F115  C354 651E EFB0 2527 DF13


signature.asc
Description: PGP signature


Re: I reproduced one of the errors!

2020-05-28 Thread Peter Pentchev
On Wed, May 27, 2020 at 03:12:01PM -0700, ToddAndMargo via perl6-users wrote:
> > On 2020-05-27 14:32, Andy Bach wrote:
> > > #!/usr/bin/env raku
> > > my Str $x;
> > > if $x.starts-with( "[" )  &&
> > > $x.contains( "]" )
> > > { say "Passed"; } else { say "Failed"; }
> > > 
> > > K:\Windows\NtUtil>raku Contains.Test.pl6
> > > Cannot resolve caller starts-with(Str:U: Str:D); none of these
> > > signatures match
> > > 
> > > (Cool:D: Cool:D $needle, :i(:$ignorecase)!, :m(:$ignoremark), *%_
> > > --> Bool)
> > > (Cool:D: Cool:D $needle, :m(:$ignoremark)!, *%_ --> Bool)
> > > (Cool:D: Cool:D $needle, *%_ --> Bool)
> > > (Str:D: Str:D $needle, :i(:$ignorecase)!, :m(:$ignoremark), *%_ -->
> > > Bool)
> > > (Str:D: Str:D $needle, :m(:$ignoremark)!, *%_ --> Bool)
> > > (Str:D: Str:D $needle, *%_ --> Bool)
> > > in block  at Contains.Test.pl6 line 3
> > > 
> > >  > The function should just complain that the variable is not initialized.
> > > 
> 
> 
> > Well, it is:
> > Cannot resolve caller starts-with(Str:U: Str:D);
> > ...
> > in block  at Contains.Test.pl6 line 3
> > 
> > it says:
> > For line 3:
> > if $x.starts-with( "[" )
> > looking for a possible method 'starts-with' with a signature of 2
> > params; an undefined string ('Str:U:') and a defined one ('Str:D:')
> > failed - here's the list of the possible signatures raku currently has
> > ..."
> > 
> > I'd not be surprise if you could write your own "starts-with(Str:U:
> > Str:D); " method in raku and take care of this.  You could probably even
> > have it "say"
> > You have an undefined String var in this call, not going to be able to
> > do much useful matching against that.  Did you forget to initialize
> > something?
> 
> Hi Andy,
> 
> The function should just complain that you need to feed it an
> initialized value instead of sending you on a wild goose chase,

It does say that you are trying to call "starts-with()" as a method on
a value of type Str:U (undefined string), and it cannot find such
a method. It also tells you what methods it can find.

It gives the same error message no matter what types the function/method
can handle and no matter what type you are trying to call it on.
From that point on Raku kind of expects you to know what Str:U means and
that the :U part means "undefined". It would give the same *type* of
message if you were trying to call a method that only works on undefined
strings and you were trying to call it on a defined string, only then it
would say that it can't find such a method for Str:D. In the eyes of
Raku, these errors are of the same kind, and it has provided you with
the types.

G'luck,
Peter

-- 
Peter Pentchev  r...@ringlet.net r...@debian.org p...@storpool.com
PGP key:http://people.FreeBSD.org/~roam/roam.key.asc
Key fingerprint 2EE7 A7A5 17FC 124C F115  C354 651E EFB0 2527 DF13


signature.asc
Description: PGP signature


Re: I need a second pair of eyes

2020-05-27 Thread Peter Pentchev
On Tue, May 26, 2020 at 07:16:54PM -0700, ToddAndMargo via perl6-users wrote:
> On 2020-05-25 23:42, ToddAndMargo via perl6-users wrote:
> > HI All,
> > 
> > I am missing something here:
> > 
> > 
> > 154:   # figure out the label
> > 155:   say %CommandLine;
> > 156:   if "%CommandLine".starts-with( "[" )  &&
> > 157:  "%CommandLine".contains( "]" ) {
> > 
> > 
> > BACKUP:\MyDocsBackup\backup1
[snip]
> 
> 
> Follow up:
> 
> This turned ot the be the same issue as the other on:
> 
> say %CommandLine;
> BACKUP:\MyDocsBackup\backup1
> 
> Was not the actual case.  %CommandLine
> was actually blank.
> 
> I need to start using `print` instead of `say` to
> proof things.
> 
> Thank you all for the help and tips!

This is... strange. Are you really, really sure that the "say" and
the "print" were really used on the same variable with the same value?
And the value is supposed to be a (possibly undefined) string?
And when the value is an undefined string (and nothing changes it after
"say" is called on it), "say" outputs something that looks like
a valid path?

This would be really, really strange. I'd say it would qualify as a bug,
unless there is something else happening there.

Are you really, really, really sure that there is nothing between
the call to "say" and the place where you use the variable that could
change the value? Are you also really, really, really sure that you have
not mistyped one of the names? If so, is there a way you could create
a minimal example, a short program that, when run on your system, always
behaves this way, and post it (attach the source file, don't retype it)
in full, so that people can try to run it on their systems and see if
"say" really does something strange?

G'luck,
Peter

-- 
Peter Pentchev  r...@ringlet.net r...@debian.org p...@storpool.com
PGP key:http://people.FreeBSD.org/~roam/roam.key.asc
Key fingerprint 2EE7 A7A5 17FC 124C F115  C354 651E EFB0 2527 DF13


signature.asc
Description: PGP signature


Re: I need help with IO.e

2020-05-19 Thread Peter Pentchev
On Tue, May 19, 2020 at 03:16:41PM +0300, Peter Pentchev wrote:
> On Mon, May 18, 2020 at 10:58:26PM -0700, ToddAndMargo via perl6-users wrote:
> > On 2020-05-18 17:14, Peter Pentchev wrote:
> > > On Mon, May 18, 2020 at 04:53:31PM -0700, ToddAndMargo via perl6-users 
> > > wrote:
> > > > In 2020-05-18 16:11, Peter Pentchev wrote:
> > > > > As an exercise for the reader: once the above sinks in, what exactly
> > > > > will "say if 'h:/'.IO.d" do?
> > > > 
> > > > It returns the the result of the expression that
> > > > "if" evaluated.
> > > 
> > > OK, so why does it give you an error message if you run it? :)
> > > 
> > > Not quite.
> > > 
> > >  say if 'h:/'.IO.d
> > > 
> > > ...is equivalent to:
> > > 
> > >  if 'h:/'.IO.d {
> > >  say;
> > >  }
> > > 
> > > which would have been valid in Perl (apart from the parentheses
> > > around the condition of the "if", Raku allows you to omit those), but
> > > it is not valid Raku. Run it and see what it says.
> > > 
> > > Once again you thought that "if" returns a value. "If" does not return
> > > a value, it is not a function, it is a statement. Just the same as "for"
> > > does not return a value, and "while" does not return a value.
> > > 
> > > G'luck,
> > > Peter
> > > 
> > 
> > Hi Peter,
> > 
> > Of course!  I am not arguing with anyone that
> > they are not right!
> > 
> > I am doing what I am doing to make things easier for
> > me to read in the future.  Since I am already using
> > a very high level language, what is one more affront
> > to my CPU?
> 
> Todd, I'm trying to tell you that you seem to misunderstand
> what "if" does. Please read my answer again: your idea of
> what "say if 'h:/'.IO.d" does is incorrect, "if" does not do
> what you think it does, and this is *essential* for understanding
> and writing Raku programs (or programs in pretty much any other
> language). Understanding the difference between functions and
> control statements is *essential*.

...control structures, I mean.

G'luck,
Peter

-- 
Peter Pentchev  r...@ringlet.net r...@debian.org p...@storpool.com
PGP key:http://people.FreeBSD.org/~roam/roam.key.asc
Key fingerprint 2EE7 A7A5 17FC 124C F115  C354 651E EFB0 2527 DF13


signature.asc
Description: PGP signature


Re: I need help with IO.e

2020-05-19 Thread Peter Pentchev
On Mon, May 18, 2020 at 10:58:26PM -0700, ToddAndMargo via perl6-users wrote:
> On 2020-05-18 17:14, Peter Pentchev wrote:
> > On Mon, May 18, 2020 at 04:53:31PM -0700, ToddAndMargo via perl6-users 
> > wrote:
> > > In 2020-05-18 16:11, Peter Pentchev wrote:
> > > > As an exercise for the reader: once the above sinks in, what exactly
> > > > will "say if 'h:/'.IO.d" do?
> > > 
> > > It returns the the result of the expression that
> > > "if" evaluated.
> > 
> > OK, so why does it give you an error message if you run it? :)
> > 
> > Not quite.
> > 
> >  say if 'h:/'.IO.d
> > 
> > ...is equivalent to:
> > 
> >  if 'h:/'.IO.d {
> >  say;
> >  }
> > 
> > which would have been valid in Perl (apart from the parentheses
> > around the condition of the "if", Raku allows you to omit those), but
> > it is not valid Raku. Run it and see what it says.
> > 
> > Once again you thought that "if" returns a value. "If" does not return
> > a value, it is not a function, it is a statement. Just the same as "for"
> > does not return a value, and "while" does not return a value.
> > 
> > G'luck,
> > Peter
> > 
> 
> Hi Peter,
> 
> Of course!  I am not arguing with anyone that
> they are not right!
> 
> I am doing what I am doing to make things easier for
> me to read in the future.  Since I am already using
> a very high level language, what is one more affront
> to my CPU?

Todd, I'm trying to tell you that you seem to misunderstand
what "if" does. Please read my answer again: your idea of
what "say if 'h:/'.IO.d" does is incorrect, "if" does not do
what you think it does, and this is *essential* for understanding
and writing Raku programs (or programs in pretty much any other
language). Understanding the difference between functions and
control statements is *essential*.

G'luck,
Peter

-- 
Peter Pentchev  r...@ringlet.net r...@debian.org p...@storpool.com
PGP key:http://people.FreeBSD.org/~roam/roam.key.asc
Key fingerprint 2EE7 A7A5 17FC 124C F115  C354 651E EFB0 2527 DF13


signature.asc
Description: PGP signature


Re: I need help with IO.e

2020-05-18 Thread Peter Pentchev
On Mon, May 18, 2020 at 04:53:31PM -0700, ToddAndMargo via perl6-users wrote:
> In 2020-05-18 16:11, Peter Pentchev wrote:
> > As an exercise for the reader: once the above sinks in, what exactly
> > will "say if 'h:/'.IO.d" do?
> 
> It returns the the result of the expression that
> "if" evaluated.

OK, so why does it give you an error message if you run it? :)

Not quite.

say if 'h:/'.IO.d

...is equivalent to:

if 'h:/'.IO.d {
say;
}

which would have been valid in Perl (apart from the parentheses
around the condition of the "if", Raku allows you to omit those), but
it is not valid Raku. Run it and see what it says.

Once again you thought that "if" returns a value. "If" does not return
a value, it is not a function, it is a statement. Just the same as "for"
does not return a value, and "while" does not return a value.

G'luck,
Peter

-- 
Peter Pentchev  r...@ringlet.net r...@debian.org p...@storpool.com
PGP key:http://people.FreeBSD.org/~roam/roam.key.asc
Key fingerprint 2EE7 A7A5 17FC 124C F115  C354 651E EFB0 2527 DF13


signature.asc
Description: PGP signature


Re: I need help with IO.e

2020-05-18 Thread Peter Pentchev
On Mon, May 18, 2020 at 03:51:30PM -0700, ToddAndMargo via perl6-users wrote:
> On 2020-05-18 15:44, Tom Browder wrote:
> > On Mon, May 18, 2020 at 16:19 ToddAndMargo via perl6-users
> > mailto:perl6-us...@perl.org>> wrote:
> > 
> > On 2020-05-18 13:28, Tom Browder wrote:
> > 
> > ...
> > 
> >  > Try:
> >  >
> >  > 'say so "test".IO.d'
> > 
> > 
> > Todd, you didn't try what I suggested. Once again, look a the line above^^
> > 
> > There is no "if" there.
> > 
> > -Tom
> > 
> 
> It was the "if" I was interested in.  "if" has to change
> a True or "useless text message" into a True or False.

No, that's not what "if" does. "If" in Raku works pretty much
the same way as "if" in Perl: it takes an expression as
an argument, checks whether the expression is true or false
(that's the part where it takes any value and does a .Bool on
it - by itself - and then looks at the result), and then, if
it was true, the "if" statement runs another part of the code.
So:

if 'h:/'.IO.d {
say 'It is a directory!';
}

...will take the string 'h:/', the .IO method will convert it to
a path, the .d method will check whether the path corresponds to
a valid directory at this moment, and then the "if" statement will
check the result of this whole thing and decide whether to run
the { say... } block. If the path is a directory, it will tell you
that it is a directory. If the expression is true, it runs the code.

The postfix "if" also works in pretty much the same way as in Perl:
it allows you to shorten this:

if 'h:/'.IO.d {
say 'It is a directory!';
}

...to this:

say 'It is a directory!' if 'h:/'.IO.d;

Now you will note that in my example I did *not* write
"say if 'h:/'.IO.d", because I did not expect the "if" to return
a value; I wrote "say 'foo' if 'h:/'.IO.d" since I expected the "if"
statement to make Raku check whether 'h:/'.IO.d returns something that
looks like truth and, if it does, to execute the "say 'foo'" part.

I'm sorry, I assumed that you were familiar with the postfix "if" form
(something if something-else). Maybe you did not recognize it as such,
sorry.

As an exercise for the reader: once the above sinks in, what exactly
will "say if 'h:/'.IO.d" do? :)

G'luck,
Peter

-- 
Peter Pentchev  r...@ringlet.net r...@debian.org p...@storpool.com
PGP key:http://people.FreeBSD.org/~roam/roam.key.asc
Key fingerprint 2EE7 A7A5 17FC 124C F115  C354 651E EFB0 2527 DF13


signature.asc
Description: PGP signature


Re: I need help with IO.e

2020-05-18 Thread Peter Pentchev
On Mon, May 18, 2020 at 03:18:26PM -0700, ToddAndMargo via perl6-users wrote:
> On 2020-05-18 14:35, Peter Pentchev wrote:
> > My point is that you put a bare "say" without telling it*what*  to say,
> > which does something quite specific in both Perl and Raku. That should,
> > at least, explain the error-like message.
> > 
> > G'luck,
> > Peter
> 
> What I was after was to see what impact I had coercing a
> Bool to a Bool verses coercing a half a Bool and unless
> text message to a Bool.
[snip another explanation of why you use .Bool, which I already
 said that I am not commenting on; my point is something entirely
 different]

All I was trying to say was to explain that "say if something" and
"say 'foo' if something" do different things, to answer your question
from a previous message why "say if something" told you something
about undefined values. That's all I was trying to help you with :)

G'luck,
Peter

-- 
Peter Pentchev  r...@ringlet.net r...@debian.org p...@storpool.com
PGP key:http://people.FreeBSD.org/~roam/roam.key.asc
Key fingerprint 2EE7 A7A5 17FC 124C F115  C354 651E EFB0 2527 DF13


signature.asc
Description: PGP signature


Re: I need help with IO.e

2020-05-18 Thread Peter Pentchev
On Mon, May 18, 2020 at 02:32:49PM -0700, ToddAndMargo via perl6-users wrote:
> On 2020-05-18 14:22, Peter Pentchev wrote:
> > Please note that in my example a couple of messages ago I did not write
> > "say if 'h:/'.IO.d", I wrote "say 'yes' if 'h:/'.IO.d". The difference
> > is very important and leads directly to the error-like message you got.
> 
> 
> Hi Peter,
> 
> I as interested in the .d difference, so I put that
> in instead.
> 
> But it does not matter.  I can't tell what I am looking at
> so it does not matter anyway

My point is that you put a bare "say" without telling it *what* to say,
which does something quite specific in both Perl and Raku. That should,
at least, explain the error-like message.

G'luck,
Peter

-- 
Peter Pentchev  r...@ringlet.net r...@debian.org p...@storpool.com
PGP key:http://people.FreeBSD.org/~roam/roam.key.asc
Key fingerprint 2EE7 A7A5 17FC 124C F115  C354 651E EFB0 2527 DF13


signature.asc
Description: PGP signature


Re: I need help with IO.e

2020-05-18 Thread Peter Pentchev
On Tue, May 19, 2020 at 12:22:55AM +0300, Peter Pentchev wrote:
> On Mon, May 18, 2020 at 12:35:47PM -0700, ToddAndMargo via perl6-users wrote:
> > On 2020-05-17 22:28, Paul Procacci wrote:
> > > Don't 'say' anything.  Just let the optimizer spit out the QAST that you
> > > are interested in looking at.
> > > The following spits out a diff after optimization:
> > > 
> > > # diff -u <(perl6 --target=optimize -e '"test".IO.e') <(perl6
> > > --target=optimize -e '"test".IO.e.Bool')
> > > 
> > >  >> Huh.  Not sure what I am looking at
> > > 
> > > You aren't specific.  Is it the error message you received because you
> > > used 'say' improperly or is it the QAST?
> > > - How to use 'say' is in the documentation.
> > > - A QAST is pretty close to an AST and I'd start there on wikipedia or
> > > something.
> > 
> > I was looking for the difference between
> > 
> > 'say if "test".IO.d',  and
> 
> Please note that in my example a couple of messages ago I did not write
> "say if 'h:/'.IO.d", I wrote "say 'yes' if 'h:/'.IO.d". The difference
> is very important and leads directly to the error-like message you got.
> 
> > 'say "test".IO.d.Bool'
> > 
> > This is were 'if" has to unscramble a "True" or
> > "text message" return.
> > 
> > But, I have no idea what all that stuff is that comes
> > back anyway, so I think I will give up.
> 
> It's the internal representation of the program you told Raku to parse
> and execute; the truth is that, just like in a sci-fi story about
> a machine that is supposed to answer any question, but only comes back
> with "the question has not been asked correctly", ...

In case anybody is curious,
http://www.gutenberg.org/cache/epub/33854/pg33854.txt

G'luck,
Peter

-- 
Peter Pentchev  r...@ringlet.net r...@debian.org p...@storpool.com
PGP key:http://people.FreeBSD.org/~roam/roam.key.asc
Key fingerprint 2EE7 A7A5 17FC 124C F115  C354 651E EFB0 2527 DF13


signature.asc
Description: PGP signature


Re: I need help with IO.e

2020-05-18 Thread Peter Pentchev
On Mon, May 18, 2020 at 12:35:47PM -0700, ToddAndMargo via perl6-users wrote:
> On 2020-05-17 22:28, Paul Procacci wrote:
> > Don't 'say' anything.  Just let the optimizer spit out the QAST that you
> > are interested in looking at.
> > The following spits out a diff after optimization:
> > 
> > # diff -u <(perl6 --target=optimize -e '"test".IO.e') <(perl6
> > --target=optimize -e '"test".IO.e.Bool')
> > 
> >  >> Huh.  Not sure what I am looking at
> > 
> > You aren't specific.  Is it the error message you received because you
> > used 'say' improperly or is it the QAST?
> > - How to use 'say' is in the documentation.
> > - A QAST is pretty close to an AST and I'd start there on wikipedia or
> > something.
> 
> I was looking for the difference between
> 
> 'say if "test".IO.d',  and

Please note that in my example a couple of messages ago I did not write
"say if 'h:/'.IO.d", I wrote "say 'yes' if 'h:/'.IO.d". The difference
is very important and leads directly to the error-like message you got.

> 'say "test".IO.d.Bool'
> 
> This is were 'if" has to unscramble a "True" or
> "text message" return.
> 
> But, I have no idea what all that stuff is that comes
> back anyway, so I think I will give up.

It's the internal representation of the program you told Raku to parse
and execute; the truth is that, just like in a sci-fi story about
a machine that is supposed to answer any question, but only comes back
with "the question has not been asked correctly", and just as with using
low-level debugging tools like strace on Unix-like systems, to ask
the right question one already needs to know most of the answer.
The QAST is most useful to those who already have some idea how
a compiler generally works, how a pseudocode virtual machine works,
how a just-in-time compiler works, and how they all handle different
expressions and the relationships between different types.

G'luck,
Peter

-- 
-- 
Peter Pentchev  r...@ringlet.net r...@debian.org p...@storpool.com
PGP key:http://people.FreeBSD.org/~roam/roam.key.asc
Key fingerprint 2EE7 A7A5 17FC 124C F115  C354 651E EFB0 2527 DF13


signature.asc
Description: PGP signature


Re: I need help with IO.e

2020-05-17 Thread Peter Pentchev
On Sun, May 17, 2020 at 12:12:51PM -0700, ToddAndMargo via perl6-users wrote:
> On 2020-05-17 03:36, Peter Pentchev wrote:
> > On Sun, May 17, 2020 at 03:01:34AM -0700, ToddAndMargo via perl6-users 
> > wrote:
> > > On 2020-05-17 02:30, Peter Pentchev wrote:
> > > > You said that you would tack Bool at the end in "if" statements, too.
> > > 
> > > Hi Peter,
> > > 
> > > No wonder.  I do not remember saying that, but I could
> > > have.  My `if` statements look like:
> > > 
> > > if not  "%Options".IO.d.Bool  {
> > >say "Creating %Options";
> > >mkdir( %Options", 0o777 );
> > > }
> > > 
> > > I definitely do not tack .Bool onto the end
> > > of my `if` statements.
> > 
> > Uh. That's exactly what you're doing. You do *not* need the .Bool
> > there at the end. The "not" makes Raku convert whatever is there
> > to a boolean, so the .Bool is implicit. And if you were to check
> > the other way, if you had "if $foo.IO.d { ... }", then the "if"
> > makes Raku convert whatever is there to a boolean, so the .Bool is
> > implicit. You do not need to put the .Bool in an "if" or a "while"
> > statement.
> > 
> > G'luck,
> > Peter
> > 
> 
> Hi Peter,
> 
> Brad asked me the same thing on another thread.  This is what I
> told him:
> 
> Hi Brad,
> 
> I do this because it keeps me out of trouble.
> 
> I want back a yes or no answer, not True or Fail
> (X::IO::DoesNotExist).
> 
> And I never remember which IO. will return
> a True or Fail or which functions (`if` does) will
> convert X::IO::DoesNotExist to a False for me.

OK, so I promise to the group that this is my last message on this
particular topic :)

Todd, you won't have to remember anything if you *only* use .IO.d and
.IO.e and all the rest the way the rest of the world uses them: *only*
in conditional statements. Your examples could have been written as:

raku -e "say 'yes' if 'h:/'.IO.d"

...and you would not have to remember anything except that .IO.d, .e,
.f, and the rest of these predicates only need to be used in
conditionals. This covers 'if', 'while', and it also covers stuff like
"my $final-decision = $path.IO.d and $path.IO.w", since this is also
using the predicates in a sort of a conditional statement. Basically,
in any *real-world* situation where you'd want to use them, you don't
need the explicit conversion to boolean.

Hope that helps.

G'luck,
Peter

-- 
Peter Pentchev  r...@ringlet.net r...@debian.org p...@storpool.com
PGP key:http://people.FreeBSD.org/~roam/roam.key.asc
Key fingerprint 2EE7 A7A5 17FC 124C F115  C354 651E EFB0 2527 DF13


signature.asc
Description: PGP signature


Re: I need help with IO.e

2020-05-17 Thread Peter Pentchev
On Sun, May 17, 2020 at 03:01:34AM -0700, ToddAndMargo via perl6-users wrote:
> On 2020-05-17 02:30, Peter Pentchev wrote:
> > You said that you would tack Bool at the end in "if" statements, too.
> 
> Hi Peter,
> 
> No wonder.  I do not remember saying that, but I could
> have.  My `if` statements look like:
> 
>if not  "%Options".IO.d.Bool  {
>   say "Creating %Options";
>   mkdir( %Options", 0o777 );
>}
> 
> I definitely do not tack .Bool onto the end
> of my `if` statements.

Uh. That's exactly what you're doing. You do *not* need the .Bool
there at the end. The "not" makes Raku convert whatever is there
to a boolean, so the .Bool is implicit. And if you were to check
the other way, if you had "if $foo.IO.d { ... }", then the "if"
makes Raku convert whatever is there to a boolean, so the .Bool is
implicit. You do not need to put the .Bool in an "if" or a "while"
statement.

G'luck,
Peter

-- 
Peter Pentchev  r...@ringlet.net r...@debian.org p...@storpool.com
PGP key:http://people.FreeBSD.org/~roam/roam.key.asc
Key fingerprint 2EE7 A7A5 17FC 124C F115  C354 651E EFB0 2527 DF13


signature.asc
Description: PGP signature


Re: I need help with IO.e

2020-05-17 Thread Peter Pentchev
On Sun, May 17, 2020 at 02:18:30AM -0700, ToddAndMargo via perl6-users wrote:
> On 2020-05-17 01:23, Peter Pentchev wrote:
> > On Sat, May 16, 2020 at 06:57:53PM -0700, ToddAndMargo via perl6-users 
> > wrote:
> > > On 2020-05-16 17:44, Peter Pentchev wrote:
> > > > On Sat, May 16, 2020 at 03:19:05PM -0700, ToddAndMargo via perl6-users 
> > > > wrote:
> > > > > On 2020-05-16 06:38, Peter Pentchev wrote:
> > > > > > > $ raku *-e* "your one-liner script here"
> > > > > > And also you might want to put some quotes around the paths to let 
> > > > > > Raku
> > > > > > know that those are strings and not some identifiers or something.
> > > > > > 
> > > > > > G'luck,
> > > > > > Peter
> > > > > > 
> > > > > 
> > > > > Hi Peter,
> > > > > 
> > > > > This is what goofed me up:
> > > > > 
> > > > > $ alias p5
> > > > > alias p5='perl -E'
> > > > > 
> > > > > $ alias p6
> > > > > alias p6='perl6 -e'
> > > > > 
> > > > > I have no such feature on the Windows side and had
> > > > > forgot about it.
> > > > > 
> > > > > Also, if you tack a .Bool on the end of IO.d, you
> > > > > get back True or False, instead of the useless True
> > > > > or Crash.  I updates my perl6.IO.txt keeper file.
> > > > > 
> > > > > And IO.e also works for directories
> > > > 
> > > > What you're doing with "tacking .Bool at the end" is usually not
> > > > necessary to do explicitly, because most people do not "say" the result
> > > > of .d or .e, but use it in an if, for, while or some such conditional
> > > > statement, in which case Raku automatically converts the expression to
> > > > a boolean, i.e. tacks a .Bool at the end.
> > > > 
> > > > The reason .d and .e return a failure otherwise is that in some cases
> > > > they may be used not in a conditional statement, but as a kind of
> > > > assertion - "I really, really think that at this point this variable
> > > > should contain a valid path to an existing directory, but if something
> > > > went wrong in my program and the variable does not contain that, I do
> > > > not want the program to go on, it would be useless, I *want* it to raise
> > > > an exception when the value is used". At least that's what I think;
> > > > I *know* that the people who rewrote .IO in v6.d are on this list, so
> > > > please correct me if I'm wrong :)
> > > > 
> > > > But the most common use of .d, .e, .f and similar, the most common by
> > > > a very large margin, is in conditionals, where Raku does the conversion
> > > > to a boolean value automatically.
> > > > 
> > > > G'luck,
> > > > Peter
> > > > 
> > > 
> > > Hi Peter,
> > > 
> > > My big issues is that  want to check to see if something
> > > is there, then take appropriate measures based on what
> > > I am doing.  Crashing is not what I want.  If I should
> > > exit based on what I find, I want the control over it.
> > 
> > So use .d in a boolean context (if, while, etc).
> > 
> > > In my "if" statements, I will use Bool anyway as it
> > > will force the issue. And will alert me that there
> > > is something else going on that I should be aware of
> > > (fail).
> > 
> > That's *exactly* the opposite of what I thought I explained, but
> > you do you, I guess.
> > 
> > > Now I have to look up f.
> > > 
> > > Found it.  If you use the Bool, it returns a False
> > > for directories.   Cool.
> > 
> > It is documented to return true for files, so yes, it would return false
> > for directories.
> > 
> > > Thank you for the detailed explanation.  Very useful
> > > and helpful!
> > > 
> > > 
> > > Just out of curiosity
> > > 
> > >   https://docs.raku.org/routine/d
> > >   (IO::Path) method d
> > >   Defined as:
> > > 
> > >   method d(--> Bool:D)
> > > 
> > >   Returns True if the invocant is a path that
> > >   exists and is a directory. The method will
> > >   fail with X::

Re: I need help with IO.e

2020-05-17 Thread Peter Pentchev
On Sat, May 16, 2020 at 06:57:53PM -0700, ToddAndMargo via perl6-users wrote:
> On 2020-05-16 17:44, Peter Pentchev wrote:
> > On Sat, May 16, 2020 at 03:19:05PM -0700, ToddAndMargo via perl6-users 
> > wrote:
> > > On 2020-05-16 06:38, Peter Pentchev wrote:
> > > > > $ raku *-e* "your one-liner script here"
> > > > And also you might want to put some quotes around the paths to let Raku
> > > > know that those are strings and not some identifiers or something.
> > > > 
> > > > G'luck,
> > > > Peter
> > > > 
> > > 
> > > Hi Peter,
> > > 
> > > This is what goofed me up:
> > > 
> > > $ alias p5
> > > alias p5='perl -E'
> > > 
> > > $ alias p6
> > > alias p6='perl6 -e'
> > > 
> > > I have no such feature on the Windows side and had
> > > forgot about it.
> > > 
> > > Also, if you tack a .Bool on the end of IO.d, you
> > > get back True or False, instead of the useless True
> > > or Crash.  I updates my perl6.IO.txt keeper file.
> > > 
> > > And IO.e also works for directories
> > 
> > What you're doing with "tacking .Bool at the end" is usually not
> > necessary to do explicitly, because most people do not "say" the result
> > of .d or .e, but use it in an if, for, while or some such conditional
> > statement, in which case Raku automatically converts the expression to
> > a boolean, i.e. tacks a .Bool at the end.
> > 
> > The reason .d and .e return a failure otherwise is that in some cases
> > they may be used not in a conditional statement, but as a kind of
> > assertion - "I really, really think that at this point this variable
> > should contain a valid path to an existing directory, but if something
> > went wrong in my program and the variable does not contain that, I do
> > not want the program to go on, it would be useless, I *want* it to raise
> > an exception when the value is used". At least that's what I think;
> > I *know* that the people who rewrote .IO in v6.d are on this list, so
> > please correct me if I'm wrong :)
> > 
> > But the most common use of .d, .e, .f and similar, the most common by
> > a very large margin, is in conditionals, where Raku does the conversion
> > to a boolean value automatically.
> > 
> > G'luck,
> > Peter
> > 
> 
> Hi Peter,
> 
> My big issues is that  want to check to see if something
> is there, then take appropriate measures based on what
> I am doing.  Crashing is not what I want.  If I should
> exit based on what I find, I want the control over it.

So use .d in a boolean context (if, while, etc).

> In my "if" statements, I will use Bool anyway as it
> will force the issue. And will alert me that there
> is something else going on that I should be aware of
> (fail).

That's *exactly* the opposite of what I thought I explained, but
you do you, I guess.

> Now I have to look up f.
> 
> Found it.  If you use the Bool, it returns a False
> for directories.   Cool.

It is documented to return true for files, so yes, it would return false
for directories.

> Thank you for the detailed explanation.  Very useful
> and helpful!
> 
> 
> Just out of curiosity
> 
>  https://docs.raku.org/routine/d
>  (IO::Path) method d
>  Defined as:
> 
>  method d(--> Bool:D)
> 
>  Returns True if the invocant is a path that
>  exists and is a directory. The method will
>  fail with X::IO::DoesNotExist if the path points to
>  a non-existent filesystem entity.
> 
> Where in the definition
> method d(--> Bool:D)
> does it state True or Fail?  It states "Bool".  Is
> something missing?

The definition does not list all the exceptions that a method or
function can throw, and for good reason - people have learned their
lessons from the Java world, where this, while it did have some very
limited use, very quickly drove programmers to just say "... raises
Exception" on everything, making it essentially useless.

OK, in more words for people who may not have any Java programming
experience: they tried to make programmers list any exceptions that may
be raised from their methods, with the expectation that programmers
would check the documentation for any exceptions raised by the functions
and methods that they call, decide which ones they want to handle and
which ones they want to propagate upwards, and then list the ones that
they propatage and the ones that they raise themselves. However, in some
cases, like when using several library functions from several

Re: Matching subpatterns in any order, conjunctions, negated matches

2020-05-16 Thread Peter Pentchev
On Sat, May 16, 2020 at 05:53:04PM -0700, Joseph Brenner wrote:
>  Peter Pentchev  wrote:
> > On Fri, May 15, 2020 at 07:32:50PM -0700, Joseph Brenner wrote:
> >> Regex engines by their nature care a lot about order, but I
> >> occasionally want to relax that to match for multiple
> >> multicharacter subpatterns where the order of them doesn't
> >> matter.
> >>
> >> Frequently the simplest thing to do is just to just do multiple
> >> matches.   Let's say you're looking for words that have a "qu" a
> >> "th" and also, say an "ea".  This works:
> >>
> >>   my $DICT  = "/usr/share/dict/american-english";
> >>   my @hits = $DICT.IO.open( :r
> >> ).lines.grep({/qu/}).grep({/th/}).grep({/ea/});
> >>   say @hits;
> >>   # [bequeath bequeathed bequeathing bequeaths earthquake earthquake's
> >> earthquakes]
> >
> > Would something like this work for you?
> >
> >   /^/
> >
> >> Where things get interesting is when you want a negated match of
> >> one of the subpatterns.  One of the things I like about the first
> >> approach using multiple chained greps is that it's easy to do a
> >> reverse match.  What if you want words with "qu" and "th" but
> >> want to *skip* ones with an "ea"?
> >>
> >>   my @hits = $DICT.IO.open( :r
> >> ).lines.grep({/qu/}).grep({/th/}).grep({!/ea/});
> >>   # [Asquith discotheque discotheque's discotheques quoth]
> >
> > Maybe something like this? (note the "!" instead of "?")
> >
> >   /^/
> >
>
> Yes, both of those work, and arguably they're a little cleaner
> looking than my conjunction approach-- though it's not necessarily any
> easier to think about.  It looks like a pattern that's matching
> for three things in order, but the zero-widthness of the "before"
> let's them all work on top of each other.
> 
> I keep thinking there's an edge case in these before/after tricks that
> might matter if we weren't matching the one-word-per-line format of
> the unix dictionaries, but I need to think about that a little more...

Actually, there is, and I conveniently did not mention it :) It's the
case when the patterns may overlap: if you do the 'http://people.FreeBSD.org/~roam/roam.key.asc
Key fingerprint 2EE7 A7A5 17FC 124C F115  C354 651E EFB0 2527 DF13


signature.asc
Description: PGP signature


Re: I need help with IO.e

2020-05-16 Thread Peter Pentchev
On Sat, May 16, 2020 at 03:19:05PM -0700, ToddAndMargo via perl6-users wrote:
> On 2020-05-16 06:38, Peter Pentchev wrote:
> > > $ raku *-e* "your one-liner script here"
> > And also you might want to put some quotes around the paths to let Raku
> > know that those are strings and not some identifiers or something.
> > 
> > G'luck,
> > Peter
> > 
> 
> Hi Peter,
> 
> This is what goofed me up:
> 
> $ alias p5
> alias p5='perl -E'
> 
> $ alias p6
> alias p6='perl6 -e'
> 
> I have no such feature on the Windows side and had
> forgot about it.
> 
> Also, if you tack a .Bool on the end of IO.d, you
> get back True or False, instead of the useless True
> or Crash.  I updates my perl6.IO.txt keeper file.
> 
> And IO.e also works for directories

What you're doing with "tacking .Bool at the end" is usually not
necessary to do explicitly, because most people do not "say" the result
of .d or .e, but use it in an if, for, while or some such conditional
statement, in which case Raku automatically converts the expression to
a boolean, i.e. tacks a .Bool at the end.

The reason .d and .e return a failure otherwise is that in some cases
they may be used not in a conditional statement, but as a kind of
assertion - "I really, really think that at this point this variable
should contain a valid path to an existing directory, but if something
went wrong in my program and the variable does not contain that, I do
not want the program to go on, it would be useless, I *want* it to raise
an exception when the value is used". At least that's what I think;
I *know* that the people who rewrote .IO in v6.d are on this list, so
please correct me if I'm wrong :)

But the most common use of .d, .e, .f and similar, the most common by
a very large margin, is in conditionals, where Raku does the conversion
to a boolean value automatically.

G'luck,
Peter

-- 
Peter Pentchev  r...@ringlet.net r...@debian.org p...@storpool.com
PGP key:http://people.FreeBSD.org/~roam/roam.key.asc
Key fingerprint 2EE7 A7A5 17FC 124C F115  C354 651E EFB0 2527 DF13


signature.asc
Description: PGP signature


Re: I need help with IO.e

2020-05-16 Thread Peter Pentchev
On Sat, May 16, 2020 at 01:29:12PM +0200, Laurent Rosenfeld via perl6-users 
wrote:
> Hi,
> 
> it should be:
> 
> $ raku *-e* "your one-liner script here"

And also you might want to put some quotes around the paths to let Raku
know that those are strings and not some identifiers or something.

G'luck,
Peter

> Le sam. 16 mai 2020 à 12:16, ToddAndMargo via perl6-users <
> perl6-us...@perl.org> a écrit :
> 
> > On 2020-05-15 22:30, ToddAndMargo via perl6-users wrote:
> > > Hi All,.
> > >
> > > Windows 7, sp1, x64
> > >
> > >  >raku -v
> > > This is Rakudo version 2020.01 built on MoarVM version
> > > 2020.01.1 implementing Perl 6.d.
> > >
> > >
> > > I am trying to get perl to tell me if a drive letter exists
> > >
> > > This is from Git's df command:
> > >
> > >  >df -kPT H:\
> > > Filesystem Type 1024-blocks  Used Available Capacity Mounted on
> > > H: ntfs   38908  9964 28944  26% /h
> > >
> > > So, H:\ is there
> > >
> > >  >raku "say H:\.IO.e"
> > > Could not open say H:\.IO.e. Failed to stat file: no such file or
> > directory
> > >
> > > And in case I need \\
> > >
> > >  >raku "say H:\\.IO.e"
> > > Could not open say H:\\.IO.e. Failed to stat file: no such file or
> > > directory
> > >
> > > And in case I need a forward slashL:
> > >  >raku "say H:/.IO.e"
> > > Could not open say H:/.IO.e. Failed to stat file: no such file or
> > directory
> > >
> > > What am I doing wrong, this time?
> > >
> > > -T
> > >
> >
> >
> > As far as I can tell IO.e and IO.d is completely trashed
> > in Windows:
> >
> > K:\Windows\NtUtil>dir H:
> >   Volume in drive H is BACKUP
> >   Volume Serial Number is 00D0-CAD4
> >
> >   Directory of H:\
> >
> > 05/15/2020  22:21 0 IAmBackup
> > 05/15/2020  22:43  MyDocsBackup
> > 1 File(s)  0 bytes
> > 1 Dir(s)  29,638,656 bytes free
> >
> >
> >
> > K:\Windows\NtUtil>raku "say 'h://IAmBackup'.IO.e"
> > Could not open say 'h://IAmBackup'.IO.e. Failed to stat file: no such
> > file or di
> > rectory
> >
> > K:\Windows\NtUtil>raku "say 'h:/IAmBackup'.IO.e"
> > Could not open say 'h:/IAmBackup'.IO.e. Failed to stat file: no such
> > file or directory
> >
> > K:\Windows\NtUtil>raku "say 'h:\IAmBackup'.IO.e"
> > Could not open say 'h:\IAmBackup'.IO.e. Failed to stat file: no such
> > file or directory
> >
> > K:\Windows\NtUtil>raku "say 'h:\\IAmBackup'.IO.e"
> > Could not open say 'h:\\IAmBackup'.IO.e. Failed to stat file: no such
> > file or directory
> >
> >
> > And that goes for IO.d too:
> >
> > K:\Windows\NtUtil>raku "say 'h:\\MyDocsBackup'.IO.d"
> > Could not open say 'h:\\MyDocsBackup'.IO.d. Failed to stat file: no such
> > file or
> >   directory
> >
> > K:\Windows\NtUtil>raku "say 'h:\MyDocsBackup'.IO.d"
> > Could not open say 'h:\MyDocsBackup'.IO.d. Failed to stat file: no such
> > file or directory
> >
> > K:\Windows\NtUtil>raku "say 'h:/MyDocsBackup'.IO.d"
> > Could not open say 'h:/MyDocsBackup'.IO.d. Failed to stat file: no such
> > file or directory
> >
> > K:\Windows\NtUtil>raku "say 'h://MyDocsBackup'.IO.d"
> > Could not open say 'h://MyDocsBackup'.IO.d. Failed to stat file: no such
> > file or  directory
> >
> > This gets a TRIPLE:  :'(  :'(  :'(
> >
> >
> >
> > And it only works slightly better under Fedora:
> >
> > $ p6 'say "GetOptLongTest.pl6".IO.e'
> > True
> >
> > $ p6 'say "GetOptLongTest.pl7".IO.e'
> > False
> >
> > $ p6 'say "p6lib".IO.d'
> > True
> >
> > $ p6 'say "p7lib".IO.d'
> > Failed to find '/home/linuxutil/p7lib' while trying to do '.d'
> >in block  at -e line 1
> >
> > Notice that it crashed instead of returning a False.
> >
> > This gets a single :'(
> >
> >  AAHH 
> >

-- 
Peter Pentchev  r...@ringlet.net r...@debian.org p...@storpool.com
PGP key:http://people.FreeBSD.org/~roam/roam.key.asc
Key fingerprint 2EE7 A7A5 17FC 124C F115  C354 651E EFB0 2527 DF13


signature.asc
Description: PGP signature


Re: Matching subpatterns in any order, conjunctions, negated matches

2020-05-16 Thread Peter Pentchev
On Fri, May 15, 2020 at 07:32:50PM -0700, Joseph Brenner wrote:
> Regex engines by their nature care a lot about order, but I
> occasionally want to relax that to match for multiple
> multicharacter subpatterns where the order of them doesn't
> matter.
> 
> Frequently the simplest thing to do is just to just do multiple
> matches.   Let's say you're looking for words that have a "qu" a
> "th" and also, say an "ea".  This works:
> 
>   my $DICT  = "/usr/share/dict/american-english";
>   my @hits = $DICT.IO.open( :r ).lines.grep({/qu/}).grep({/th/}).grep({/ea/});
>   say @hits;
>   # [bequeath bequeathed bequeathing bequeaths earthquake earthquake's
> earthquakes]

Would something like this work for you?

  /^/

> Where things get interesting is when you want a negated match of
> one of the subpatterns.  One of the things I like about the first
> approach using multiple chained greps is that it's easy to do a
> reverse match.  What if you want words with "qu" and "th" but
> want to *skip* ones with an "ea"?
> 
>   my @hits = $DICT.IO.open( :r 
> ).lines.grep({/qu/}).grep({/th/}).grep({!/ea/});
>   # [Asquith discotheque discotheque's discotheques quoth]

Maybe something like this? (note the "!" instead of "?")

  /^/

G'luck,
Peter

-- 
Peter Pentchev  r...@ringlet.net r...@debian.org p...@storpool.com
PGP key:http://people.FreeBSD.org/~roam/roam.key.asc
Key fingerprint 2EE7 A7A5 17FC 124C F115  C354 651E EFB0 2527 DF13


signature.asc
Description: PGP signature


Re: fill in form

2020-05-16 Thread Peter Pentchev
On Fri, May 15, 2020 at 04:42:44PM -0700, ToddAndMargo via perl6-users wrote:
> On 2020-05-15 15:23, Peter Pentchev wrote:
> > On Fri, May 15, 2020 at 02:51:10PM -0700, ToddAndMargo via perl6-users 
> > wrote:
> > > On 2020-05-13 14:05, Peter Pentchev wrote:
> > > > So... I believe Timo gave you that as an example how to use a grid to
> > > > position the various controls (buttons, text labels, input fields).
> > > > You start there, you figure out what text labels, what input fields,
> > > > what buttons you need, and then you use the 03-grid.p6 example as a base
> > > > on how to do this with Raku and GTK+.
> > > 
> > > Actually, he showed me the end result, not how he did it.
> > > I really need to know how he did it
> > 
> > Um, what he showed you was not in any way related to GTK+; it was
> > an example of using grid layout in Cascading Style Sheets (CSS),
> > a widely-used extension to HTML for making webpages. His point was
> > to illustrate the *idea* of aligning buttons, text labels, and text
> > input boxes to a grid.
> > 
> > So you posted a screenshot of running the 03-grid.p6 example.
> > It showed a couple of buttons and a text label, and it aligned them in
> > the way described in the source code. Play around with it a bit, move
> > the buttons and the text labels around, create another element or two,
> > look at the other examples, maybe the one that says "Hello World", maybe
> > the one that is called "text", see what other types of GTK+ things you
> > can put onto the grid.
> 
> With the exception that I do not know how to get the
> data back out of the pop up.  The example does not even
> have a `okay` and `cancel` button

...so, as I said, you look at the other examples. This one is merely
an example of aligning things, not of making things do something.
That's what the other examples (like the ones that, I don't know, maybe
the ones that I mentioned?).

G'luck,
Peter

-- 
Peter Pentchev  r...@ringlet.net r...@debian.org p...@storpool.com
PGP key:http://people.FreeBSD.org/~roam/roam.key.asc
Key fingerprint 2EE7 A7A5 17FC 124C F115  C354 651E EFB0 2527 DF13


signature.asc
Description: PGP signature


Re: fill in form

2020-05-15 Thread Peter Pentchev
On Fri, May 15, 2020 at 02:51:10PM -0700, ToddAndMargo via perl6-users wrote:
> On 2020-05-13 14:05, Peter Pentchev wrote:
> > So... I believe Timo gave you that as an example how to use a grid to
> > position the various controls (buttons, text labels, input fields).
> > You start there, you figure out what text labels, what input fields,
> > what buttons you need, and then you use the 03-grid.p6 example as a base
> > on how to do this with Raku and GTK+.
> 
> Actually, he showed me the end result, not how he did it.
> I really need to know how he did it

Um, what he showed you was not in any way related to GTK+; it was
an example of using grid layout in Cascading Style Sheets (CSS),
a widely-used extension to HTML for making webpages. His point was
to illustrate the *idea* of aligning buttons, text labels, and text
input boxes to a grid.

So you posted a screenshot of running the 03-grid.p6 example.
It showed a couple of buttons and a text label, and it aligned them in
the way described in the source code. Play around with it a bit, move
the buttons and the text labels around, create another element or two,
look at the other examples, maybe the one that says "Hello World", maybe
the one that is called "text", see what other types of GTK+ things you
can put onto the grid.

G'luck,
Peter

-- 
Peter Pentchev  r...@ringlet.net r...@debian.org p...@storpool.com
PGP key:http://people.FreeBSD.org/~roam/roam.key.asc
Key fingerprint 2EE7 A7A5 17FC 124C F115  C354 651E EFB0 2527 DF13


signature.asc
Description: PGP signature


Re: bash "."?

2020-05-15 Thread Peter Pentchev
On Fri, May 15, 2020 at 01:24:27AM -0700, ToddAndMargo via perl6-users wrote:
> On 2020-05-15 00:26, ToddAndMargo via perl6-users wrote:
> > On 2020-05-14 23:57, Shlomi Fish wrote:
> > > The INI formats have no official (ISO/etc.) standard, and there are many
> > > variations of them. See, for example, the various options that
> > > https://metacpan.org/pod/Config::IniFiles  accepts (note that I
> > > comaintain it
> > > now).
> > > 
> > > > I will be playing with them shortly.  I really want
> > > > to see how CONFIG handles section titles.
> > > > 
> > > > Thank you!
> > > > 
> > > > -T
> > 
> > # zef install Config::IniFiles
> > ===> Searching for: Config::IniFiles
> > No candidates found matching identity: Config::IniFiles
> > 
> > 
> > :'(  :'(  :'(
> 
> 
> I downloaded it from git and the directions did not work

Let's start with "you do realize that Config::IniFiles is a Perl 5
module, not a Raku one, right?"... of course, it might be possible to
use it through Raku's Inline::Perl5, but it would be much, much easier
to use one of the native Raku modules that people already mentioned in
this thread.

G'luck,
Peter

-- 
Peter Pentchev  r...@ringlet.net r...@debian.org p...@storpool.com
PGP key:http://people.FreeBSD.org/~roam/roam.key.asc
Key fingerprint 2EE7 A7A5 17FC 124C F115  C354 651E EFB0 2527 DF13


signature.asc
Description: PGP signature


Re: sqrt and Buf question

2020-05-14 Thread Peter Pentchev
On Thu, May 14, 2020 at 02:36:30PM -0700, ToddAndMargo via perl6-users wrote:
> On 2020-05-14 08:13, Bruce Gray wrote:
> > 
> > 
> > > On May 14, 2020, at 7:27 AM, ToddAndMargo via perl6-users 
> > >  wrote:
> > > 
> > > Hi All,
> > > 
> > > 1) how do I get 40 or more digits out of sqrt?
> > 
> > —snip—
> > 
> > Use an Integer Root algorithm on ($number-you-want-the-root-of * 100 ** 
> > $number-of-digits-you-want), then shift the decimal point of the result.
> > 
> > Exact code here:
> > https://rosettacode.org/wiki/Integer_roots#Raku
> > 
> > —
> > Hope this helps,
> > Bruce Gray (“Util” on RosettaCode, too)
> 
> 
> sub integer_root ( Int $p where * >= 2, Int $n --> Int ) {
> my Int $d = $p - 1;
> my $guess = 10**($n.chars div $p);
> my $iterator = { ( $d * $^x   +   $n div ($^x ** $d) ) div $p };
> my $endpoint = {  $^x  ** $p <= $n
>  and ($^x + 1) ** $p >  $n };
> min (+$guess, $iterator ... $endpoint)[*-1, *-2];
> }
> 
> say integer_root( 2, 2 * 100 ** 2000 );
> 
> 
> 
> It does help!  I can reproduce noise to my heart's content!
> 
> Questions:
> 
> what is $p in the sub declaration? Is it always a 2?

https://rosettacode.org/wiki/Integer_roots

> what is `$n` in the sub declaration?  Looks like
> the third set of numbers is the digits I want.

https://rosettacode.org/wiki/Integer_roots

> what is the second number (100)?

https://rosettacode.org/wiki/Integer_roots

> And what is `2 * 100 ** 2000 `?  Is that `(2 x 100)^ 2000`
> ((2 times 100) to the 2000 power?

Point 1: exponentiation has a higher priority than multiplication.

Point 2: https://rosettacode.org/wiki/Integer_roots

G'luck,
Peter

-- 
Peter Pentchev  r...@ringlet.net r...@debian.org p...@storpool.com
PGP key:http://people.FreeBSD.org/~roam/roam.key.asc
Key fingerprint 2EE7 A7A5 17FC 124C F115  C354 651E EFB0 2527 DF13


signature.asc
Description: PGP signature


Re: How do I handle Getopt::Long stray entries?

2020-05-14 Thread Peter Pentchev
On Fri, May 15, 2020 at 07:57:47AM +0300, Peter Pentchev wrote:
> On Thu, May 14, 2020 at 06:46:17PM -0700, ToddAndMargo via perl6-users wrote:
> > On 2020-05-11 21:19, Peter Pentchev wrote:
> > > #!/usr/bin/env raku
> > > 
> > > use v6.d;
> > > 
> > > use Getopt::Long;
> > > 
> > > sub cmd_install($cmd, Array[Str] :$enablerepo = [], Bool :$y = False, 
> > > *@rest --> int)
> > > {
> > >   say 'install';
> > >   dd $cmd;
> > >   dd @rest;
> > >   dd $enablerepo;
> > >   dd $y;
> > >   return 0;
> > > }
> > > 
> > > sub cmd_list($cmd, Array[Str] :$enablerepo = [], *@rest --> int)
> > > {
> > >   say 'list';
> > >   dd $cmd;
> > >   dd @rest;
> > >   dd $enablerepo;
> > >   return 42;
> > > }
> > > 
> > > my %HANDLERS = (
> > >   install => _install,
> > >   
> > >   # "list" doesn't care about the "-y" parameter, so skip it
> > >   list => -> $cmd, :$enablerepo = [], :$y = False, *@rest --> int {
> > >   cmd_list $cmd, :$enablerepo, |@rest
> > >   },
> > > );
> > > 
> > > sub note-fatal(Str:D $msg)
> > > {
> > >   $msg.note;
> > >   exit 1;
> > > }
> > > 
> > > {
> > >   my $opts = get-options(
> > >   "enablerepo=s@",
> > >   "y",
> > >   );
> > >   CATCH { when Getopt::Long::Exception { .message.note; exit 1 } };
> > >   dd $opts;
> > > 
> > >   note-fatal 'No command specified' unless $opts.elems;
> > >   my $cmd = $opts[0];
> > >   my $handler = %HANDLERS{$cmd};
> > >   note-fatal "Unknown command '$cmd'" unless $handler;
> > >   exit $handler(|$opts);
> > > }
> > 
> > 
> > How do I use it?  Where are the options declared?
> 
> What does https://modules.raku.org/dist/Getopt::Long:cpan:LEONT (the
> link you posted at the top of your first message) say in the "SYNOPSIS"
> section?

Okay, so that might have been something of a trick question, since
it seems that synopsis does not have an example of the Capture-style
invocation[1] :) You may have to actually read the "Simple options" section
below to find out what get-options() returns :)

G'luck,
Peter

[1] https://github.com/Leont/getopt-long6/pull/5

-- 
Peter Pentchev  r...@ringlet.net r...@debian.org p...@storpool.com
PGP key:http://people.FreeBSD.org/~roam/roam.key.asc
Key fingerprint 2EE7 A7A5 17FC 124C F115  C354 651E EFB0 2527 DF13


signature.asc
Description: PGP signature


Re: How do I handle Getopt::Long stray entries?

2020-05-14 Thread Peter Pentchev
On Thu, May 14, 2020 at 06:46:17PM -0700, ToddAndMargo via perl6-users wrote:
> On 2020-05-11 21:19, Peter Pentchev wrote:
> > #!/usr/bin/env raku
> > 
> > use v6.d;
> > 
> > use Getopt::Long;
> > 
> > sub cmd_install($cmd, Array[Str] :$enablerepo = [], Bool :$y = False, 
> > *@rest --> int)
> > {
> > say 'install';
> > dd $cmd;
> > dd @rest;
> > dd $enablerepo;
> > dd $y;
> > return 0;
> > }
> > 
> > sub cmd_list($cmd, Array[Str] :$enablerepo = [], *@rest --> int)
> > {
> > say 'list';
> > dd $cmd;
> > dd @rest;
> > dd $enablerepo;
> > return 42;
> > }
> > 
> > my %HANDLERS = (
> > install => _install,
> > 
> > # "list" doesn't care about the "-y" parameter, so skip it
> > list => -> $cmd, :$enablerepo = [], :$y = False, *@rest --> int {
> > cmd_list $cmd, :$enablerepo, |@rest
> > },
> > );
> > 
> > sub note-fatal(Str:D $msg)
> > {
> > $msg.note;
> > exit 1;
> > }
> > 
> > {
> > my $opts = get-options(
> > "enablerepo=s@",
> > "y",
> > );
> > CATCH { when Getopt::Long::Exception { .message.note; exit 1 } };
> > dd $opts;
> > 
> > note-fatal 'No command specified' unless $opts.elems;
> > my $cmd = $opts[0];
> > my $handler = %HANDLERS{$cmd};
> > note-fatal "Unknown command '$cmd'" unless $handler;
> > exit $handler(|$opts);
> > }
> 
> 
> How do I use it?  Where are the options declared?

What does https://modules.raku.org/dist/Getopt::Long:cpan:LEONT (the
link you posted at the top of your first message) say in the "SYNOPSIS"
section?

G'luck,
Peter

-- 
Peter Pentchev  r...@ringlet.net r...@debian.org p...@storpool.com
PGP key:http://people.FreeBSD.org/~roam/roam.key.asc
Key fingerprint 2EE7 A7A5 17FC 124C F115  C354 651E EFB0 2527 DF13


signature.asc
Description: PGP signature


Re: bash "."?

2020-05-14 Thread Peter Pentchev
On Thu, May 14, 2020 at 04:39:18AM -0700, ToddAndMargo via perl6-users wrote:
> On 2020-05-13 22:27, Bruce Gray wrote:
> > 
> > 
> > > On May 13, 2020, at 9:37 PM, ToddAndMargo via perl6-users 
> > >  wrote:
> > > 
> > > Hi All,
> > > 
> > > Do we have anything like Bash's "." statement where
> > > we can read in a bunch of values from a .cfg file?
> > > (I think it is called "include", but I am not sure.)
> > > 
> > > . /etc/sysconfig/network-scripts/ifcfg-br0
> > > 
> > > which populates these (and other) variables
> > > 
> > > DEVICE=br0
> > > TYPE=Bridge
> > > ONBOOT=yes
> > > USERCTL=yes
> > > DELAY=0
> > > NM_CONTROLLED=yes
> > > BOOTPROTO=none
> > > PREFIX=24
> > > ...
> > > 
> > > Many thanks,
> > > -T
> > 
> > Hi Todd,
> > 
> > FYI, the `.` Bash command is also called `source`, which is easier to 
> > search on the Web, and clearer in email:
> > https://ss64.com/bash/source.html
> > 
> > The closest equivalent in Raku is:
> > https://docs.raku.org/routine/EVALFILE
> > , which could be used for config data like so:
> > $ cat a.dat
> > $foo = "bar";
> > $baz = "quxx";
> > 
> > $ perl6 -e 'our ($foo, $baz); EVALFILE "a.dat"; .say for $foo, $baz;'
> > bar
> > quxx
> > 
> > , but please do not use it for this purpose.
> > 
> > EVALFILE is in all-caps to show that it might be dangerous and not for 
> > general use; it is “grep-able evil”, and could eval any valid Raku code, 
> > even evil things like `run “rm -rf /“`.
> > 
> > IMHO, Bash's `source`-style of loading variables pollutes the main 
> > namespace and causes hard-to-debug “action at a distance”.
> > In Raku (or any other dynamic language), the use of some kind of Config 
> > module is safer and cleaner:
> > https://modules.raku.org/t/CONFIG
> > https://github.com/raku-community-modules/perl6-Config-JSON
> > https://github.com/Skarsnik/perl6-config-simple
> > https://metacpan.org/pod/Config::Tiny
> > 
> > For example:
> > 
> > $ cat config.json
> > {
> >"baz": "quxx",
> >"foo": "bar”
> > }
> > $ perl6 -e 'use Config::JSON; my %c; %c{$_} = jconf($_) for ; say 
> > %c{$_} for ;'
> > bar
> > quxx
> > 
> > $ cat b.dat
> > foo = bar
> > baz = quxx
> > $ perl6 -e 'use Config::Tiny:from; my $conf = 
> > Config::Tiny.read("b.dat"); .say for $conf<_>'
> > bar
> > quxx
> > 
> > 
> > —
> > Hope this helps,
> > Bruce Gray (Util of PerlMonks)
> 
> 
> Hi Bruce,
> 
> I looked at the first two links above.  Neither showed
> the format of the data being read. But you did.  Is
> there some reason why the two links did not show the format?

Well, they do both say they read .ini-style files. I think that they
will both be able to read simple key=value files like the network
definition sysconfig ones on RedHat-style systems that you seem to want.
Keep in mind that the shell probably interprets a bit more, so some
configuration-reading modules may e.g. return the quotes around the
value or something like that; take them for a spin and see.
Also, it's almost certain that these modules will not be able to help if
the files that you read make use of the fact that the shell performs
variable expansion: they will not be able to expand other variables in
lines like:

KEYFILE="/etc/keys/$HOSTNAME.key"

or something like that.

If you come across files like that, you may have to write your own
parser.

For some general information on ini-like files, see
https://en.wikipedia.org/wiki/INI_file

G'luck,
Peter

-- 
Peter Pentchev  r...@ringlet.net r...@debian.org p...@storpool.com
PGP key:http://people.FreeBSD.org/~roam/roam.key.asc
Key fingerprint 2EE7 A7A5 17FC 124C F115  C354 651E EFB0 2527 DF13


signature.asc
Description: PGP signature


Re: fill in form

2020-05-13 Thread Peter Pentchev
On Wed, May 13, 2020 at 07:58:08AM -0700, Todd Chester via perl6-users wrote:
> > On 12/05/2020 20:44, ToddAndMargo via perl6-users wrote:
> >>> On 12/05/2020 00: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
> >>
> >>
> >> On 2020-05-12 08:18, Timo Paulssen wrote:
> >>> Hi Todd,
> >>>
> >>> normally I'd expect you want to create a grid with labels on the left
> >>> and text inputs on the right.
> >>>
> >>> the examples/ folder in the GTK::Simple distribution (or the source on
> >>> github) has an example of the Grid class, which is very powerful.
> >>>
> >>> The grid is possibly more complicated than you need it to be; instead
> >>> you can probably have one VBox that contains one HBox for every label +
> >>> input field.
> >>>
> >>> One benefit that the Grid will give you is that you can much more easily
> >>> line up all the fill-in text inputs, whereas with a VBox of HBoxes it
> >>> may just make every text input as wide as possible so it (almost)
> >>> touches the end of the label, so different words ("city" vs "first
> >>> name") could result in different-sized text inputs.
> >>>
> >>> hope that helps
> >>> - Timo
> >>>
> >>
> >>
> >> Hi Timo,
> >>
> >> You mean this one?
> >>
> >> https://github.com/raku-community-modules/gtk-simple/blob/master/examples/03-grid.pl6
> >>
> >>
> >> https://ibb.co/hgKHgW4
> >>
> >> I do not see the utility of what I am after.
> >>
> >> :'(
> >>
> >> -T
> 
> On 2020-05-13 05:26, Timo Paulssen wrote:
> > Is this not anything like what you're after?
> > 
> > https://external-content.duckduckgo.com/iu/?u=https%3A%2F%2Fwww.w3.org%2FTR%2F2016%2FCR-css-grid-1-20160929%2Fimages%2Fauto-placed-form.png=1=1
> > 
> > Kind Regards
> >    - Timo
> > 
> 
> Yes!

So... I believe Timo gave you that as an example how to use a grid to
position the various controls (buttons, text labels, input fields).
You start there, you figure out what text labels, what input fields,
what buttons you need, and then you use the 03-grid.p6 example as a base
on how to do this with Raku and GTK+.

G'luck,
Peter

-- 
Peter Pentchev  r...@ringlet.net r...@debian.org p...@storpool.com
PGP key:http://people.FreeBSD.org/~roam/roam.key.asc
Key fingerprint 2EE7 A7A5 17FC 124C F115  C354 651E EFB0 2527 DF13


signature.asc
Description: PGP signature


Re: How do I handle Getopt::Long stray entries?

2020-05-11 Thread Peter Pentchev
On Mon, May 11, 2020 at 04:09:32PM -0700, ToddAndMargo via perl6-users wrote:
> On 2020-05-11 11:48, Peter Pentchev wrote:
> > On Mon, May 11, 2020 at 12:40:05AM -0700, ToddAndMargo via perl6-users 
> > wrote:
> > > On 2020-05-10 23:47, Peter Pentchev wrote:
> > > > On Sun, May 10, 2020 at 06:20:02PM -0700, ToddAndMargo via perl6-users 
> > > > wrote:
> > > > > Hi All,
> > > > > 
> > > > > https://modules.raku.org/dist/Getopt::Long:cpan:LEONT
> > > > > 
> > > > > How do I handle stray entries (unknown options) without
> > > > > crashing?  Is there some grab bag I can stick all
> > > > > those into?
> > > > 
> > > > When something signals an error using "die", you can catch it
> > > > using a CATCH block, especially if you know that the exception
> > > > thrown will be of a particular type. Now, the Getopt::Long
> > > > documentation does not explicitly mention it, but the module does
> > > > indeed define its own exception type, so you can do something
> > > > like this:
> > > > 
> > > >   use v6.d;
> > > >   use Getopt::Long;
> > > >   get-options('length=i' => my $length);
> > > >   CATCH { when Getopt::Long::Exception { .message.note; exit 1 } };
> > > >   if defined $length {
> > > >   say "Whee, length is $length";
> > > >   } else {
> > > >   say 'No length specified';
> > > >   }
> > > > 
> > > > The "when" condition within the CATCH block will make it only handle
> > > > these exceptions; any other errors will be handled (or passed through) 
> > > > in
> > > > their own way.
> > > > 
> > > > For more information about exceptions, see the documentation at
> > > > https://docs.raku.org/language/exceptions
> > > > 
> > > > G'luck,
> > > > Peter
> > > > 
> > > 
> > > I was actually hope to pick up the extra entries and use them
> > > 
> > > programname.pl6 --abc def ghi
> > > 
> > > I wanted to pick up ghi and use it
> > 
> > If "ghi" is not an option or an argument to an option, then I believe
> > that Getopt::Long, like similar modules in other languages, will
> > just leave it in @ARGV.
> > 
> > > I also wanted to pick up an extra pair not on the list
> > > (unknown option) and complain about them to the user
> > 
> > Well, it seems that Getopt::Long's exceptions are not quite that
> > detailed for the moment. It could be done though, the module could
> > be touched up a little bit so that there are different exceptions
> > for different problems encountered, and some of them contained
> > additional details... but that's up to the author or to whoever
> > decides to fork and extend the module :)
> > 
> > G'luck,
> > Peter
> > 
> 
> Thank you for the words of wisdom!
> 
> I am after the functionality I see in Fedora.  For
> example
> 
> dnf [options]  [...]
> $ dnf --enablerepo=* install firefox
> 
> But I will have to compromise
> 
> :-)

Compromise how? Take a look at the attached source.

G'luck,
Peter

-- 
Peter Pentchev  r...@ringlet.net r...@debian.org p...@storpool.com
PGP key:http://people.FreeBSD.org/~roam/roam.key.asc
Key fingerprint 2EE7 A7A5 17FC 124C F115  C354 651E EFB0 2527 DF13
#!/usr/bin/env raku

use v6.d;

use Getopt::Long;

sub cmd_install($cmd, Array[Str] :$enablerepo = [], Bool :$y = False, *@rest 
--> int)
{
say 'install';
dd $cmd;
dd @rest;
dd $enablerepo;
dd $y;
return 0;
}

sub cmd_list($cmd, Array[Str] :$enablerepo = [], *@rest --> int)
{
say 'list';
dd $cmd;
dd @rest;
dd $enablerepo;
return 42;
}

my %HANDLERS = (
install => _install,

# "list" doesn't care about the "-y" parameter, so skip it
list => -> $cmd, :$enablerepo = [], :$y = False, *@rest --> int {
cmd_list $cmd, :$enablerepo, |@rest
},
);

sub note-fatal(Str:D $msg)
{
$msg.note;
exit 1;
}

{
my $opts = get-options(
"enablerepo=s@",
"y",
);
CATCH { when Getopt::Long::Exception { .message.note; exit 1 } };
dd $opts;

note-fatal 'No command specified' unless $opts.elems;
my $cmd = $opts[0];
my $handler = %HANDLERS{$cmd};
note-fatal "Unknown command '$cmd'" unless $handler;
exit $handler(|$opts);
}


signature.asc
Description: PGP signature


Re: How do I handle Getopt::Long stray entries?

2020-05-11 Thread Peter Pentchev
On Mon, May 11, 2020 at 12:40:05AM -0700, ToddAndMargo via perl6-users wrote:
> On 2020-05-10 23:47, Peter Pentchev wrote:
> > On Sun, May 10, 2020 at 06:20:02PM -0700, ToddAndMargo via perl6-users 
> > wrote:
> > > Hi All,
> > > 
> > > https://modules.raku.org/dist/Getopt::Long:cpan:LEONT
> > > 
> > > How do I handle stray entries (unknown options) without
> > > crashing?  Is there some grab bag I can stick all
> > > those into?
> > 
> > When something signals an error using "die", you can catch it
> > using a CATCH block, especially if you know that the exception
> > thrown will be of a particular type. Now, the Getopt::Long
> > documentation does not explicitly mention it, but the module does
> > indeed define its own exception type, so you can do something
> > like this:
> > 
> >  use v6.d;
> >  use Getopt::Long;
> >  get-options('length=i' => my $length);
> >  CATCH { when Getopt::Long::Exception { .message.note; exit 1 } };
> >  if defined $length {
> >  say "Whee, length is $length";
> >  } else {
> >  say 'No length specified';
> >  }
> > 
> > The "when" condition within the CATCH block will make it only handle
> > these exceptions; any other errors will be handled (or passed through) in
> > their own way.
> > 
> > For more information about exceptions, see the documentation at
> > https://docs.raku.org/language/exceptions
> > 
> > G'luck,
> > Peter
> > 
> 
> I was actually hope to pick up the extra entries and use them
> 
> programname.pl6 --abc def ghi
> 
> I wanted to pick up ghi and use it

If "ghi" is not an option or an argument to an option, then I believe
that Getopt::Long, like similar modules in other languages, will
just leave it in @ARGV.

> I also wanted to pick up an extra pair not on the list
> (unknown option) and complain about them to the user

Well, it seems that Getopt::Long's exceptions are not quite that
detailed for the moment. It could be done though, the module could
be touched up a little bit so that there are different exceptions
for different problems encountered, and some of them contained
additional details... but that's up to the author or to whoever
decides to fork and extend the module :)

G'luck,
Peter

-- 
Peter Pentchev  r...@ringlet.net r...@debian.org p...@storpool.com
PGP key:http://people.FreeBSD.org/~roam/roam.key.asc
Key fingerprint 2EE7 A7A5 17FC 124C F115  C354 651E EFB0 2527 DF13


signature.asc
Description: PGP signature


Re: How do I handle Getopt::Long stray entries?

2020-05-11 Thread Peter Pentchev
On Sun, May 10, 2020 at 06:20:02PM -0700, ToddAndMargo via perl6-users wrote:
> Hi All,
> 
> https://modules.raku.org/dist/Getopt::Long:cpan:LEONT
> 
> How do I handle stray entries (unknown options) without
> crashing?  Is there some grab bag I can stick all
> those into?

When something signals an error using "die", you can catch it
using a CATCH block, especially if you know that the exception
thrown will be of a particular type. Now, the Getopt::Long
documentation does not explicitly mention it, but the module does
indeed define its own exception type, so you can do something
like this:

use v6.d;

use Getopt::Long;

get-options('length=i' => my $length);
CATCH { when Getopt::Long::Exception { .message.note; exit 1 } };

if defined $length {
say "Whee, length is $length";
} else {
say 'No length specified';
}

The "when" condition within the CATCH block will make it only handle
these exceptions; any other errors will be handled (or passed through) in
their own way.

For more information about exceptions, see the documentation at
https://docs.raku.org/language/exceptions

G'luck,
Peter

-- 
Peter Pentchev  r...@ringlet.net r...@debian.org p...@storpool.com
PGP key:http://people.FreeBSD.org/~roam/roam.key.asc
Key fingerprint 2EE7 A7A5 17FC 124C F115  C354 651E EFB0 2527 DF13


signature.asc
Description: PGP signature


Re: endian

2020-01-24 Thread Peter Pentchev
On Fri, Jan 24, 2020 at 02:23:56PM -0800, ToddAndMargo via perl6-users wrote:
> On 2020-01-24 13:49, Peter Pentchev wrote:
> > On Fri, Jan 24, 2020 at 09:05:36AM -0800, ToddAndMargo via perl6-users 
> > wrote:
> > > On 2020-01-24 01:17, Marcel Timmerman wrote:
> > > > On 1/23/20 6:28 PM, ToddAndMargo via perl6-users wrote:
> > > > > > > On Thu, Jan 23, 2020 at 11:51 AM ToddAndMargo via
> > > > > > > perl6-users  > > > > > > <mailto:perl6-us...@perl.org>> wrote:
> > > > > > > 
> > > > > > >      Hi All,
> > > > > > > 
> > > > > > >      This is just a trivia question.
> > > > > > > 
> > > > > > >      Does anyone know if the actual data stored in
> > > > > > >      Raku variables is little endian or big endian?
> > > > > > > 
> > > > > > >      -T
> > > > > 
> > > > > On 2020-01-23 09:07, Paul Procacci wrote:
> > > > > > endianess is dictate by the cpu.
> > > > > > If I store the value 4 into some memory address, the storage of
> > > > > > and retrieval thereof is controlled by the cpu.
> > > > > > 
> > > > > 
> > > > > Then I presume Raku rug on a Intel processor would
> > > > > be little endian.  So when I enter 0xFF44 it is
> > > > > really being stored as 44, FF in memory.  Interesting.
> > > > 
> > > > Most of the time you don't really need to know unless you move your data
> > > > from one machine to another in binary form. In that case you need a test
> > > > before interpreting the data.
> > > > 
> > > > Marcel
> > > 
> > > Hi Marcel,
> > > 
> > > The reason for the trivia quest was that I have been
> > > doing a lot of stuff with NativeCall lately and
> > > you have to prepare data in little endian to
> > > send to NativeCall and to interpret bytes of little
> > > endian when it come back.  So I was just curious.
> > > 
> > > Chuckle.  The travails of a high level language:
> > > take litle endian apart to put them back together
> > > to be restored in what looks like big endian but
> > > really is little endian under the hood.
> > 
> > I doubt anything really takes things apart... I'm not sure where you get
> > the "what looks like big-endian" from - Marcel's point was that Raku's
> > (or Perl's, or Python's, or...) integers and floats do not really look
> > like big-endian, they do not look like little-endian, they are
> > endian-agnostic. I'd bet that underneath moar and nqp do what is native
> > to the platform - so, in x86/amd64's case, Raku is probably
> > little-endian all the way, but you don't notice it, because you don't
> > need to.
> > 
> > G'luck,
> > Peter
> > 
> 
> 
> Hi Peter,
> 
> One of the guys over on the WinApi list gave
> me a WinAPI call written in assembly.  Probably
> the one and only time in all the ENTIRE history of
> programming where assembly was easier to do
> than a high(er) level language.  Chuckle!

Ehh, if by "easier" you mean "try to keep track of which registers to
pass the parameters in, where does the first one go, where does the
second one go, oh, there are too many parameters, I have to keep the
rest on the stack... OK, now which registers do I have to save? Nah,
this call promises it will preserve these ones, and I already have that
value in that variable over there, so I don't even need to save this
one... OK, now make the call... now what did it return, a long integer?
Ah, so it's in this register... no, wait, it returned a structure
containing two long integers, so the first one is here and the second
one is over there..."

...okay :)

G'luck,
Peter

PS. Don't get me wrong, I've done a lot of assembly language
programming, and it is undoubtedly the correct tool for some tasks.
Just... not all of them.

-- 
Peter Pentchev  roam@{ringlet.net,debian.org,FreeBSD.org} p...@storpool.com
PGP key:http://people.FreeBSD.org/~roam/roam.key.asc
Key fingerprint 2EE7 A7A5 17FC 124C F115  C354 651E EFB0 2527 DF13


signature.asc
Description: PGP signature


Re: endian

2020-01-24 Thread Peter Pentchev
On Fri, Jan 24, 2020 at 09:05:36AM -0800, ToddAndMargo via perl6-users wrote:
> On 2020-01-24 01:17, Marcel Timmerman wrote:
> > On 1/23/20 6:28 PM, ToddAndMargo via perl6-users wrote:
> > > > > On Thu, Jan 23, 2020 at 11:51 AM ToddAndMargo via
> > > > > perl6-users  > > > > <mailto:perl6-us...@perl.org>> wrote:
> > > > > 
> > > > >     Hi All,
> > > > > 
> > > > >     This is just a trivia question.
> > > > > 
> > > > >     Does anyone know if the actual data stored in
> > > > >     Raku variables is little endian or big endian?
> > > > > 
> > > > >     -T
> > > 
> > > On 2020-01-23 09:07, Paul Procacci wrote:
> > > > endianess is dictate by the cpu.
> > > > If I store the value 4 into some memory address, the storage of
> > > > and retrieval thereof is controlled by the cpu.
> > > > 
> > > 
> > > Then I presume Raku rug on a Intel processor would
> > > be little endian.  So when I enter 0xFF44 it is
> > > really being stored as 44, FF in memory.  Interesting.
> > 
> > Most of the time you don't really need to know unless you move your data
> > from one machine to another in binary form. In that case you need a test
> > before interpreting the data.
> > 
> > Marcel
> 
> Hi Marcel,
> 
> The reason for the trivia quest was that I have been
> doing a lot of stuff with NativeCall lately and
> you have to prepare data in little endian to
> send to NativeCall and to interpret bytes of little
> endian when it come back.  So I was just curious.
> 
> Chuckle.  The travails of a high level language:
> take litle endian apart to put them back together
> to be restored in what looks like big endian but
> really is little endian under the hood.

I doubt anything really takes things apart... I'm not sure where you get
the "what looks like big-endian" from - Marcel's point was that Raku's
(or Perl's, or Python's, or...) integers and floats do not really look
like big-endian, they do not look like little-endian, they are
endian-agnostic. I'd bet that underneath moar and nqp do what is native
to the platform - so, in x86/amd64's case, Raku is probably
little-endian all the way, but you don't notice it, because you don't
need to.

G'luck,
Peter

-- 
Peter Pentchev  roam@{ringlet.net,debian.org,FreeBSD.org} p...@storpool.com
PGP key:http://people.FreeBSD.org/~roam/roam.key.asc
Key fingerprint 2EE7 A7A5 17FC 124C F115  C354 651E EFB0 2527 DF13


signature.asc
Description: PGP signature


Re: I need syntax to sub declare return a hash and an array

2020-01-21 Thread Peter Pentchev
On Tue, Jan 21, 2020 at 07:16:17PM -0800, Todd Chester via perl6-users wrote:
> 
> 
> On 2020-01-21 18:57, Tom Browder wrote:
> > On Tue, Jan 21, 2020 at 18:34 Todd Chester via perl6-users
> > mailto:perl6-us...@perl.org>> wrote:
> > 
> > On 2020-01-21 16:09, Todd Chester via perl6-users wrote:
> >  >> 4) A block (that is the { ... } bit) will always 'return' the last
> >  >> expression evaluated.
> >  >
> >  > Seems to me I have see the last expression returned even without
> >  > the {...}.  Maybe I am misremembering.
> > 
> > 
> > Todd, the {} is the block defining the subroutine.
> > 
> >   > sub AplusB( $a, $b --> Int ){$a+$b;}
> > 
> > 
> > The above is the sub's definition.
> > 
> > 
> > 
> > 
> > 
> > 
> > The above should generate an error because the mandatory args are
> > missing, depending on the context (don't quote me on that).
> 
>  is printer out by REPL.  I don't know why.  REPL
> does that a lot.

The REPL tells you that the result of the expression you entered (the
sequence of characters "sub AplusB..{$a+$b}") was to define
a subroutine called "AplusB", which is what you wanted it to do.
The "&" sigil (a sigil is basically the character before a thing's name in
Raku and Perl 5) means that the name "AplusB" refers to a subroutine,
not a variable or anything else.

> >   > AplusB 2, 3
> > 5
> > 
> > The above shows the sub being called with the required two args, and the
> > 5 is the returned value which is probably shown in the REPL since there
> > is no semicolon after the call and the 5 is not usually seen otherwise.
> 
> $ p6 'sub AplusB( $a, $b --> Int ){$a+$b}; say AplusB 2, 3;'
> 5
> 
> 
> > -Tom
> 
> Hi Tom,
> 
> I was trying to cut things down to the simplest terms.
> I was responding to Richard's statement
> 
>  >> 4) A block (that is the { ... } bit) will always 'return' the last
>  >>expression evaluated.
> 
> I created a sub without the "{...}" and showed where it would
> return the last equation without the "{...}".  I may have
> misunderstood Richard.

You created a sub with "$a+$b" in a "{...}" block. The "{$a+$b}"
sequence of characters in what you typed is the "{...}" block that
Richard is referring to - a block that starts with a "{" character, ends
with a "}" character and contains a series of Raku expressions
separated by semicolons.

In your case the block only contains a single expression, "$a+$b", which
represents the sum of the two arguments to the subroutine - this is
*exactly* what Richard meant. If you were trying to illustrate his point
that a block without an explicit "return" statement would return
the last expression, you succeeded. If you were trying to demonstrate
something that does not have a "{...}", well, nope, "{$a+$b}" is exactly
the "{...}" that he was talking about, so the fact that AplusB returns
the sum of $a and $b is exactly what he meant.

G'luck,
Peter

-- 
Peter Pentchev  roam@{ringlet.net,debian.org,FreeBSD.org} p...@storpool.com
PGP key:http://people.FreeBSD.org/~roam/roam.key.asc
Key fingerprint 2EE7 A7A5 17FC 124C F115  C354 651E EFB0 2527 DF13


signature.asc
Description: PGP signature


Re: Ping JJ: string literals

2020-01-20 Thread Peter Pentchev
On Sun, Jan 19, 2020 at 12:20:18AM -0500, Paul Procacci wrote:
> On Sun, Jan 19, 2020 at 12:12 AM yary  wrote:
> 
> > In UTF-16 every character is 16 bits, so all 8 bits of zeros tells you is
> > that it's possibly a big-endian ascii character or a little-endian
> > non-ascii character at a position divisible by 256. All zeros U+ is
> > unicode NULL, which the windows UTF-16 C convention uses to terminate the
> > string.
> 
> Perfect.  Obviously didn't know that.  My assumption that only the first
> byte gets checked was obviously wrong.

It is correct if you're talking about UTF-8, not UTF-16 :)

G'luck,
Peter

-- 
Peter Pentchev  roam@{ringlet.net,debian.org,FreeBSD.org} p...@storpool.com
PGP key:http://people.FreeBSD.org/~roam/roam.key.asc
Key fingerprint 2EE7 A7A5 17FC 124C F115  C354 651E EFB0 2527 DF13


signature.asc
Description: PGP signature


Re: definition confusion of + and +^

2020-01-20 Thread Peter Pentchev
On Sun, Jan 19, 2020 at 08:25:15PM -0800, ToddAndMargo via perl6-users wrote:
> One last question on htis.  What does
> 
> multi sub prefix:<+^>(Any --> Int:D)
> 
> Mean.  Prefix means before.  +^(Any) get
> me a participation trophy, so I do not
> understand.
> 
> 
> :'(
> 
> INQUIRING MINDS WANT TO KNOW! (That is
> a joke referencing a tabloid commercial.)

The <> characters surround the name of the operator, so the operator is
named "+^". This means that you would use it on $foo as:

$something = +^$foo;

The part in the parentheses is a description of what arguments this
function (the operator that we are now describing in terms of functions)
will take and what type it will return. The part before the --> sign is
what arguments it takes - in this case it takes a single argument that
must be of the Any type or one of its subtypes, so pretty much anything
(yeah, yeah, I know) in Raku may be used as an argument to this
operator. The part after the --> sign describes the type of the value
that the function (the +^ operator) will return - it says that the
returned value will be an integer and that it will always have a
definite value, it will not be an undefined value.

So this means that whatever you have in a variable $foo, you may write
+^$foo and you will get an integer.

G'luck,
Peter

-- 
Peter Pentchev  roam@{ringlet.net,debian.org,FreeBSD.org} p...@storpool.com
PGP key:http://people.FreeBSD.org/~roam/roam.key.asc
Key fingerprint 2EE7 A7A5 17FC 124C F115  C354 651E EFB0 2527 DF13


signature.asc
Description: PGP signature


Re: more unixish perl6?

2019-09-24 Thread Peter Pentchev
On Tue, Sep 24, 2019 at 09:50:06AM +0200, Marc Chantreux wrote:
> hello,
> 
> i don't know if it's useful to feedback on it but i would like to share
> about MAIN.
> 
> this is a very nice thing to have it built-in so the quality of your
> scripts can be improved without effort ($*USAGE is very nice!) but
> here are some parts i feel i miss.
> 
> * dealing with $*ARGFILES should be simpler (something like the closing @ in
>   perl5 signatures)
> * a support of arguments cluster would be (both '-s -d +' and  '-sd+' should 
> be valid)

I know this is not quite what you're looking for, but JFTR (shameless
plug) there is the Getopt::Std Perl 6 module that implements old-style
getopt()-like argument parsing. The downsides are that it does not
support long options (this is on purpose - I personally am not a big fan
of long options, although I do understand why others may like them),
it does not do automatic --help and --version handling (also on purpose,
maybe I'm a bit of a control freak, but I do like the code paths to be
explicit), and, of course, it does not have the awesome Perl 6 "multi
sub MAIN" automated handling of groups of options :)

> * having something like auto-help that print $*USAGE on $*OUT
> 
>   multi sub MAIN ( Bool :h(:$help), +@rest ) { $*USAGE.say }

Just to make it clear: I very much like that Perl 6 has automated
options handling depending on the arguments to MAIN, it's just that some
of my programs do not need it.

> aside: the perl6 error messages comes with escape caracters even if $*ERR 
> isn't tty.
> this is unusual and makes things boring when you capture the error into
> an editor or a filter. i don't know if it can be useful in some cases.

G'luck,
Peter

-- 
Peter Pentchev  roam@{ringlet.net,debian.org,FreeBSD.org} p...@storpool.com
PGP key:http://people.FreeBSD.org/~roam/roam.key.asc
Key fingerprint 2EE7 A7A5 17FC 124C F115  C354 651E EFB0 2527 DF13


signature.asc
Description: PGP signature


Re: I need help with "lines"

2019-03-15 Thread Peter Pentchev
On Fri, Mar 15, 2019 at 07:52:57AM -0700, Todd Chester via perl6-users wrote:
> 
> 
> On 3/15/19 2:52 AM, Peter Pentchev wrote:
> > 1. Learn to use pgrep instead of the myriad variations of ps | grep;
> > pgrep has been standardized by POSIX for a long time and is almost
> > certainly available in all the installations that you will ever need
> > to touch[1].
> 
> pgrep is interesting!  But it is not listing all the processes.  :'(
> 
> $ pgrep firefox
> 2135
> 
> $ ps ax | grep [f]irefox | awk '{print $1}'
> 2135
> 2239
> 2342
> 2425

So maybe play around with its options a bit; take a look at its manual page.
Also note that "ps ax | grep [f]irefox" (and I would VERY STRONGLY suggest
that you put the argument to "grep" in quotes to avoid the shell interpreting
it in weird and wonderful ways) might also match a process with a different
name that has "firefox" in its list of arguments - actually that's
the crazy reason for the '[f]irefox' hack, since this way the grep process
will not find itself (it's a variation of a "ps ax | grep firefox | grep -v 
grep"
construct that people still seem to want to use).

G'luck,
Peter

-- 
Peter Pentchev  roam@{ringlet.net,debian.org,FreeBSD.org} p...@storpool.com
PGP key:http://people.FreeBSD.org/~roam/roam.key.asc
Key fingerprint 2EE7 A7A5 17FC 124C F115  C354 651E EFB0 2527 DF13


signature.asc
Description: PGP signature


Re: I need help with "lines"

2019-03-15 Thread Peter Pentchev
On Fri, Mar 15, 2019 at 07:58:11AM -0700, Todd Chester via perl6-users wrote:
> 
> 
> On 3/15/19 3:02 AM, Peter Pentchev wrote:
> > On Fri, Mar 15, 2019 at 11:52:15AM +0200, Peter Pentchev wrote:
> > [snip]
> > > 3. The standard input stream in Perl 6 is called $*IN (think of it as
> > > mostly equivalent to what <<>> and <> would read from in Perl 5,
> > 
> > ...sorry about this part, I know it's not correct.
> > 
> > > and pretty much the same thing as Perl 5's STDIN.
> > 
> > ...this is the correct statement.
> > 
> > > sub is-ours($line) {
> > >   $line ~~ /^ \s* $ = [\d+] \s+ "zsh" \s .* \s+ $ = [ <[- 
> > > \d :]> + ] $/
> > >   ?? (~$/ => pad-elapsed $/)
> > >   !! Any
> > > }
> > 
> > Of course, you may need to modify this a bit if you don't want to look
> > for "zsh" processes... :)
> > 
> > G'luck,
> > Peter
> > 
> 
> 
> Never did figure out why everything went into @x[0]

What do you mean "everything"?  If you have an array (or a sequence) and
you sort it, you have another array (or sequence) with the same members,
but in a different order.  Then, if you only want the largest (or smallest,
or whatever) member, that means that you only want the first element of
the array.

G'luck,
Peter

-- 
Peter Pentchev  roam@{ringlet.net,debian.org,FreeBSD.org} p...@storpool.com
PGP key:http://people.FreeBSD.org/~roam/roam.key.asc
Key fingerprint 2EE7 A7A5 17FC 124C F115  C354 651E EFB0 2527 DF13


signature.asc
Description: PGP signature


Re: I need help with "lines"

2019-03-15 Thread Peter Pentchev
On Fri, Mar 15, 2019 at 11:52:15AM +0200, Peter Pentchev wrote:
[snip]
> 3. The standard input stream in Perl 6 is called $*IN (think of it as
>mostly equivalent to what <<>> and <> would read from in Perl 5,

...sorry about this part, I know it's not correct.

> and pretty much the same thing as Perl 5's STDIN.

...this is the correct statement.

> sub is-ours($line) {
>   $line ~~ /^ \s* $ = [\d+] \s+ "zsh" \s .* \s+ $ = [ <[- 
> \d :]> + ] $/
>   ?? (~$/ => pad-elapsed $/)
>   !! Any
> }

Of course, you may need to modify this a bit if you don't want to look
for "zsh" processes... :)

G'luck,
Peter

-- 
Peter Pentchev  roam@{ringlet.net,debian.org,FreeBSD.org} p...@storpool.com
PGP key:http://people.FreeBSD.org/~roam/roam.key.asc
Key fingerprint 2EE7 A7A5 17FC 124C F115  C354 651E EFB0 2527 DF13


signature.asc
Description: PGP signature


Re: I need help with "lines"

2019-03-15 Thread Peter Pentchev
s/16   Ss+0:02 -zsh").Seq

OK, so we have the lines read from the standard input; let's see if we
can get the first word of each line:

[roam@straylight ~]$ ps ax | grep -e '[z]sh' | perl6 -e 'dd $*IN.lines.map: 
*.words[0]'
("3469", "3876", "8782", "10041", "10257", "10523", "10728", "10959", "11196", 
"11236", "17512", "17905", "18089", "18846", "19232", "19808", "20368", 
"21046", "21232", "24099", "29673").Seq

Right, but we want them as integers, right?

[roam@straylight ~]$ ps ax | grep -e '[z]sh' | perl6 -e 'dd $*IN.lines.map: 
*.words[0].Int'
(3469, 3876, 8782, 10041, 10257, 10523, 10728, 10959, 11196, 11236, 17512, 
17905, 18089, 18846, 19232, 19808, 20368, 21046, 21232, 24099, 29673).Seq

Let's sort them in reverse; note that we need to put the whole construct
so far in parentheses - we can't just stick a ".sort" at the end, since
it will operate only on a single integer, and that makes no sense.  We
need to take the whole sequence returned by ".map" and then sort it:

[roam@straylight ~]$ ps ax | grep -e '[z]sh' | perl6 -e 'dd ($*IN.lines.map: 
*.words[0].Int).sort.reverse'
(29673, 24099, 21232, 21046, 20368, 19808, 19232, 18846, 18089, 17905, 17512, 
11236, 11196, 10959, 10728, 10523, 10257, 10041, 8782, 3876, 3469).Seq

And now to only get the largest process ID:

[roam@straylight ~]$ ps ax | grep -e '[z]sh' | perl6 -e 'dd ($*IN.lines.map: 
*.words[0].Int).sort.reverse[0]'
29673

Actually we can put the parentheses in a slightly different place, too:

[roam@straylight ~]$ ps ax | grep -e '[z]sh' | perl6 -e 'dd 
$*IN.lines.map(*.words[0].Int)'
(3469, 3876, 8782, 10041, 10257, 10523, 10728, 10959, 11196, 11236, 17512, 
17905, 18089, 18846, 19232, 19808, 20368, 21046, 21232, 24099, 29673).Seq

OK, now let's see if pgrep would have helped:

[roam@straylight ~]$ pgrep zsh | perl6 -e 'dd 
$*IN.lines.map(*.Int).sort.reverse[0]'
29673

Yep, thought so :)  However... hm, you say you want the largest process
ID, but I'm not sure that this is *really* what you *need*; do you not
need the process that *started the most recently*?  (you know, on a long
running system the process IDs may wrap; this depends on the system,
some of them have really, really large process IDs, but some of them
also use them for other purposes, so still).  Unfortunately, this is
the point where the fun of using standardized utilities ends, since
for this next step it would be best to have a BSD-like ps(1) which
understands "-o" and has the "etime" format specifier.  So, left as
an exercise for the reader, how about this:

ps x -o pid,comm,etime | perl6 -e 'dd $*IN.lines.map({ /^ \s* $ = [\d+] 
\s+ "zsh" \s .* \s+ $ = [ <[- \d :]> + ] $/ ?? (~$/ => (0, 0, 0, 
|$/.split(/<[-:]>/).map(*.Int))[*-4..*]) !! Any 
}).grep(*.defined).sort(*.value)[0].key'

Yes, I know it's a lot :) Take a look at it, see if you can break it
down into meaningful parts, see how those parts interplay; if you have
any questions, feel free to ask.  And, BTW, yes, on my Debian system
this showed a process with ID 29673 running for more than 20 days and
then a process with ID 23280 running for less than thirty minutes, so,
yes, this is what you need, not the largest process ID.

...okay, okay, here goes the very complex line above changed into
a somewhat readable program:

#!/usr/bin/env perl6

use v6.c;

sub pad-elapsed($elapsed) {
my @ints = $elapsed.split(/<[-:]>/).map: *.Int;
my @padded = (0, 0, 0, |@ints);
return @padded[*-4..*];
}

sub is-ours($line) {
$line ~~ /^ \s* $ = [\d+] \s+ "zsh" \s .* \s+ $ = [ <[- 
\d :]> + ] $/
?? (~$/ => pad-elapsed $/)
!! Any
}

my @only-ours = $*IN.lines.map();
my @only-real-ones = @only-ours.grep(*.defined);
my @sorted = @only-real-ones.sort(*.value);
my $latest-pid = @sorted[0].key;

say $latest-pid;

Hope that helped!

G'luck,
Peter

[1] The "almost certainly" is because, yes, yes, I know, I also have that
dusty old HP/UX crunching away in a customer's basement; still.

-- 
Peter Pentchev  roam@{ringlet.net,debian.org,FreeBSD.org} p...@storpool.com
PGP key:http://people.FreeBSD.org/~roam/roam.key.asc
Key fingerprint 2EE7 A7A5 17FC 124C F115  C354 651E EFB0 2527 DF13


signature.asc
Description: PGP signature


Re: contains booboo

2018-12-19 Thread Peter Pentchev
On Wed, Dec 19, 2018 at 04:14:37AM -0800, ToddAndMargo via perl6-users wrote:
> > > Le mer. 19 déc. 2018 à 08:57, ToddAndMargo via perl6-users
> > > mailto:perl6-us...@perl.org>> a écrit :
> > > 
> > >  >> On Tue, Dec 18, 2018 at 10:49 PM ToddAndMargo via perl6-users
> > >  >> mailto:perl6-us...@perl.org>
> > > <mailto:perl6-us...@perl.org <mailto:perl6-us...@perl.org>>> wrote:
> > >  >>
> > >  >> Hi All,
> > >  >>
> > >  >> Where is my booboo?
> > >  >>
> > >  >> $ p6 'my$x="abcd"; if $x.contains("b" && not "q") {say
> > > "y"}else{say
> > >  >> "n"};'
> > >  >>
> > >  >> n
> > >  >>
> > >  >>
> > >  >> In the mean time, I will ue
> > >  >>   if $x.contains("b") && not $x.contains( "q" )
> > >  >>
> > >  >>
> > >  >> Many thanks,
> > >  >> -T
> > > 
> > > On 12/18/18 4:13 PM, Ralph Mellor wrote:
> > >  > .contains tests whether its invocant, treated as a string,
> > > contains its
> > >  > argument, treated as a string.
> > >  >
> > >  > The argument you've given to .contains is:
> > >  >
> > >  > "b" && not "q".
> > >  >
> > >  > That's not a string.
> > >  >
> > >  > Here's one option:
> > >  >
> > >  > my$x="abcd"; if $x.contains("b") && not $x.contains("q") {say
> > >  > "y"}else{say "n"};
> > >  >
> > > 
> > > Hi Ralph,
> > > 
> > > That was my work around.
> > > 
> > > The reason I asked the question was the following:
> > > 
> > > $ p6 'my$x="abcd"; if $x.contains("b" & "d") {say "y"}else{say "n"};'
> > > y
> > > 
> > > $ p6 'my$x="abcd"; if $x.contains("b" & "e") {say "y"}else{say "n"};'
> > > n
> > > 
> > > So it seemed to me that the following should also work, which
> > > it does not:
> > > 
> > > Should be "y"
> > > $ p6 'my$x="abcd"; if $x.contains("b" & not "e") {say "y"}else{say
> > > "n"};'
> > > n
> > > 
> > > Should be "n" and it is
> > > $ p6 'my$x="abcd"; if $x.contains("b" & not "d") {say "y"}else{say
> > > "n"};'
> > > n
> > > 
> > > 
> > > I think maybe I am pushing the limits.  Perl has 101 way of
> > > doing everything.  It think I am pushing 102.
> > > 
> > > -T
> > > 
> 
> On 12/19/18 12:37 AM, Laurent Rosenfeld via perl6-users wrote:
> > Hi Todd,
> > 
> > first, please don't mix up the && Boolean operator and infix &, an /all/
> > junction operator.
> > 
> > Also consider the difference between the following code snippets:
> > 
> > > my$x="abcd"; if $x.contains(not "e") {say "y"}else{say "n"};
> > n
> > > my$x="abcd"; if $x.contains(none "e") {say "y"}else{say "n"};
> > y
> > 
> > Or between these:
> > 
> > > my$x="abcd"; if $x.contains("b" & (not "d")) {say "y"}else{say "n"};
> > n
> > > my$x="abcd"; if $x.contains("b" & (none "e")) {say "y"}else{say "n"};
> > y
> > 
> > HTH, Laurent.
> 
> "none" sweet.  I did not know I could do that.  Thank you!
> Got to get my "not"'s straightened out too.

Please note that the difference between "none" and "not" is exactly
the same as the difference between "&" and "&&" - one is a junction
operator (BTW let me just say "sweet!" and thank the Perl 6 gods for
bringing this to us!) and the other is a Boolean logical operator.

G'luck,
Peter

-- 
Peter Pentchev  roam@{ringlet.net,debian.org,FreeBSD.org} p...@storpool.com
PGP key:http://people.FreeBSD.org/~roam/roam.key.asc
Key fingerprint 2EE7 A7A5 17FC 124C F115  C354 651E EFB0 2527 DF13


signature.asc
Description: PGP signature


Re: How do I address bytes in a Buf/binary variable?

2018-10-08 Thread Peter Pentchev
On Mon, Oct 08, 2018 at 01:38:54AM -0700, ToddAndMargo via perl6-users wrote:
> On 10/8/18 1:34 AM, Peter Pentchev wrote:
> > On Mon, Oct 08, 2018 at 01:25:31AM -0700, ToddAndMargo via perl6-users 
> > wrote:
> > > Hi All!
> > > 
> > > Question: I am using `read` to read the first 400 bytes of an unknown file
> > > (could be a binary file).  The 400 bytes go into a variable
> > > of type "Buf".  This is not a string.
> > > 
> > > p6 'my $fh=open "/home/linuxutil/To", :r; my Buf $f = $fh.read( 400 );
> > > $fh.close;'
> > > 
> > > Now in $f, I want to look at each byte one at a time for a
> > > bitwise pattern using bitwise AND.
> > > 
> > > How do I address each byte?
> > > 
> > > `dd` seems to get me the information I need, but it prints it:
> > > 
> > >  $ p6 'my $fh=open "/home/linuxutil/To", :r; my Buf $f = $fh.read( 10 
> > > );
> > > $fh.close; dd $f;'
> > > 
> > >  Buf[uint8] $f = Buf[uint8].new(87,111,114,100,80,114,111,0,0,0)
> > > 
> > > An array of bytes would be great.
> > 
> > Point a browser at https://docs.perl6.org/ and click on "Types" in
> > the top ribbon.  You will see a list of all the Perl 6 built-in types;
> > "Buf" is there near the top.  Click on "Buf".
> 
> Been there, done that already.  No idea what it said.

OK, so for future reference, when you see a reference page for a type
like that, look at the left side to see which roles it implements and
which methods it takes from these roles.  As I wrote below, in this case
the Positional role could have been a clue that you can address a Buf
object using [index] (I seem to remember another thread of yours with
people explaining the Positional role).

Also, in the future, take a look at the code in the examples; in this
particular case, the use of "$b[1]" could have been a hint.

> > Now there are two clues as to what you want: one of them is that
> > the table of contents on the left has a section "Routines supplied by
> > role Positional", and the other one is that the very first example
> > has a line saying "$b[1] = 42".
> > 
> > So you can use a Buf object as an array of whatever it contains.
> > 
> > G'luck,
> > Peter
> > 
> 
> Hi Peter,
> 
> Perfect!  Exactly what I was after!

Glad it worked out for you!

G'luck,
Peter

-- 
Peter Pentchev  roam@{ringlet.net,debian.org,FreeBSD.org} p...@storpool.com
PGP key:http://people.FreeBSD.org/~roam/roam.key.asc
Key fingerprint 2EE7 A7A5 17FC 124C F115  C354 651E EFB0 2527 DF13


signature.asc
Description: PGP signature


Re: How do I address bytes in a Buf/binary variable?

2018-10-08 Thread Peter Pentchev
On Mon, Oct 08, 2018 at 01:25:31AM -0700, ToddAndMargo via perl6-users wrote:
> Hi All!
> 
> Question: I am using `read` to read the first 400 bytes of an unknown file
> (could be a binary file).  The 400 bytes go into a variable
> of type "Buf".  This is not a string.
> 
> p6 'my $fh=open "/home/linuxutil/To", :r; my Buf $f = $fh.read( 400 );
> $fh.close;'
> 
> Now in $f, I want to look at each byte one at a time for a
> bitwise pattern using bitwise AND.
> 
> How do I address each byte?
> 
> `dd` seems to get me the information I need, but it prints it:
> 
> $ p6 'my $fh=open "/home/linuxutil/To", :r; my Buf $f = $fh.read( 10 );
> $fh.close; dd $f;'
> 
> Buf[uint8] $f = Buf[uint8].new(87,111,114,100,80,114,111,0,0,0)
> 
> An array of bytes would be great.

Point a browser at https://docs.perl6.org/ and click on "Types" in
the top ribbon.  You will see a list of all the Perl 6 built-in types;
"Buf" is there near the top.  Click on "Buf".

Now there are two clues as to what you want: one of them is that
the table of contents on the left has a section "Routines supplied by
role Positional", and the other one is that the very first example
has a line saying "$b[1] = 42".

So you can use a Buf object as an array of whatever it contains.

G'luck,
Peter

-- 
Peter Pentchev  roam@{ringlet.net,debian.org,FreeBSD.org} p...@storpool.com
PGP key:http://people.FreeBSD.org/~roam/roam.key.asc
Key fingerprint 2EE7 A7A5 17FC 124C F115  C354 651E EFB0 2527 DF13


signature.asc
Description: PGP signature


Re: routine declaration line question

2018-10-04 Thread Peter Pentchev
> > > Now All I have to figure out is how tot tell "what" is being
> > > returned.  Am I suppose to pick that up from context?
> > > 
> > > -T
> 
> 
> On 10/3/18 10:02 PM, Brad Gilbert wrote:
> > If a routine does not declare it's return type, absolutely anything
> > can be returned.
> >
> > One reason may be that its return value isn't really useful.
> >
> > It could be that the writer didn't think to declare it. (or didn't want
> to)
> >
> > Another possibility is that the potential returned values are of many
> > different types.
> >
> > ---
> >
> > Note that any returned value that gets ignored will get sunk.
> > (That means the `.sink()` method will get called)
> >
> >  class Baz {
> >  method sink () { say 'the result of foo() was sunk' }
> >  }
> >  sub foo () {
> >  Baz.new
> >  }
> >
> >  foo(); # the result of foo() was sunk
> >
> > So I suppose it is similar to Modula2, except it is up to the writer
> > of the class if they shake their finger at you.
> > On Wed, Oct 3, 2018 at 10:26 PM ToddAndMargo 
> 
> Thank you.  The default return is Mu.  That I get.
> 
> How do I figure out what data is being returned? Trial and error?

You just quoted Brad Gilbert's message.  Please reread the part that
starts with "If a routine does not declare a return type..." and
goes on until "...of many different types."  If the routine's
documentation does not describe its return value, it probably falls
under the "not useful" umbrella.  If the documentation does describe
it, there you have it.

Before continuing on this abstract "how do I tell in general" part,
let us know which routines exactly are you wondering right now about.

G'luck,
Peter

-- 
Peter Pentchev  roam@{ringlet.net,debian.org,FreeBSD.org} p...@storpool.com
PGP key:http://people.FreeBSD.org/~roam/roam.key.asc
Key fingerprint 2EE7 A7A5 17FC 124C F115  C354 651E EFB0 2527 DF13


signature.asc
Description: PGP signature


Re: [perl #127566] [BUG] run hangs on slurp-rest with :out and :err if command runs background process

2016-02-19 Thread Peter Pentchev
On Thu, Feb 18, 2016 at 12:02:48PM -0800, Simon Ruderich wrote:
> # New Ticket Created by  Simon Ruderich 
> # Please include the string:  [perl #127566]
> # in the subject line of all future correspondence about this issue. 
> # https://rt.perl.org/Ticket/Display.html?id=127566 >
> 
> 
> Hello,
> 
> I'm having a weird problem with run. In the following sample,
> Perl6 waits after "slurping err" when the ssh mux process gets
> spawned in the background on the initial connection. It waits
> until the ssh mux process terminates on its own and then prints
> the output (stdout/stderr) correctly. If the ssh mux process is
> already running, everthing works fine.
> 
> my @cmd = «
> ssh
> -o Protocol=2
> -o ControlMaster=auto
> -o ControlPath=master-%l-%h-%r
> -o ControlPersist=30
> »;
> @cmd.append('root@steep', 'ls');

I don't think this is a Perl problem; I believe it may be a real
OpenSSH bug (or, at least, unexpected behavior).

The problem is that when your SSH client decides to start the mux
process, the latter *does not close* its standard error stream;
it keeps file descriptor 2 open to whatever the original SSH client
had it open to - usually this is the user's terminal, but in your
case, it's the pipe back to your program.  Even though the original
SSH client process exited, the pipe is still open (to another process,
yet still open anyway), and Perl is absolutely correct to wait for
everything that has the pipe open to close it.  This does not even
come from Perl, it's your OS's kernel doing it - but, since there is
a process still using the pipe, it's correct to do it that way :(

As far as I can see, this behavior - leaving fd 2 open to the original
client's standard error stream - is not explicitly documented in
either the ssh(1) manual page or the ssh_config(5) one.  I've even
tried passing the -E option to send the debug logs to someplace else,
but it does indeed only affect the debug logs, not the actual standard
error stream :(

I wonder if it might be worthwhile to raise this with the OpenSSH
developers; I could do that if you'd like me to.

G'luck,
Peter

-- 
Peter Pentchev  r...@ringlet.net r...@freebsd.org p...@storpool.com
PGP key:http://people.FreeBSD.org/~roam/roam.key.asc
Key fingerprint 2EE7 A7A5 17FC 124C F115  C354 651E EFB0 2527 DF13


signature.asc
Description: PGP signature


Re: It's time to use "use 6.c"

2016-02-09 Thread Peter Pentchev
On Sat, Feb 06, 2016 at 08:20:14PM -0500, yary wrote:
> Thanks all... I expect hiccups... just venting to help (future coders
> and current self)... while we're on this topic
> 
> a) lwp-download.pl doesn't have a "use 6". Since Windows ignores the
> shebang, it invokes perl5 which is registered to handle "pl" files,
> and gives a bunch of syntax errors. If it did have "use 6" at the top,
> then it would give a single more meaningful error... yet another
> reason for module authors to put "use 6" in their code.
> 
> b) subject line should be "use 6.c", the "v" is depreciated... edited

For the record, just to clear up some possible confusion, "use 6.c"
doesn't work in source files; you need "use v6.c".

G'luck,
Peter

-- 
Peter Pentchev  r...@ringlet.net r...@freebsd.org p...@storpool.com
PGP key:http://people.FreeBSD.org/~roam/roam.key.asc
Key fingerprint 2EE7 A7A5 17FC 124C F115  C354 651E EFB0 2527 DF13


signature.asc
Description: PGP signature


run "...", :out forgetting about the exit code?

2016-02-02 Thread Peter Pentchev
Hi,

[roam@straylight ~]$ perl6 -e 'use v6.c; use strict; my $p = run "false"; say 
$p.exitcode;'1
[roam@straylight ~]$ perl6 -e 'use v6.c; use strict; my $p = run "false", :out; 
say $p.exitcode;'
0
[roam@straylight ~]$ perl6 -e 'use v6.c; use strict; my $p = run "false", :out; 
print $p.out.slurp-rest; say $p.exitcode;'
0
[roam@straylight ~]$ 

So, uhm, what am I missing?  Shouldn't $p.exitcode remain 1 no matter whether
I've invoked run() with or without :out?  Should I file a bug?

It doesn't matter whether the program actually produces any output on
the standard output stream:

[roam@straylight ~]$ perl6 -e 'use v6.c; use strict; my $p = run "sh", "-c", 
"env LANG=C date; exit 3"; say $p.exitcode;'
   
Wed Feb  3 01:34:50 EET 2016
3
[roam@straylight ~]$ perl6 -e 'use v6.c; use strict; my $p = run "sh", "-c", 
"env LANG=C date; exit 3", :out; say "<<<" ~ $p.out.slurp-rest ~ ">>>"; say 
$p.exitcode;'   
 
<<>>
0
[roam@straylight ~]$

This happens absolutely reproducibly on all of the following:

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

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

This is Rakudo version 2016.01.1 built on MoarVM version 2016.01
implementing Perl 6.c.

My system is Debian testing:

Linux straylight 4.3.0-1-amd64 #1 SMP Debian 4.3.3-5 (2016-01-04) x86_64 
GNU/Linux

Thanks in advance for any clarifications, including "what the *bleep*,
just read this line of the documentation already!" :)

G'luck,
Peter

-- 
Peter Pentchev  r...@ringlet.net r...@freebsd.org p...@storpool.com
PGP key:http://people.FreeBSD.org/~roam/roam.key.asc
Key fingerprint 2EE7 A7A5 17FC 124C F115  C354 651E EFB0 2527 DF13


signature.asc
Description: PGP signature


Re: run "...", :out forgetting about the exit code?

2016-02-02 Thread Peter Pentchev
On Wed, Feb 03, 2016 at 01:37:18AM +0200, Peter Pentchev wrote:
> Hi,
> 
> [roam@straylight ~]$ perl6 -e 'use v6.c; use strict; my $p = run "false"; say 
> $p.exitcode;'1
> [roam@straylight ~]$ perl6 -e 'use v6.c; use strict; my $p = run "false", 
> :out; say $p.exitcode;'
> 0
> [roam@straylight ~]$ perl6 -e 'use v6.c; use strict; my $p = run "false", 
> :out; print $p.out.slurp-rest; say $p.exitcode;'
> 0
> [roam@straylight ~]$ 
> 
> So, uhm, what am I missing?  Shouldn't $p.exitcode remain 1 no matter whether
> I've invoked run() with or without :out?  Should I file a bug?

Just for the record, my $p = Proc.new(:out); $p.spawn(...); behaves in
exactly the same way (no big surprise there, just thought I'd check).

G'luck,
Peter

-- 
Peter Pentchev  r...@ringlet.net r...@freebsd.org p...@storpool.com
PGP key:http://people.FreeBSD.org/~roam/roam.key.asc
Key fingerprint 2EE7 A7A5 17FC 124C F115  C354 651E EFB0 2527 DF13


signature.asc
Description: PGP signature


Re: run "...", :out forgetting about the exit code?

2016-02-02 Thread Peter Pentchev
On Wed, Feb 03, 2016 at 01:37:18AM +0200, Peter Pentchev wrote:
> Hi,
> 
> [roam@straylight ~]$ perl6 -e 'use v6.c; use strict; my $p = run "false"; say 
> $p.exitcode;'1
> [roam@straylight ~]$ perl6 -e 'use v6.c; use strict; my $p = run "false", 
> :out; say $p.exitcode;'
> 0
> [roam@straylight ~]$ perl6 -e 'use v6.c; use strict; my $p = run "false", 
> :out; print $p.out.slurp-rest; say $p.exitcode;'
> 0
> [roam@straylight ~]$ 
> 
> So, uhm, what am I missing?  Shouldn't $p.exitcode remain 1 no matter whether
> I've invoked run() with or without :out?  Should I file a bug?
> 
> It doesn't matter whether the program actually produces any output on
> the standard output stream:
> 
> [roam@straylight ~]$ perl6 -e 'use v6.c; use strict; my $p = run "sh", "-c", 
> "env LANG=C date; exit 3"; say $p.exitcode;'  
>  
> Wed Feb  3 01:34:50 EET 2016
> 3
> [roam@straylight ~]$ perl6 -e 'use v6.c; use strict; my $p = run "sh", "-c", 
> "env LANG=C date; exit 3", :out; say "<<<" ~ $p.out.slurp-rest ~ ">>>"; say 
> $p.exitcode;' 
>
> << >>>
> 0
> [roam@straylight ~]$

Hm.  Okay.  I think I figured it out.  When I added a $p.out.close
call to make sure that the process has *really* exited, it threw
a X::Proc::Unsuccessful exception at me right there.  For some
reason I thought that assigning the process to a variable would
protect me from the exception.

However, I'm still a bit confused - the Proc documentation seems to
say that exitcode() will return -1, not 0, if the process has not
ended yet.  Is this the real problem here?

G'luck,
Peter

-- 
Peter Pentchev  r...@ringlet.net r...@freebsd.org p...@storpool.com
PGP key:http://people.FreeBSD.org/~roam/roam.key.asc
Key fingerprint 2EE7 A7A5 17FC 124C F115  C354 651E EFB0 2527 DF13


signature.asc
Description: PGP signature


Re: run "...", :out forgetting about the exit code?

2016-02-02 Thread Peter Pentchev
On Tue, Feb 02, 2016 at 06:41:12PM -0500, Brandon Allbery wrote:
> On Tue, Feb 2, 2016 at 6:37 PM, Peter Pentchev <r...@ringlet.net> wrote:
> 
> > So, uhm, what am I missing?  Shouldn't $p.exitcode remain 1 no matter
> > whether
> > I've invoked run() with or without :out?  Should I file a bug?
> >
> 
> https://rt.perl.org/Ticket/Display.html?id=125757

Oof, right.  Yeah, as witnessed by my other mail, I did realize that
the process was still running.  Still, as mentioned there,
http://doc.perl6.org/type/Proc#method_exitcode says something about
-1 if the process has not exited yet; I guess that's what threw me.

Thanks, and sorry for not looking through RT!

G'luck,
Peter

-- 
Peter Pentchev  r...@ringlet.net r...@freebsd.org p...@storpool.com
PGP key:http://people.FreeBSD.org/~roam/roam.key.asc
Key fingerprint 2EE7 A7A5 17FC 124C F115  C354 651E EFB0 2527 DF13


signature.asc
Description: PGP signature


Re: Failed to install latest Rakudo

2016-02-02 Thread Peter Pentchev
On Tue, Feb 02, 2016 at 08:45:44PM -0600, Tom Browder wrote:
> I entered:
> 
>   $ rakudobrew build moar 2016.01.1
> 
> and after a while I saw:
> 
> 
> Rakudo has been built and installed.
> Updating shims
> Done, moar-2016.01.1 built
> 
> 
> Then:
> 
>   $ perl6 -v
> This is Rakudo version 2015.12 built on MoarVM version 2015.12
> implementing Perl 6.c.
> 
> Am I doing something wrong?  As far as I know, that's the incantation
> I have used on most previous upgrades (except I always seemed to get
> the latest Rakudo without specifying the release version).

Try these:

  rakudobrew current
  rakudobrew versions
  rakudobrew switch 2016.01.1
  rakudobrew current

What you say about previous upgrades sounds a bit weird to me -
it's true that I only started with 2015.12, but with the current at
that time version of rakudobrew, it always left me at the known-good
version after an upgrade, it never switched automatically to
the just-built one; I've always had to "rakudobrew switch" by hand.
It's possible that earlier versions would switch automatically, but
the current behavior actually sounds reasonable from a reliability
point of view, too.

G'luck,
Peter

-- 
Peter Pentchev  r...@ringlet.net r...@freebsd.org p...@storpool.com
PGP key:http://people.FreeBSD.org/~roam/roam.key.asc
Key fingerprint 2EE7 A7A5 17FC 124C F115  C354 651E EFB0 2527 DF13


signature.asc
Description: PGP signature


Re: Finding and fixing Perl 6 bugs

2016-02-02 Thread Peter Pentchev
On Tue, Feb 02, 2016 at 09:17:23PM -0600, Tom Browder wrote:
> This page:
> 
>   http://perl6.org/getting-started/involved
> 
> references finding and fixing bugs but it doesn't point to further help.
> 
> At the very least I believe there should be on that page a list of all the
> Perl 6 projects and what address to send bug reports to. Also a
> consolidated list of preferred subject tags to help categorize bugs would
> probably help everyone.
> 
> Perl 5 (and I believe 6) uses the weird (to me) rt.perl.org bug system and
> I have so far found no instructions on how to use it.  There is the program
> perlbug for Perl 5 but no reference I can find on using it for Perl 6.  I
> have an account on rt.perl.bug but cannot find anything other than my
> non-existent entries.  There is a public interface so ordinary users can
> see bugs but apparently not do anything about it.

Well, I've had some success filing a RT request recently; the workflow
was something like that:
- go to rt.perl.org
- if somewhere near the upper left corner of your screen there's text
  saying "Welcome anonymous guest", click "Login as another user" right
  next to it
- if you don't have a Bitcard account, create one, it's a matter of seconds
- click on the "Log in with it" text in the "Bitcard account" box
- after logging in, you should see a localized button saying something like
  "New ticket" near the upper right corner of your screen; there's a listbox
  next to it allowing you to choose the Perl version to file a ticket for
- write the ticket information and submit it
- that's it :)

Well, I do admit that the "Login as another user" and the "New ticket"
buttons were just a little bit hard to find at first glance, but other
than that, it was pretty straightforward, at least for me.

G'luck,
Peter

-- 
Peter Pentchev  r...@ringlet.net r...@freebsd.org p...@storpool.com
PGP key:http://people.FreeBSD.org/~roam/roam.key.asc
Key fingerprint 2EE7 A7A5 17FC 124C F115  C354 651E EFB0 2527 DF13


signature.asc
Description: PGP signature


Re: Rationale for $!

2016-01-27 Thread Peter Pentchev
On Wed, Jan 27, 2016 at 10:32:46AM -0500, Felipe Gasper wrote:
[snip]
> But, what is the point of $! at all? The exception is given to the CATCH
> block as $_. If I want access to it outside CATCH, isn’t the expected
> workflow to save CATCH{$_} to a variable, the way my example does it?

Well, it makes it possible to write this concise thing:

  try my $f = open ...;
  die "Could not open $fname: $!" if $!;

G'luck,
Peter

-- 
Peter Pentchev  r...@ringlet.net r...@freebsd.org p...@storpool.com
PGP key:http://people.FreeBSD.org/~roam/roam.key.asc
Key fingerprint 2EE7 A7A5 17FC 124C F115  C354 651E EFB0 2527 DF13


signature.asc
Description: PGP signature


Re: Nice-to-have class methods

2016-01-27 Thread Peter Pentchev
On Wed, Jan 27, 2016 at 02:14:17PM +, Philip Hazelden wrote:
> On Wed, Jan 27, 2016 at 1:43 PM Peter Pentchev <r...@ringlet.net> wrote:
> 
> > On Wed, Jan 27, 2016 at 07:00:11AM -0600, Tom Browder wrote:
> > > Given so many handy methods for built-in classes, it would be nice to
> > have
> > > a couple of more for some, for instance:
> > >
> > > IO:Path.stemname
> > >   Like basename except any suffix is removed
> >
> > Hmm, this sounds like a nice idea on a first glance, but then again,
> > can you tell me exactly what situations would that be useful for?
> > Is it for compressed files (e.g. .zip vs .tar.gz) or MS-DOS/Windows
> > executables (.com, .exe, .bat), or something else?
> > When I strip filename extensions, I usually know exactly what extensions
> > I want to strip - e.g. ".conf" or ".pl" or something like that.  There
> > are very, very rare cases when any extension should be stripped - and
> > there's also a problem with that.
[snip my explanation of a problem with removing everything after the first dot]
> 
> For a "convert files to $format" thing, you'd want to replace the
> extension. You don't need to specify the previous extension(s) if it's a
> quick-and-dirty thing where you know everything passed to it will be
> acceptable; and you don't want to, if you're passing out to some other
> service which can handle various input formats. (e.g. a wrapper around
> ffmpeg or ImageMagick or something - they can handle a lot of filetypes
> with a lot of likely extensions.)

Right, so that would probably mean that you need a function that removes
the *last* extension; that might indeed make sense, although it's
trivial to implement as a regular expression substitution (but also beware
the case of a filename with no dots at all).

G'luck,
Peter

-- 
Peter Pentchev  r...@ringlet.net r...@freebsd.org p...@storpool.com
PGP key:http://people.FreeBSD.org/~roam/roam.key.asc
Key fingerprint 2EE7 A7A5 17FC 124C F115  C354 651E EFB0 2527 DF13


signature.asc
Description: PGP signature


Re: Nice-to-have class methods

2016-01-27 Thread Peter Pentchev
On Wed, Jan 27, 2016 at 07:00:11AM -0600, Tom Browder wrote:
> Given so many handy methods for built-in classes, it would be nice to have
> a couple of more for some, for instance:
> 
> IO:Path.stemname
>   Like basename except any suffix is removed

Hmm, this sounds like a nice idea on a first glance, but then again,
can you tell me exactly what situations would that be useful for?
Is it for compressed files (e.g. .zip vs .tar.gz) or MS-DOS/Windows
executables (.com, .exe, .bat), or something else?
When I strip filename extensions, I usually know exactly what extensions
I want to strip - e.g. ".conf" or ".pl" or something like that.  There
are very, very rare cases when any extension should be stripped - and
there's also a problem with that.

You see, I was kind of surprised many years ago when I first met
somebody who routinely used a dot as a word separator in filenames -
a file that I would've called "yearly-report.txt" or "YearlyReport.txt",
he would call "yearly.report.txt".  Over the years after that, I
stumbled into many other people who do that - not a majority, certainly,
but, well, many people indeed.

So a function that would remove *any* filename extensions, that is,
anything after and including the first dot, would produce really weird
results if applied to filenames created by such people.

G'luck,
Peter

-- 
Peter Pentchev  r...@ringlet.net r...@freebsd.org p...@storpool.com
PGP key:http://people.FreeBSD.org/~roam/roam.key.asc
Key fingerprint 2EE7 A7A5 17FC 124C F115  C354 651E EFB0 2527 DF13


signature.asc
Description: PGP signature