Re: Help with %?RESOURCES variable

2023-04-19 Thread Brad Gilbert
Unless things have changed since I was last active, only modules are
precompiled. `?` Twigilled variables are set at compile time.
So if it had any values, they wouldn't be useful, because they would be
created anew every time.

On Mon, Apr 17, 2023, 11:48 AM David Santiago  wrote:

>
> Hi Polgár
>
> A seg, 17-04-2023 às 18:08 +0200, Polgár Márton escreveu:
> > I think this is the classic case of ?-twigilled, "compile-time"
> > variables only being available in modules. It kind of forces you to
> > always have the pattern of: heavy-lifting in a module inside lib, and
> > the script just uses the module.
> >
>
>
>
> yes, that was the case. It works inside a module. I guess i have to
> think differently on how to organize the code.
>
> Thanks and best regards,
> David Santiago
>
>


Re: Regex surprises

2022-09-12 Thread Brad Gilbert
Raku removed all of the regex cruft that has accumulated over the years.
(Much of that cruft was added by Perl.)

I'm not going to respond to the first part of your email, as I think it is
an implementation artifact.

On Mon, Sep 12, 2022 at 3:06 PM Sean McAfee  wrote:

> Hello--
>
> I stumbled across a couple of bits of surprising regex behavior today.
>
> First, consider:
>
> S:g[ x { say 1 } ] = say 2 given "xx"
>
> I expected this to print 1, 2, 1, 2, but it prints 1, 1, 2, 2.  So it
> looks like, in a global substitution like this, Raku doesn't look for
> successive matches and then evaluate the replacements as it goes, but finds
> all of the matches *first* and then works through the substitutions.  In
> my actual problem I was mutating state in the regex code block, and then it
> didn't work because all of the mutations happened before even a single
> replacement was evaluated.  Is it really meant to work this way?
>



Now the following is intentional.

Raku treats regexes as a domain specific sub language.
One of the ways it does that is by having each sub expression act as an
independent sub expression.

Would you expect `/ (a) | (b) /` to act significantly differently to `if
($a) {$0 = ...} elsif ($b) {$0 = ...}`?
(Where `$0` could be thought of as representing the first value on the
stack, or similar.)

Next, consider:
>
> > "y" ~~ /(x)|(y)/
> 「y」
>  0 => 「y」
>
> y is in the second set of grouping parentheses, so I expected it to be in
> group 1, but it's in group 0.  So it looks like the group index starts from
> 0 in every branch of an alternation.  I do so much regex slinging I'm
> amazed it took me so long to discover this, if it's not a relatively recent
> change.  I'm accustomed to being able to determine which alternation branch
> was matched by checking which group is defined (in other languages too, not
> just Raku).  This kind of thing:
>
> S:g[(x)|(y)] = $0 ?? x-replacement !! y-replacement
>
> I guess instead I need to do this:
>
> S:g[x|y] = $/ eq 'x' ?? x-replacement !! y-replacement
>
> It seems very strange that I need to re-examine the match to know what
> matched.  The match should be able to tell me what matched.  Or is there
> perhaps some alternate way for me to tell which alternative matched?
>

Other languages, including Perl, have just added feature after feature to
regexes without thinking about the regex language as a whole.

Raku started over from scratch. Larry then took the knowledge learned over
decades of language design and applied it to regex.
Like I said, one of those things that Larry realized is that independent
sub expressions should be independent.

If you really want to know how to determine which alternation matched,
there are plenty of ways to do it.

/ $0 = (x) | $1 = ($y) /

/ $ = x | $ = y /

/
  x
  :my $*alternation = 0;
|
  y
  :my $*alternation = 1;
/

/
  x
  :my $*replacement = ...;
|
  y
  :my $*replacement = ...;
/

That last one would allow you to remove the `??` `!!` from your code.

(I haven't been doing much with Raku for months, so there are likely some
other methods I'm not thinking of.)


Re: Ping Larry Wall: excessive compile times

2022-08-29 Thread Brad Gilbert
The Raku compiler is written in Raku (to an extent) so no it can't be toned
down. I've been out of the loop for a while, but there has been work to
make the compiler use a better design which should be more optimizable.

On Mon, Aug 29, 2022, 2:01 PM ToddAndMargo via perl6-users <
perl6-us...@perl.org> wrote:

> On 8/29/22 11:50, Brad Gilbert wrote:
> > Actually Raku is faster to compile than Perl5. If you consider all of
> > the features it comes with.
> >
> > For example, in Raku everything is an object with meta features. If you
> > add Moose or similar to Perl5 then the compile times will often take
> > longer than the equivalent Raku times.
> >
> > That's not the only such feature that you have to add to Perl5 to get
> > feature parity.
> >
> > Then you have to also realize that the Perl5 compiler has had since 1994
> > to get faster vs. 2015 for Raku.
>
> I do adore Perl 6 (Raku).  I almost completely
> dropped Perl 5 when I got a load of P6's
> subroutines.  I program in Top Down and P5's
> subs are a nightmare.   I have one P5 program
> I support that I have not ported yet.
>
> As a beginner, my programs are rather simple.
> If P6 being feature rich is part of the
> problem, is there a way to tell P6's compiler
> to back off a bit?
>
>
>
>
>


Re: Ping Larry Wall: excessive compile times

2022-08-29 Thread Brad Gilbert
Actually Raku is faster to compile than Perl5. If you consider all of the
features it comes with.

For example, in Raku everything is an object with meta features. If you add
Moose or similar to Perl5 then the compile times will often take longer
than the equivalent Raku times.

That's not the only such feature that you have to add to Perl5 to get
feature parity.

Then you have to also realize that the Perl5 compiler has had since 1994 to
get faster vs. 2015 for Raku.

On Mon, Aug 29, 2022, 10:48 AM ToddAndMargo via perl6-users <
perl6-us...@perl.org> wrote:

> Dear Larry Wall,
>
> Sorry for writing you directly, but I know you
> sometimes answer questions on this mailing list.
> And those answers are uniquely easy for a beginner
> to understand.
>
> The compile times of Perl5 and Perl6 are dramatically
> different.  Perl 5 is literally 100 times or more
> faster than Perl6.  It is professionally embarrassing
> to turn over a program to customer that takes up to
> 20 seconds to start.
>
> I have reported the issue over on:
>
>https://github.com/perl-foundation-outreach/gsoc-2021-ideas/issues/4
>
>  From the bug report, I compared a program I ported from
> Perl 5 to Perl 6.
>
>$ raku -c --stagestats GetUpdates.pl6
>Stage start : 0.000
>Stage parse : 17.851
>Stage syntaxcheck: Syntax OK
>
>$ time perl -c GetUpdates.pl
>GetUpdates.pl syntax OK
>real 0m0.305s
>user 0m0.243s
>sys 0m0.029s
>
>
> 17.851 versus 0.75 seconds.   Or 238 times slower.
>
> Since you wrote both Perl 5 and Perl 6, is there some
> reason beyond my limited understanding of how these
> things work as to why your Perl 5 is so much faster to
> compile that your Perl 6?
>
> And is wishing for the situation to be corrected
> not a reasonable request?
>
> Also, am I stuck with the .precomp work around, which
> is not helpful when you have to run a lot of
> iterations to debug things such are regex's?
> 17 seconds to see if I goofed a regex is killing me!
>
> Many thanks,
> -T
>
>


Re: author specification

2022-05-11 Thread Brad Gilbert
After thinking on it, :auth<> is sort of an authentication chain. Just a
really short one.

To authenticate a module with :auth you have to first
authenticate zef.

On Wed, May 11, 2022 at 4:02 PM Darren Duncan 
wrote:

> This discussion thread has excellent timing, because I was otherwise about
> to
> come here and start a thread on the topic.
>
> I have been interested in the weeds of Raku's fully qualified compunit
> naming
> convention for a long long time, since I first saw it in Larry's
> Apocalypse 12
> https://raku.org/archive/doc/design/apo/A12.html section on "Versioning".
>
> My interest is not only for the Raku ecosystem itself but also its
> generalization into programming languages or code repositories in the
> abstract.
>
> For a key example, Raku's fully qualified compunit naming convention has
> an
> analogy in the Java world for versioning of JARs in Maven Central et al,
> where
> Raku's base-name plus "auth" plus "ver" correspond to Maven's "groupId"
> plus
> "artifactId" plus version number.  Or somewhat like "groupId", the typical
> Java
> package naming convention that starts with a reversed internet domain name
> of
> the creator.
>
> Many years ago (before I knew about Maven etc) I adopted the Raku fully
> qualified compunit naming convention for my own Raku-inspired projects
> including
> Muldis Object Notation (MUON) and Muldis Data Language (MDL).  Both my
> format/language specifications and artifacts/compunits are versioned with
> the
> base name plus authority plus version number triplicate.
>
> The Raku docs seem to have evolved since then but the original mention of
> "auth"
> in Apocalypse 12 highlighted internet domain names such as "
> http://www.some.com;
> as an option, I quote (slightly paraphrased):
>
>  The syntax of a versioned class declaration looks like this:
>
>  class Dog-1.2.1-cpan:JRANDOM;
>  class Dog-1.2.1-http://www.some.com
>  class Dog-1.2.1-mailto:jran...@some.com;
>
>  class Dog-1.2.1-JRANDOM;
>  class Dog-1.2.1-http://www.some.com/~jrandom;
>  class dog-1.2.1-jran...@some.com;
>
> For perhaps one of my most important contributions to this thread...
>
> The way I see it, the best interpretation of "auth" is the more abstract
> "authority" which is some kind of unique identifier for a real person or
> organization that is releasing the artifact.  This should be abstracted
> away as
> much as possible from any actual repositories where the artifact is
> available.
>
> If the general form of "auth" is basically "foo:bar" where "foo" defines a
> delegating authority that controls a namespace and "bar" is the artifact
> releasor's reserved name in that namespace, then it means "auth" is more a
> lookup in an identity broker which is orthogonal to where the artifacts
> are
> distributed.
>
> In the modern day, I see that the internet domain name system is the
> closest
> thing we have to a universal long term identity broker.  A creator
> reserves
> their name by registering and controlling the internet domain name.
>
> While possibly not strictly required, I believe this is that the Maven
> "groupId"
> and more generally the long-term practice of Java package names has done.
>
> For my part, long ago, inspired by Apocalypse 12, I started using
> "http://muldis.com; as the authority/auth for my specs and compunits
> etc.  See
>
> https://github.com/muldis/Muldis_Object_Notation/blob/master/spec/Muldis_Object_Notation.md
> for a specific example, both the VERSION at the top, as well as the
> VERSIONING
> section at the bottom.
>
> The way I see it, though an author or distributor may use different
> repositories
> such as CPAN or Github to distribute things, all distributions by the same
> person/org should use the same "auth", and different "auth" are for
> different
> persons/orgs to distinguish themselves.
>
> When you have a Raku compunit Foo that is declaring its own fully
> qualified
> version, or is declaring its dependencies' fully qualified versions, they
> shouldn't have to be more specific than saying, I am authority X, and I
> want
> compunit Bar by authority Y.  This is like pointing to a fingerprint
> identifier,
> and that association should not break just because Bar is being
> distributed in
> different places, and it shouldn't matter where the end user gets Bar from
> as
> long as it is the same Bar.
>
> So if an author decides that their id is "CPAN:jrandom" then they should
> keep
> using "CPAN:jrandom" no matter where the artifacts are actually
> distributed.
> This "CPAN:jrandom" isn't an instruction to get the module from CPAN, it
> is just
> an instruction to get a module from anywhere the user is comfortable with
> per
> their own policies that identifies itself as "CPAN:jrandom".
>
> Independently from this, various repositories can have constraints that
> only
> someone who has proven they own "CPAN:jrandom" on CPAN etc can upload
> things
> with that auth, or at least while claiming that they are the 

Re: author specification

2022-05-03 Thread Brad Gilbert
There could be a way for one of them to only act as a middle man. Basically
have fez defer to CPAN and just host a copy of it.

On Tue, May 3, 2022, 10:59 AM Marcel Timmerman  wrote:

> Hi Brad,
>
> Auth is for more than just the author. It is for author, authority, and
> authentication.
>
> There is no password or other cryptographic way, so authentication is not
> possible. Obviously, I might miss some insight here.
>
> In the documentation I read; ":auth generally takes the form hosting:ID,
> as in github:github-user or gitlab:gitlab-user". For me, hosting is e.g.
> on GitHub or Gitlab to store the software, and ecosystems are for spreading
> the word, i.e. telling that there is a software available somewhere, and
> this somewhere is not important. That is the work for zef to find out.
>
> And the word 'generally' means that it is just an example, it is in the
> end just a string.
> Furthermore, there is no mention in the docs of any use other than naming
> it in a useful way. No remarks of needing it to login into some ecosystem
> and no word about that separator, being a column, or split it up in more
> than two fields using an other character.
>
> Searching through some distributions I find 'zef:lizmat', 'github:MARTIMM',
> 'tonyo', 'cpan:WARRINGD', 'github:ccworld1000, ccworld1...@gmail.com,
> 2291108...@qq.com', showing that there is absolutely no clear way to use
> that field. For me, it means again that the auth field must be completely
> free and the same, independent of the ecosystem in use.
>
> CPAN can't authenticate github or fez modules, and vice versa. There is a
> reason the field is only the first four letters.
>
> The word 'github' is longer.
>
> That they are seen as different modules is an intended feature, not a bug.
>
> I didn't want to say that it was a bug, sorry for the confusion.
>
> I would like to know how you would want the system to handle a module from
> me. cpan:BGILLS github:b2gills and I intend to get b2gills on fez as well.
> (CPAN doesn't allow numbers, otherwise I would have it there to.)
>
> Do you want to write several meta files with different auth fields
> depending on the ecosystem you want to send it to? The only thing you can
> do without much work is sending a project e.g. to fez and another to cpan
> but I don't see the use of spreading your projects over several ecosystems.
>
> Also for a class you wrote, JSON::Class, what should I write (I took it to
> the extreme of course, 'use JSON::Class' would do)
>
> use JSON::Class:auth;
> use JSON::Class:auth;
> use JSON::Class:auth;
>
> All three are getting the same software, or not, when it is someone els-es
> auth.
>
> What if someone else took a user name on github that matched one on CPAN
> or fez?
>
> That is the point I want to make. Keeping the auth field the same
> everywhere, independent of ecosystem, will show that the software is the
> same everywhere. If that someone has the same account name as someone else
> on cpan or fez it will show a difference in the auth field.
>
> So, I think there is a lot to ponder over
> Regards,
> Marcel
>
>
> On Mon, May 2, 2022, 3:23 PM Marcel Timmerman  wrote:
>
>> Hi,
>>
>> I was wondering about the 'auth' specification in the meta file or on the
>> class/module/package. I was used to specify it as 'github:MARTIMM' because
>> I store the stuff on GitHub for all the goodies it offers. Now I see that
>> fez wants to start with 'fez:' and when I look at the raku.land site for a
>> module of mine I see a remark *'*The uploading author of cpan:MARTIMM
>> does not match the META author of github:MARTIMM.' because I upload it to
>> CPAN nowadays and have never specified somewhere that the auth has become
>> 'cpan:MARTIMM'.
>>
>> I feel that this is not useful (even correct) to pin someone to use an
>> auth specification with a defined prefix for some ecosystem one is using.
>> So changing to another ecosystem forces that person to change the auth
>> everywhere in its code and meta files to get rid of any errors or warnings.
>> Besides that, the change of the author on the same code poses the question
>> later on, if that code is forked and changed by someone else or that it is
>> still the same developer working on it?
>>
>> Regards,
>> Marcel
>>
>>
>


Re: author specification

2022-05-02 Thread Brad Gilbert
Auth is for more than just the author. It is for author, authority, and
authentication. CPAN can't authenticate github or fez modules, and vice
versa. There is a reason the field is only the first four letters.

That they are seen as different modules is an intended feature, not a bug.

I would like to know how you would want the system to handle a module from
me. cpan:BGILLS github:b2gills and I intend to get b2gills on fez as well.
(CPAN doesn't allow numbers, otherwise I would have it there to.)

What if someone else took a user name on github that matched one on CPAN or
fez?

On Mon, May 2, 2022, 3:23 PM Marcel Timmerman  wrote:

> Hi,
>
> I was wondering about the 'auth' specification in the meta file or on the
> class/module/package. I was used to specify it as 'github:MARTIMM' because
> I store the stuff on GitHub for all the goodies it offers. Now I see that
> fez wants to start with 'fez:' and when I look at the raku.land site for a
> module of mine I see a remark *'*The uploading author of cpan:MARTIMM
> does not match the META author of github:MARTIMM.' because I upload it to
> CPAN nowadays and have never specified somewhere that the auth has become
> 'cpan:MARTIMM'.
>
> I feel that this is not useful (even correct) to pin someone to use an
> auth specification with a defined prefix for some ecosystem one is using.
> So changing to another ecosystem forces that person to change the auth
> everywhere in its code and meta files to get rid of any errors or warnings.
> Besides that, the change of the author on the same code poses the question
> later on, if that code is forked and changed by someone else or that it is
> still the same developer working on it?
>
> Regards,
> Marcel
>
>


Re: Grammar Help

2021-12-26 Thread Brad Gilbert
I'm on mobile, but without checking, I think the problem is here

rule  pairlist   {  * % \; }

Specifically it's the missing %

rule  pairlist   {  * %% \; }

JSON doesn't allow trailing commas or semicolons, so JSON::Tiny uses just %.
Your data does have trailing semicolons, so you want to use %% instead.

Also why did you change , without actually changing anything?


On Sun, Dec 26, 2021, 3:22 AM Simon Proctor  wrote:

> Still waking up but I think the issue is your pairlist has a semi colon
> divider but this should be after each pair.
>
> So the trailing semi colon after b is causing it to fail.
>
> On Sun, 26 Dec 2021, 06:01 Paul Procacci,  wrote:
>
>> Hey all,
>>
>> Twas the night of Christmas, when all through the house, not a creature
>> was stirring except Paul w/ his mouse.
>>
>> Hope everyone had a Merry Christmas and takes likings to corny opening
>> statements.  ;)
>>
>> I was writing a little something tonight using Grammars and ran into
>> something that I can't seem to wrap my head around.  I'm hoping someone
>> could explain in detail.
>>
>> Given the following data:
>>  data -
>> objectKey:
>> {
>> a = "bi";
>> b = "hi";
>> }
>>  end data -
>>
>>
>>  and the following logic partially taken from JSON::Tiny:
>>
>>  code 
>> grammar myTest {
>> token TOP{ \s*  \s* }
>> rule  object {  '{'  '}' }
>> # rule  object {  '{' ~ '}'  }
>> rule  objectKey  {  ':' }
>> rule  pairlist   {  * % \; }
>> rule  pair   {  '='  }
>> token cstr   { + }
>> token value  { '"' ~ '"' * }
>> }
>>
>> class myTestActions {
>> method TOP($/) {
>> make $.made.hash.item;
>> }
>>
>> method object($/) {
>> say 'hello';
>> }
>>
>> method objectKey($/) {
>> make $.made;
>> }l
>> method pairlist($/) {
>> make $>>.made.flat;
>> }
>>
>> method pair($/) {
>> make $.made => $.made;
>> }
>>
>> method cstr($/)  { make ~$/ }
>> method value($/) { make ~$/ }
>> }
>>  code 
>>
>>
>> ... it'd be my hopes that this would match.  However, It's not matching
>> on 'object' and I can't seem to figure out why.
>>
>> Adding Grammar::Tracer yields the following:
>>
>> TOP
>> |  object
>> |  |  objectKey
>> |  |  |  cstr
>> |  |  |  * MATCH "objectKey"
>> |  |  * MATCH "objectKey:\n"
>> |  |  pairlist
>> |  |  |  pair
>> |  |  |  |  cstr
>> |  |  |  |  * MATCH "a"
>> |  |  |  |  value
>> |  |  |  |  * MATCH "\"bi\""
>> |  |  |  * MATCH "a = \"bi\""
>> |  |  |  pair
>> |  |  |  |  cstr
>> |  |  |  |  * MATCH "b"
>> |  |  |  |  value
>> |  |  |  |  * MATCH "\"hi\""
>> |  |  |  * MATCH "b = \"hi\""
>> |  |  |  pair
>> |  |  |  |  cstr
>> |  |  |  |  * FAIL
>> |  |  |  * FAIL
>> |  |  * MATCH "a = \"bi\";\n\tb = \"hi\""
>> |  * FAIL
>> * FAIL
>>
>> What exactly am I doing wrong?  Does '{' ~ '}' not work as I expect here?
>> Appreciate any insight.
>>
>> Thanks,
>> Paul
>> --
>> __
>>
>> :(){ :|:& };:
>>
>


Re: Order of multi sub definitions can resolve dispatch ambiguity

2021-09-25 Thread Brad Gilbert
On Sat, Sep 25, 2021 at 2:30 PM Joseph Brenner  wrote:

> > Since subsets are just code it would be difficult to impossible
> > to determine all of the ones that can match without actually
> > running them all. This would slow down every call that uses
> > multiple subsets.
>
> I can see how there would be a big performance hit, but I haven't
> yet turned up any reference to this behavior in the docs.  I
> don't see anything to clue you in that subsets are an exception,
> and I don't think there's anything about
> order-of-definition-of-sub being a tie-breaker under any
> circumstances.
>

The docs are not the definitive source of truth.
They are at best an approximation.

> By most narrow candidate, it means by type.
>
> If you'd said that to me, I'd still have expected it to work the
> way that I did, because the way I look at it I'm creating new
> types via subset.
>

By type I mean something that can be instantiated or subclassed.
Subsets cannot do either of those two things.
You can create a subset of a subset, but that is not the same thing.


> > All subsets "of" the same type are sorted by the order they are
> > written.
>
> Even if I'd figured that two subsets of Str were going to treated as Str,
> I'd have expected an "Ambiguous call" error.
>
> If the two subsets are defined in different modules I suspect you
> could get some strange behavior that would be hard to debug.
> It's not always immediately obvious in what order two things were
> defined.
>

Doing what you want would make using subsets with multis much less useful.

multi factorial ( 0 --> 1 ){}
multi factorial ( 1 --> 1 ){}
multi factorial ( UInt \n ){ factorial(n - 1) * n }

say factorial( 1 );
# ERROR: both UInt and 1 subsets match.

You could modify the general case, but that is tedious and error prone.

multi factorial ( Int \n where {$_ >= 0 && $_ != 0 && $_ != 1} ){
factorial(n - 1) * n }

(The reason I didn't just do $_ >= 2 is that if another multi is added it
should be dealt with in the same way as 0 and 1)


> On 9/24/21, Brad Gilbert  wrote:
> > This is intended behavior.
> >
> > Since subsets are just code it would be difficult to impossible to
> > determine all of the ones that can match without actually running them
> all.
> > This would slow down every call that uses multiple subsets.
> >
> > By most narrow candidate, it means by type. All subsets "of" the same
> type
> > are sorted by the order they are written.
> >
> > The ambiguity it talks about is when two candidates have the same level
> of
> > type for a given input. For example Str and Int for an IntStr.
> >
> >
> > On Fri, Sep 24, 2021, 1:32 AM Joseph Brenner  wrote:
> >
> >> This code uses multi dispatch with constraints that are ambiguous
> >> in a few cases, because there's some overlap in the lists of
> >> monsters and heroes: 'mothera' and 'godzilla'.
> >>
> >> my @monsters = < godzilla  mothera ghidora  gammera  golem
> >> wormface >;
> >> my @heroes   = < beowulf   bluebeetle  bernie   mothera  godzilla
> >> maynard_g_krebs >;
> >>
> >> subset Monster of Str where { $_ eq any( @monsters ) };
> >> subset Heroof Str where { $_ eq any( @heroes ) };
> >>
> >> ## Monster is favored over Hero because of the order of definition
> >> of these multi subs
> >> multi sub speak (Monster $m) {
> >> say "The monster, $m roars!";
> >> }
> >> multi sub speak (Hero $h) {
> >> say "The hero, $h shouts!";
> >> }
> >>
> >> speak('ghidora');  # The monster, ghidora roars!
> >> speak('beowulf');  # The hero, beowulf shouts!
> >> speak('mothera');  # The monster, mothera roars!
> >>
> >> I would've expected that in the case of 'mothera', this would
> >> error out unless an "is default" was added to one of the multi
> >> subs.  Instead the ambiguity is resolved by the order of
> >> definition: if you reverse the order of the "multi sub speak"s,
> >> then mothera is treated as Hero not Monster.
> >>
> >> This is not the behavior described in the documentation:
> >>
> >>  https://docs.raku.org/language/glossary#index-entry-Multi-Dispatch
> >>  Multi-dispatch§
> >>
> >>  The process of picking a candidate for calling of a set of
> >>  methods or subs that come by the same name but with different
> >>  arguments. The most narrow candidate wins. In case of an
> >>  ambiguity, a routine with is default trait will be chosen if
> >>  one exists, otherwise an exception is thrown.
> >>
> >
>


Re: Order of multi sub definitions can resolve dispatch ambiguity

2021-09-24 Thread Brad Gilbert
This is intended behavior.

Since subsets are just code it would be difficult to impossible to
determine all of the ones that can match without actually running them all.
This would slow down every call that uses multiple subsets.

By most narrow candidate, it means by type. All subsets "of" the same type
are sorted by the order they are written.

The ambiguity it talks about is when two candidates have the same level of
type for a given input. For example Str and Int for an IntStr.


On Fri, Sep 24, 2021, 1:32 AM Joseph Brenner  wrote:

> This code uses multi dispatch with constraints that are ambiguous
> in a few cases, because there's some overlap in the lists of
> monsters and heroes: 'mothera' and 'godzilla'.
>
> my @monsters = < godzilla  mothera ghidora  gammera  golem
> wormface >;
> my @heroes   = < beowulf   bluebeetle  bernie   mothera  godzilla
> maynard_g_krebs >;
>
> subset Monster of Str where { $_ eq any( @monsters ) };
> subset Heroof Str where { $_ eq any( @heroes ) };
>
> ## Monster is favored over Hero because of the order of definition
> of these multi subs
> multi sub speak (Monster $m) {
> say "The monster, $m roars!";
> }
> multi sub speak (Hero $h) {
> say "The hero, $h shouts!";
> }
>
> speak('ghidora');  # The monster, ghidora roars!
> speak('beowulf');  # The hero, beowulf shouts!
> speak('mothera');  # The monster, mothera roars!
>
> I would've expected that in the case of 'mothera', this would
> error out unless an "is default" was added to one of the multi
> subs.  Instead the ambiguity is resolved by the order of
> definition: if you reverse the order of the "multi sub speak"s,
> then mothera is treated as Hero not Monster.
>
> This is not the behavior described in the documentation:
>
>  https://docs.raku.org/language/glossary#index-entry-Multi-Dispatch
>  Multi-dispatch§
>
>  The process of picking a candidate for calling of a set of
>  methods or subs that come by the same name but with different
>  arguments. The most narrow candidate wins. In case of an
>  ambiguity, a routine with is default trait will be chosen if
>  one exists, otherwise an exception is thrown.
>


Re: intermixed types and resulting types

2021-08-30 Thread Brad Gilbert
The multi infix:<+>( \a, \b ) candidate is the one that accepts non Numeric
values.

What it does is try to convert the two values into Numeric ones, and then
redispatch using those values.

If either one produces an error instead of a Numeric, that error is passed
along.

On Mon, Aug 30, 2021 at 9:30 AM Ralph Mellor 
wrote:

> On Sun, Aug 22, 2021 at 4:59 PM yary  wrote:
> >
> > "How would you know what types are compatible for a particular
> operation?"
> >
> > inspecting a routine's arguments.
>
> Bingo.
>
> > The first couple candidates raise questions for me
> >
> > multi($x = 0) - how is there a single-arg candidate for an infix
> operator?
>
> It's a really nice design for expressing what to do in situations like
> this:
>
> ```
> say infix:<+>(42);  # 42
> my @numbers = 99;
> say [+] @numbers;   # 99
> ```
> Similarly there are zero parameter candidates to cover zero arg cases:
> ```
> say infix:<+>();  # 0
> my @numbers;
> say [+] @numbers; # 0
> ```
>
> See https://en.wikipedia.org/wiki/Identity_function for the related
> concept
> used in mathematics. Raku uses these zero/one parameter signatures to
> provide a clean general solution to the general problem of what to do if an
> infix operator is passed less than two arguments.
>
> > multi(\a, \b) - does this accept everything, is it a "cleanup"
> > candidate for error reporting?
>
> It accepts any call with two arguments (as is the case for most
> calls) if none of the other two parameter signatures match.
>
> My guess would be that it's for error reporting. (Ideally one would
> be able to call  `.WHY` on that candidate to see why it was written,
> in this case to see if it was for error reporting.)
>
> > I'm curious about how some candidates bind to bare names
> > \a, \b while others use sigilled variables, I'm assuming that's
> > due to the original programmer's style preference.
>
> A sigil implies some (rudimentary) type information. For example,
> an `@` implies `Positional`, which is pretty generic but not entirely
> so. Then there is of course the ultimate generic sigil, namely `$`.
>
> But while it is indeed *very* generic, it still implies some rudimentary
> type information that isn't 100% generic. For one thing, it hints that
> the value it's bound to probably *isn't* `Positional` or `Associative`.
> (Otherwise, why didn't they use `@` or `%`?) For another, it allows
> traits to be applied that add other dimensions of type information.
>
> Consider this code:
> ```
> multi foo (\a)  { say a   }
> multi foo ($ is rw) { say '$' }
> multi foo (@)   { say '@' }
> multi foo (%)   { say '%' }
>
> foo @;  # @
> foo %;  # %
> foo $;  # $
> foo 42; # 42
> ```
>
> Slashing the sigil out removes any ambiguity (or, if you prefer,
> *maximizes* the ambiguity) of what a variable is bound to. It could
> be bound to *anything* -- `Positional`, `Associative`, or otherwise.
> So slashing the sigil -- `\foo` -- jumps out as being somehow even
> more generic than using `$`.
>
> --
> raiph
>


Re: [naive] hash assingment

2021-07-14 Thread Brad Gilbert
Honestly I would advise against using ==> at the moment.

For one thing it doesn't even work like it is intended.
Each side of it is supposed to act like a separate process.

There are also issues with the syntax that are LTA.
The fact that you have to tell it the left side is actually a list is one
such issue.

It isn't even all that clearer than just using a method call

> %a .map({.sqrt});

---

Using 「.Slip」 or 「|」 prefix works, but is the wrong thing.
You need to tell it that it is a list, so use 「.List」 or 「@(…)」

> @(%a) ==> map({.sqrt})
> %a.List ==> map({.sqrt})

Since a Slip is a type of List, using it works, but for the wrong reasons.


On Wed, Jul 14, 2021 at 2:58 PM Aureliano Guedes 
wrote:

> thank
>
> It is now more clear.
> And I like this notation |%a ==> map({.sqrt});
> less is more sometimes
>
>
>
> On Wed, Jul 14, 2021 at 4:41 PM Daniel Sockwell 
> wrote:
>
>> To expand slightly on what Clifton said, the reason that
>>
>> > %a = %a.map: { .sqrt };
>> > # (1 1.4142135623730951 1.7320508075688772 2 2.23606797749979)
>>
>> does what you mean but
>>
>> > %a{'column1'} ==> map( { .sqrt } )
>> > # (2.23606797749979)
>>
>> does not is that the method .map maps over *each item* in the Array,
>> whereas
>> ==> map maps over the Array as *one collection*.  When taking the square
>> root,
>> an Array needs to be treated as an number, which for Raku means treating
>> it as
>> a count of how many elements it has (i.e., its length).
>>
>> So `%a{'column1'} ==> map({.sqrt})` is the same as
>> `%a{'column1'}.elems.map({.sqrt})`
>>
>> If want to map over each item in the Array when using the ==> operator,
>> you need to
>> slip the items out of the Array before feeding them on.  You can do that
>> with either
>> of the following (equivalent) lines:
>>
>> > %a{'column1'}.Slip ==> map({.sqrt});
>> > |%a{'column1>'}==> map({.sqrt});
>>
>> (Also, you may already know this, but when the keys of your hash are
>> strings, you
>> can write %a instead of %a{'column1'}  )
>>
>> Hope that helps!
>>
>> –codesections
>>
>
>
> --
> Aureliano Guedes
> skype: aureliano.guedes
> contato:  (11) 94292-6110
> whatsapp +5511942926110
>


Re: gather take eager syntax

2021-04-20 Thread Brad Gilbert
A Hash either takes some number of pairs

my %h = a => 1, b => 2;

or an even number of elements, which become key value pairs

my %h = 'a', 1, 'b', 2;

`eager` returns an eager Sequence/List etc

   (eager a => 1).raku # (:a(1),)

A Sequence/List is itself a thing. Which means that it can be a key.

So when you pass that to a Hash constructor, it accepts that as the key,
but it still needs the value to go with it.

my %h{Any} = (eager a => 1), 2;
# {(a => 1) => 2}

That is the only key in that Hash is itself a Pair object.

my $key = a => 1;
my %h = ($key,), 2;
say %h{$key}; # 2

`eager` only really makes sense on something that is already an Iterable.

my %h = eager gather { take 'a'; take 1 }

So since `eager` is defined as a Sequence/List operation, it turns its
arguments into that if they aren't already.

my \value = eager "foo";
say value.raku; # ("foo",)

What you didn't notice is that your third example also went wrong. It has a
key which is a Pair, and a value which is also a Pair.

my %h;
%h{ foo => 1 } = (bar => 2);
# {foo 1 => bar => 2}

my %h = ( foo => 1, ),  bar => 2;
# {foo 1 => bar => 2}

Note that since Hashes have Str keys by default, that the key actually gets
stringified instead of staying a Pair object.

%h{ "foo\t1" } = bar => 2;

say ( foo => 1 ).Str.raku; # "foo\t1"

If we use an object key, it doesn't get stringified. Which better shows
what happened.

my %h{Any} = ( foo => 1, ),  bar => 2;
# :{(foo => 1,) => bar => 2}


I honestly don't understand why you would `eager` the argument of a `take`.
It's too late to mark the `gather` as eager.

On Tue, Apr 20, 2021 at 12:39 AM Norman Gaywood  wrote:

> Hi, I can't figure out why the last line here is failing.
> Version 2020.07
>
> $ raku
> To exit type 'exit' or '^D'
> > my %h = gather { take "foo"=>1; take "bar"=>2;}
> {bar => 2, foo => 1}
> > my %h = gather { take "foo"=>1}
> {foo => 1}
> > my %h = gather { take eager "foo"=>1; take "bar"=>2;}
> {foo 1 => bar => 2}
> > my %h = gather { take eager "foo"=>1}
> Odd number of elements found where hash initializer expected:
> Only saw: $(:foo(1),)
>   in block  at  line 1
>
> --
> Norman Gaywood, Computer Systems Officer
> School of Science and Technology
> University of New England
> Armidale NSW 2351, Australia
>
> ngayw...@une.edu.au  http://turing.une.edu.au/~ngaywood
> Phone: +61 (0)2 6773 2412  Mobile: +61 (0)4 7862 0062
>
> Please avoid sending me Word or Power Point attachments.
> See http://www.gnu.org/philosophy/no-word-attachments.html
>


Re: Objects, TWEAK and return

2021-03-13 Thread Brad Gilbert
Ralph, the last value in all functions are not sunk by default, so of
course the last one in `TWEAK` is not sunk by default.
This is intended behaviour.

It is up to the code that calls a function to sink the result if that is
the desired behaviour.

sub foo {
'a b c'.words».uc.map: *.say;
}

my $ = foo(); # nothing is printed

sink foo(); # «A␤B␤C␤» is printed

The bug is that the calling code is not sinking the result.


On Sat, Mar 13, 2021 at 8:05 PM Ralph Mellor 
wrote:

> Here's a golf:
>
> class { submethod TWEAK  { Any.map: {say 99} } }.new; #
> class { submethod TWEAK  { Any.map: {say 99}; 42 } }.new; # 99
> class { submethod TWEAK (--> 42) { Any.map: {say 99} } }.new; # 99
>
> The last line in a `BUILD` or `TWEAK` submethod is not eagerly evaluated
> by default.
>
> That sounds like a bug to me. But if not, and in the meantime,
> because your `$!filelist.lines...` line is the last one in your `TWEAK`
> submethod, the `@!show` array is being left empty, so the value to
> the right of `%` evaluates to zero, hence the error message you're seeing.
>
> On Sat, Mar 13, 2021 at 8:30 PM  wrote:
> >
> > Hi,
> >
> > When working with this week challenge for the PerlWeeklyChallenge, I
> noticed this behaviour with TWEAK:
> >
> > This does not work:
> >   submethod TWEAK {
> > $!filelist.lines».split(',').map( -> ($a, $b) { @!show.push: ( $a,
> $b )  });
> >   }
> >
> > This works:
> >   submethod TWEAK {
> > $!filelist.lines».split(',').map( -> ($a, $b) { @!show.push: ( $a,
> $b )  });
> > return;
> >   }
> >
> > It also works with other commands instead of 'return' (like assigning a
> value to a variable). From the examples in the documentation, I am not
> certain this is the expected behaviour.
> >
> > Thanks for this extraordinary language,
> >
> > Joan
> >
> >
> > P.S: This is the context where the command appears.  Apologies for the
> messy-Raku,
> > --
> > use Test;
> >
> > my $data = '1709363,"Les Miserables Episode 1: The Bishop (broadcast
> date: 1937-07-23)"
> > 1723781,"Les Miserables Episode 2: Javert (broadcast date: 1937-07-30)"
> > 1723781,"Les Miserables Episode 3: The Trial (broadcast date:
> 1937-08-06)"
> > 1678356,"Les Miserables Episode 4: Cosette (broadcast date: 1937-08-13)"
> > 1646043,"Les Miserables Episode 5: The Grave (broadcast date:
> 1937-08-20)"
> > 1714640,"Les Miserables Episode 6: The Barricade (broadcast date:
> 1937-08-27)"
> > 1714640,"Les Miserables Episode 7: Conclusion (broadcast date:
> 1937-09-03)"';
> >
> > class Movies {
> >
> >   has $.starttime;
> >   has $.currenttime;
> >   has $.filelist;
> >   has @!show; # ( [ time, show ] )
> >
> >   submethod TWEAK {
> > # miliseconds -> seconds
> > $!filelist.lines».split(',').map( -> ($a, $b) { @!show.push: ( $a,
> $b )  });
> > return;
> >   }
> >
> >   method what-show() {
> > my $position =  ( $!currenttime - $!starttime ) %
> @!show[*;0].sum/1000;
> > my ($time, $show);
> > for @!show[*;0] -> $show-time {
> >   $time += $show-time;
> >   return @!show[$show++;1] if $time > $position;
> > }
> >   }
> > }
> >
> > my $mv = Movies.new(
> >   starttime   => '1606134123',
> >   currenttime => '1614591276',
> >   filelist=> $data
> > );
> >
> > is $mv.what-show, '"Les Miserables Episode 1: The Bishop (broadcast
> date: 1937-07-23)"';
>


Re: Objects, TWEAK and return

2021-03-13 Thread Brad Gilbert
I think that this is caused because it is returning a 「Sequence」 that is
not getting sunk.
This is because the last value from a function is never sunk in that
function.

You could also use 「eager」 「sink」 or follow it with 「Nil」 or some other
value (instead of 「return」)

eager $!filelist.lines».split(',').map( -> ($a, $b) { @!show.push: (
$a, $b )  });
sink $!filelist.lines».split(',').map( -> ($a, $b) { @!show.push: ( $a,
$b )  });
$!filelist.lines».split(',').map( -> ($a, $b) { @!show.push: ( $a, $b )
 });  Nil
$!filelist.lines».split(',').map( -> ($a, $b) { @!show.push: ( $a, $b )
 });  'some other value'

You can also make 「TWEAK」 return a 「Nil」 in the signature (or any
constant/literal).

submethod TWEAK (-->Nil) { … }

Since the last value in the function is never returned it is also sunk.

---

It might be a good idea if the code that calls 「TWEAK」 (and maybe 「BUILD」)
sinks any result that they get.
Or maybe it should only sink 「Sequence」 values.

There are good reasons for allowing a 「submethod」 to return a value that
doesn't get sunk, so that should not change.

At any rate I don't think there is a bug in how 「submethod TWEAK」 is
compiled and run.
That part is working as intended.

On Sat, Mar 13, 2021 at 2:30 PM  wrote:

> Hi,
>
> When working with this week challenge for the PerlWeeklyChallenge
> , I noticed this behaviour with TWEAK:
>
> *This does not work:*
>   submethod TWEAK {
> $!filelist.lines».split(',').map( -> ($a, $b) { @!show.push: ( $a, $b
> )  });
>   }
>
> *This works:*
>   submethod TWEAK {
> $!filelist.lines».split(',').map( -> ($a, $b) { @!show.push: ( $a, $b
> )  });
> return;
>   }
>
> It also works with other commands instead of 'return' (like assigning a
> value to a variable). From the examples in the documentation, I am not
> certain this is the expected behaviour.
>
> Thanks for this extraordinary language,
>
> Joan
>
>
> P.S: This is the context where the command appears.  Apologies for the
> messy-Raku,
> --
> use Test;
>
> my $data = '1709363,"Les Miserables Episode 1: The Bishop (broadcast date:
> 1937-07-23)"
> 1723781,"Les Miserables Episode 2: Javert (broadcast date: 1937-07-30)"
> 1723781,"Les Miserables Episode 3: The Trial (broadcast date: 1937-08-06)"
> 1678356,"Les Miserables Episode 4: Cosette (broadcast date: 1937-08-13)"
> 1646043,"Les Miserables Episode 5: The Grave (broadcast date: 1937-08-20)"
> 1714640,"Les Miserables Episode 6: The Barricade (broadcast date:
> 1937-08-27)"
> 1714640,"Les Miserables Episode 7: Conclusion (broadcast date:
> 1937-09-03)"';
>
> class Movies {
>
>   has $.starttime;
>   has $.currenttime;
>   has $.filelist;
>   has @!show; # ( [ time, show ] )
>
>   submethod TWEAK {
> # miliseconds -> seconds
> $!filelist.lines».split(',').map( -> ($a, $b) { @!show.push: ( $a, $b
> )  });
> return;
>   }
>
>   method what-show() {
> my $position =  ( $!currenttime - $!starttime ) % @!show[*;0].sum/1000;
> my ($time, $show);
> for @!show[*;0] -> $show-time {
>   $time += $show-time;
>   return @!show[$show++;1] if $time > $position;
> }
>   }
> }
>
> my $mv = Movies.new(
>   starttime   => '1606134123',
>   currenttime => '1614591276',
>   filelist=> $data
> );
>
> is $mv.what-show, '"Les Miserables Episode 1: The Bishop (broadcast date:
> 1937-07-23)"';
>


Re: Working with a regex using positional captures stored in a variable

2021-03-13 Thread Brad Gilbert
It makes <…> more consistent precisely because <$pattern> doesn't capture.

If the first character inside is anything other than an alpha it doesn't
capture.
Which is a very simple description of when it captures.

 doesn't capture because of the 「?」
 doesn't capture because of the 「!」
<.ws> doesn't capture because of the 「.」
<> doesn't capture because of the 「&」
<$pattern> doesn't capture because of the 「$」
<$0> doesn't capture because of the 「$」
<@a> doesn't capture because of the 「@」
<[…]> doesn't capture because of the 「[」
<-[…]> doesn't capture because of the 「-]
<:Ll> doesn't capture because of the 「:」

For most of those, you don't actually want it to capture.
With 「.」 the whole point is that it doesn't capture.

 does capture because it starts with an alpha
 does capture because it starts with an alpha

$0 = <$pattern> doesn't capture to $, but does capture to $0
$ = <$pattern> captures because of $ =

It would be a mistake to just make <$pattern> capture.
Consistency is perhaps Raku's most important feature.

One of the mottos of Raku, is that it is ok to confuse a new programmer, it
is not ok to confuse an expert.
An expert in Raku understands the deep fundamental ways that Raku is
consistent.
So breaking consistency should be very carefully considered.

In this case, there is very little benefit.
Even worse, you then have to come up with some new syntax to prevent it
from capturing when you don't want it to.
That new syntax wouldn't be as guessible as it currently is. Which again
would confuse experts.

If anyone seriously suggests such a change, I will vehemently fight to
prevent it from happening.

I would be more likely to accept <=$pattern> being added as a synonym to
.

On Sat, Mar 13, 2021 at 3:30 PM Joseph Brenner  wrote:

> Thanks much for your answer on this.  I think this is the sort of
> trick I was looking for:
>
> Brad Gilbert wrote:
>
> > You can put it back in as a named
>
> > > $input ~~ / 
> > 「9 million」
> >  pattern => 「9 million」
> >   0 => 「9」
> >   1 => 「million」
>
> That's good enough, I guess, though you need to know about the
> issue... is there some reason it shouldn't happen automatically,
> using the variable name to label the captures?
>
> I don't think this particular gotcha is all that well
> documented, though I guess there's a reference to this being a
> "known trap" in the documentation under "Regex interpolation"--
> but that's the sort of remark that makes sense only after you know
> what its talking about.
>
> I have to say, my first reaction was something like "if they
> couldn't get this working right, why did they put it in?"
>
>
> On 3/11/21, Brad Gilbert  wrote:
> > If you interpolate a regex, it is a sub regex.
> >
> > If you have something like a sigil, then the match data structure gets
> > thrown away.
> >
> > You can put it back in as a named
> >
> > > $input ~~ / 
> > 「9 million」
> >  pattern => 「9 million」
> >   0 => 「9」
> >   1 => 「million」
> >
> > Or as a numbered:
> >
> > > $input ~~ / $0 = <$pattern>
> > 「9 million」
> >  0 => 「9 million」
> >   0 => 「9」
> >   1 => 「million」
> >
> > Or put it in as a lexical regex
> >
> > > my regex pattern { (\d+) \s+ (\w+) }
> > > $input ~~ /   /
> > 「9 million」
> >  pattern => 「9 million」
> >   0 => 「9」
> >   1 => 「million」
> >
> > Or just use it as the whole regex
> >
> > > $input ~~ $pattern # variable
> > 「9 million」
> >  0 => 「9」
> >  1 => 「million」
> >
> > > $input ~~  # my regex pattern /…/
> > 「9 million」
> >  0 => 「9」
> >  1 => 「million」
> >
> > On Thu, Mar 11, 2021 at 2:29 AM Joseph Brenner 
> wrote:
> >
> >> Does this behavior make sense to anyone?  When you've got a regex
> >> with captures in it, the captures don't work if the regex is
> >> stashed in a variable and then interpolated into a regex.
> >>
> >> Do capture groups need to be defined at the top level where the
> >> regex is used?
> >>
> >> { #  From a code example in the "Parsing" book by Moritz Lenz, p. 48,
> >> section 5.2
> >>my $input = 'There are 9 million bicycles in beijing.';
> >>if $input ~~ / (\d+) \s+ (\w+) / {
> >>say $0.^name;  # Match
> >>say $0;  

Re: Working with a regex using positional captures stored in a variable

2021-03-11 Thread Brad Gilbert
If you interpolate a regex, it is a sub regex.

If you have something like a sigil, then the match data structure gets
thrown away.

You can put it back in as a named

> $input ~~ / 
「9 million」
 pattern => 「9 million」
  0 => 「9」
  1 => 「million」

Or as a numbered:

> $input ~~ / $0 = <$pattern>
「9 million」
 0 => 「9 million」
  0 => 「9」
  1 => 「million」

Or put it in as a lexical regex

> my regex pattern { (\d+) \s+ (\w+) }
> $input ~~ /   /
「9 million」
 pattern => 「9 million」
  0 => 「9」
  1 => 「million」

Or just use it as the whole regex

> $input ~~ $pattern # variable
「9 million」
 0 => 「9」
 1 => 「million」

> $input ~~  # my regex pattern /…/
「9 million」
 0 => 「9」
 1 => 「million」

On Thu, Mar 11, 2021 at 2:29 AM Joseph Brenner  wrote:

> Does this behavior make sense to anyone?  When you've got a regex
> with captures in it, the captures don't work if the regex is
> stashed in a variable and then interpolated into a regex.
>
> Do capture groups need to be defined at the top level where the
> regex is used?
>
> { #  From a code example in the "Parsing" book by Moritz Lenz, p. 48,
> section 5.2
>my $input = 'There are 9 million bicycles in beijing.';
>if $input ~~ / (\d+) \s+ (\w+) / {
>say $0.^name;  # Match
>say $0;# 「9」
>say $1.^name;  # Match
>say $1;# 「million」
>say $/;
> # 「9 million」
> #  0 => 「9」
> #  1 => 「million」
>}
> }
>
> say '---';
>
> { # Moving the pattern to var which we interpolate into match
>my $input = 'There are 9 million bicycles in beijing.';
>my $pattern = rx{ (\d+) \s+ (\w+) };
>if $input ~~ / <$pattern> / {
>say $0.^name;  # Nil
>say $0;# Nil
>say $1.^name;  # Nil
>say $1;# Nil
>say $/;# 「9 million」
>}
> }
>
> In the second case, the match clearly works, but it behaves as
> though the capture groups aren't there.
>
>
>raku --version
>
>Welcome to 퐑퐚퐤퐮퐝퐨™ v2020.10.
>Implementing the 퐑퐚퐤퐮™ programming language v6.d.
>


Re: dimensions in a multidimensional array

2021-02-05 Thread Brad Gilbert
There is a reason that you can't just ask for the dimensions of an
unspecified multidimensional array.
It may be multiple dimensions.

[[1,2,3],
[4,5,6,7,8,9,10]].shape

If it gave a result it would be something like:

(2,3|7)

On Fri, Feb 5, 2021 at 8:50 AM Theo van den Heuvel 
wrote:

> Hi gurus,
>
> I cannot seem to find an idiomatic way to get the dimensions of a
> multidimensional array,
> other than by looking at the size of the first row and column, with
> @m[0;*].elems and @m[*;0].elems.
> Am I missing something in the docs?
>
> Thanks,
>
> --
> Theo van den Heuvel
>
>


Re: LTA documentation page

2021-01-05 Thread Brad Gilbert
There really shouldn't be that much difference between what the
documentation says and how your version works.

The biggest thing would be new functions that you don't have yet.
(Which you could just copy the code from the sources into your program if
you need them.)

Even if rakudoc did install, it would just copy the most recent docs as of
the time you installed it.

It's not like the Perl docs which are in the same repository as the code.
The Raku docs aren't even controlled by the same organization on
GitHub, let alone being in the same repository.
(There are different requirements to being in the different projects.)

On Tue, Jan 5, 2021 at 7:31 AM Gianni Ceccarelli 
wrote:

> On 2021-01-05 JJ Merelo  wrote:
> > Gianni is basically right. rakudoc has not really been released yet
> > into the ecosystem, and p6doc will get you the documentation itself,
> > which you will have to build then. So LTA is true, and there's some
> > work to be done. There's probably an issue already created, but it
> > will pop up if you create another one, so please do raise the issue
> > and focus it on the documentation part if it does not.
>
> https://github.com/Raku/doc/issues/3769
>
> > We really encourage people to peruse the documentation online, though.
> > https://docs.raku.org
>
> Why? The online documentation will not, in the general case, match the
> rakudo version I have installed.
>
> --
> Dakkar - 
> GPG public key fingerprint = A071 E618 DD2C 5901 9574
>  6FE2 40EA 9883 7519 3F88
> key id = 0x75193F88
>
>


Re: surprise with start

2021-01-05 Thread Brad Gilbert
What is happening is that the `start` happens on another thread.
That thread is not the main thread.

The program exits when the main thread is done.
Since the main thread doesn't have anything else to do it exits before that
`sleep` is done.

The more correct way to handle it would be to wait for the `start` to
finish.

my $p = start { sleep 1; say "done" }
say "working";
await $p;

On Tue, Jan 5, 2021 at 7:41 AM Theo van den Heuvel 
wrote:

> thanks. That helps.
>
> Elizabeth Mattijsen schreef op 2021-01-05 14:37:
> > If those are the only lines in your program, the program will have
> > exited before the sleep in the start has actually passed.  If you
> > change the program to:
> >
> > start { sleep 1; say "done"; exit }
> > say "working";
> > sleep;
> >
> > you should also see the "done".
> >
> >> On 5 Jan 2021, at 14:15, Theo van den Heuvel 
> >> wrote:
> >>
> >> Hi gurus,
> >>
> >> The first example in the documentation on the start control flow does
> >> not seem to work as promised.
> >> Here is the code:
> >>
> >> start { sleep 1; say "done" }
> >> say "working";
> >> # working, done
> >>
> >> Both 2020.1 and the 2020.12 version under Ubuntu yield only "working".
> >> Am I missing something?
> >>
> >> --
> >> Theo van den Heuvel
>
> --
> Theo van den Heuvel
> Van den Heuvel HLT Consultancy
>


Re: Extra . needed

2021-01-03 Thread Brad Gilbert
You've already asked a similar question.

https://stackoverflow.com/questions/54033524/perl6-correctly-passing-a-routine-into-an-object-variable

When you call $a.f() you are getting the value in &!f which is a function.

When you call $a.f().() you are getting the value in &!f, and then also
calling that function.

You don't need the parens on a method call if they are empty.

So $a.f() is the same as $a.f
and $a.f().() is the same as $a.f.()

On Sun, Jan 3, 2021 at 12:30 PM Richard Hainsworth 
wrote:

> I was playing with classes and adding a closure to an attribute.
>
> I discovered that to call a closure on object I need `.()` rather than
> just `()`. See REPL below.
>
> raku
> Welcome to 퐑퐚퐤퐮퐝퐨™ v2020.12.
> Implementing the 퐑퐚퐤퐮™ programming language v6.d.
> Built on MoarVM version 2020.12.
>
> To exit type 'exit' or '^D'
> > class A { has &.f = -> { 'xyz' }}
> (A)
> > my A $a .=new
> A.new(f => ->  { #`(Block|94272504746848) ... })
> > say $a.f()
> ->  { #`(Block|94272504749656) ... }
> > say $a.f.()
> xyz
> >
>
>
> I was wondering whether it was intended for `()` to return something other
> than `.()`?
>
> My first thought would be that `.()` would have the same syntactic sugar
> as `.[]` on an Array object.
>
> I looked in the Documentation and in Classes found
> &!callback();
> inside class Task.
>
> So I think there may be something a bit wrong. Or is this an artifact of
> REPL?
>


Re: concurrency of asynchronous events - input from multiple keyboards

2021-01-01 Thread Brad Gilbert
I think the simplest way to turn that into a Supply is to use the `supply`
keyword

my $pm = Audio::PortMIDI.new;


my $input = supply {
my $stream = $pm.open-input($input-device-number, 32);

DONE {
$stream.close;
}

loop {
emit $stream.read(1);
}
}


react {
whenever key-pressed(:!echo) {
given .fc {
when 'q' { done }
default { .raku.say }
}
}

my $voice = $pm.open-output($output-device-number, 32);
whenever $input {
$voice.write(|$_);
}
}

On Fri, Jan 1, 2021 at 12:31 PM Nathan Gray 
wrote:

> I am working on a small virtual organ program, where I have
> multiple MIDI controller keyboards which can be connected to one
> or more synthesizer channels to emit various sounds
> simultaneously.
>
> At this point, I am able to read events from a single MIDI
> controller and send the events to the correct synthesizer channel
> (I'm using Timidity at the moment).
>
> I would like to read keypresses from the computer keyboard and
> use those to adjust which synthesizers receive which MIDI events.
> In other words, I press a note on my MIDI controller and the note
> plays a sound on the synthesizer I have set up.  When I press the
> letter 'a' on my computer keyboard, I would like to add another
> synthesizer, so that subsequent notes played on the MIDI
> controller send events to the original synthesizer and to a new
> synthesizer.
>
> I was able to build a script to read in events from the computer
> keyboard (via the module Term::ReadKey).  I read these keypresses
> in a react block with a whenever:
>
> react {
> whenever key-pressed(:!echo) {
> # Eventually will connect or disconnect a synthesizer for the
> relevant MIDI controller.
> # Currently just prints out the key that was pressed.
> given .fc {
> when 'q' { done }
> default { .raku.say }
> }
> }
> }
>
> The MIDI events are being read via the module Audio::PortMIDI in
> a loop block:
>
> my $pm = Audio::PortMIDI.new;
> my $stream = $pm.open-input($input-device-number, 32);
> my $voice = $pm.open-output($output-device-number, 32);
> # Read events from the MIDI controller and write to the synthesizer.
> loop {
> if $stream.poll {
> my @notes = $stream.read(1);
> $voice.write(@notes);
> }
> }
>
> I'm struggling to figure out how to combine the react block for
> the computer keyboard events and the loop block for the MIDI
> events.  I would like to be able to accept events from both
> devices concurrently.
>
> It seems like I might need to turn the loop into a Supply of some
> kind, but I'm not sure how I would go about doing that.  If I
> understand correctly, once it is a supply, I could add it to the
> react block as another whenever event.
>
> I have found examples of how to create a Supply using a loop and
> a Promise that is kept after a specific amount of time
> (
> https://stackoverflow.com/questions/57486372/concurrency-react-ing-to-more-than-one-supply-at-a-time
> ),
> but I have not found anything that is polling from a data stream.
>
> My attempt of polling the stream in a whenever block errors out,
> without me ever pressing a key, which makes it seem like it is
> trying to read when there are no keypress events available.
>
> whenever so $stream.poll {
> my @notes = $stream.read(1);
> ...
> }
>
> Type check failed for return value; expected Str but got Any (Any)
>   in sub with-termios at
> /home/kolibrie/.raku/sources/C758559420AEADF99B8D412BDFADA739CAC14C2A
> (Term::ReadKey) line 20
>   in block  at
> /home/kolibrie/.raku/sources/C758559420AEADF99B8D412BDFADA739CAC14C2A
> (Term::ReadKey) line 51
>
> Any insights would be greatly appreciated.
>
> -kolibrie
>


Re: for and ^ question

2020-12-31 Thread Brad Gilbert
It does not look like an array from 0 to ($nCount - 1). It only iterates
like that.

It is a Range object from 0 to $nCount excluding $nCount.

^9 === Range.new( 0, 9, :excludes-max ) # True
0 ~~ ^9 # True
1 ~~ ^9 # True
0.5 ~~ ^9 # True
8 ~~ ^9 # True
8.9 ~~ ^9 # True

9 ~~ ^9 # False

In the case of `for ^9 {…}` it iterates starting at 0, and continuing to
just before 9.

It does that because `for` iterates the Range object.

It does NOT store any values other than the min, max and either excludes.

An array would store the values in the middle. Which would be a waste of
memory.
Which is why it does not do that.

On Wed, Dec 30, 2020 at 8:09 PM ToddAndMargo via perl6-users <
perl6-us...@perl.org> wrote:

> On 12/30/20 5:39 PM, ToddAndMargo via perl6-users wrote:
> > Hi All,
> >
> > In the following for loop:
> >
> >  for ^$nCount -> $i {
> >
> > What is the ^ doing?
> >
> > Confused again,
> > -T
>
> Used in context, the ^ makes the integer $nCount look
> like an array of 0 to ($nCount - 1).  Am I missing
> something?
>
> my $x=4;
> for ^$x -> $i { print "i = $i\n"; }
>
> i = 0
> i = 1
> i = 2
> i = 3
>
>


Re: Checking for nil return

2020-12-28 Thread Brad Gilbert
The closest to null is actually an undefined type object

On Mon, Dec 28, 2020, 3:36 PM yary  wrote:

> Been thinking about this, and checked out the Rakudo repository to peek
> into the source.
>
> Allowing Failure as a return always makes sense to me– every block needs
> to be capable of passing along a failure, that's how the language is
> designed.
>
> On the other hand, Nil is not a Failure. Conceptually it is a lack of an
> answer, similar to SQL's null concept.
>
> What's the usefulness of having Nil skip return type checking-
> specifically Nil and not its Failure descendents?
>
> This example under https://docs.raku.org/type/Nil shows what I think is a
> less-than-awesome specification, and I am curious about the reasoning
> behind it being defined as valid
>
> sub a( --> Int:D ) { return Nil }
>
>
>
> -y
>
>
> On Sun, Dec 20, 2020 at 7:18 PM Brad Gilbert  wrote:
>
>> Nil is always a valid return value regardless of any check.
>>
>> This is because it is the base of all failures.
>>
>> On Sat, Dec 19, 2020, 8:17 PM yary  wrote:
>>
>>> Is this a known issue, or my misunderstanding?
>>>
>>> > subset non-Nil where * !=== Nil;
>>> (non-Nil)
>>> > sub out-check($out) returns non-Nil { return $out }
>>> 
>>> > out-check(44)
>>> 44
>>> > out-check(Nil)
>>> Nil
>>>
>>> ^ Huh, I expected an exception on "out-check(Nil)" saying the return
>>> value failed the "returns" constraint.
>>>
>>> The subtype works as I expect as an the argument check
>>>
>>> > sub in-check (non-Nil $in) { $in }
>>> 
>>> > in-check(33)
>>> 33
>>> > in-check(Nil)
>>> Constraint type check failed in binding to parameter '$in'; expected
>>> non-Nil but got Nil (Nil)
>>>   in sub in-check at  line 1
>>>   in block  at  line 1
>>>
>>> $ raku --version
>>> This is Rakudo version 2020.07 built on MoarVM version 2020.07
>>> implementing Raku 6.d.
>>>
>>> Is this my understanding of return type checking that's off, or a known
>>> issue, or something I should add to an issue tracker?
>>>
>>> -y
>>>
>>


Re: Is self a C pointer?

2020-12-20 Thread Brad Gilbert
It doesn't matter if it is a C pointer.

Unless you are working on Moarvm, you should consider them arbitrary unique
numbers. Like GUID.

That said, yes I'm sure that they represent a location in memory.

On Sun, Dec 20, 2020, 6:45 PM ToddAndMargo via perl6-users <
perl6-us...@perl.org> wrote:

> Hi All,
>
> In the following:
>
> Example 3:
>
> class PrintTest {
> has Str $.Msg;
>
> method PrintMsg()  {
>print "self   = <" ~ self.Msg ~ ">\n";
>print "self   = <" ~ self.Str ~ ">\n";
> }
> }
>
> my $x = PrintTest.new(Msg => "abc");
>
> $x.PrintMsg
> self   = 
> self   = >
>
> is "95224840" a C pointer?  What is that thing?
>
>
> Many thanks,
> -T
>


Re: Checking for nil return

2020-12-20 Thread Brad Gilbert
Nil is always a valid return value regardless of any check.

This is because it is the base of all failures.

On Sat, Dec 19, 2020, 8:17 PM yary  wrote:

> Is this a known issue, or my misunderstanding?
>
> > subset non-Nil where * !=== Nil;
> (non-Nil)
> > sub out-check($out) returns non-Nil { return $out }
> 
> > out-check(44)
> 44
> > out-check(Nil)
> Nil
>
> ^ Huh, I expected an exception on "out-check(Nil)" saying the return value
> failed the "returns" constraint.
>
> The subtype works as I expect as an the argument check
>
> > sub in-check (non-Nil $in) { $in }
> 
> > in-check(33)
> 33
> > in-check(Nil)
> Constraint type check failed in binding to parameter '$in'; expected
> non-Nil but got Nil (Nil)
>   in sub in-check at  line 1
>   in block  at  line 1
>
> $ raku --version
> This is Rakudo version 2020.07 built on MoarVM version 2020.07
> implementing Raku 6.d.
>
> Is this my understanding of return type checking that's off, or a known
> issue, or something I should add to an issue tracker?
>
> -y
>


Re: How do I address individual elements inside an object

2020-12-19 Thread Brad Gilbert
You can interpolate a method call in a string, but you need the parens.

say "$FruitStand.location() has $FruitStand.apples() apples in stock";

On Sat, Dec 19, 2020 at 4:28 AM Laurent Rosenfeld via perl6-users <
perl6-us...@perl.org> wrote:

> Yeah, right. $FruitStand.apples is not a direct access to the attribute,
> but a method invocation (a call to a method implicitly created by Raku), so
> it doesn't get interpolated within the string. So it should be outside the
> string or used with a code interpolation block.
>
> For example:
>
> say "Fruitstand in {$FruitStand.location} has {$FruitStand.apples}
> apples.";
>
> or
>
> say "Fruitstand in ", $FruitStand.location,  "has ", $FruitStand.apples,
> " apples.";
>
> or the construct with the ~ concatenation operator that you used.
>
> Cheers,
> Laurent..
>
>
> 
>  Garanti
> sans virus. www.avast.com
> 
> <#m_8010816652420510664_DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2>
>
> Le ven. 18 déc. 2020 à 23:55, ToddAndMargo via perl6-users <
> perl6-us...@perl.org> a écrit :
>
>> On 12/18/20 9:42 AM, William Michels via perl6-users wrote:
>> > Hi Laurent, I get:
>> >
>> > Fruitstand in Fruit<140431957910656>.location has
>> >   Fruit<140431957910656>.apples apples.
>> >
>> > [Rakudo v2020.10]
>> >
>> > Best, Bill.
>> >
>>
>> Hi Bill,
>>
>>  From my notes in progress:
>>
>> -T
>>
>>
>> *** addressing values inside and object ***
>>
>> Reading:
>>say $FruitStand.apples
>>400
>>
>>$FruitStand.apples.say
>>400
>>
>>print $FruitStand.location ~ " has " ~ $FruitStand.apples ~"
>> apples in stock\n";
>>Cucamonga has 400 apples in stock
>>
>>Note: an "oops!".  Separate the variables from the string, or else:
>>say "$FruitStand.location has $FruitStand.apples apples in
>> stock";
>>Fruit<79300336>.location has Fruit<79300336>.apples apples in
>> stock
>>
>>Writing (must be declared as "rw"):
>>
>


Re: Missing NullPointerException

2020-12-16 Thread Brad Gilbert
with $drone.engine {
.start;
say "engine started";
}

On Tue, Dec 15, 2020, 11:10 PM Konrad Bucheli via perl6-users <
perl6-us...@perl.org> wrote:

>
> Hi Ralph
>
> Thanks a lot for the extensive answer.
>
> I still consider it a trap because it does not do what it tells it does.
>
> If I have:
>
> say "launching drone";
> $drone.engine.start;
> say "engine started";
>
> After I run the above I got both messages, but no propeller spinning. So I
> checked start() in and out, because that is where the problem is obviously.
> But it was not, it was in engine().
> And I want my programming language/runtime to tell me if I am doing
> obviously stupid things.
> Note that it has nothing to do with the "pyramid of doom". It would make
> sense in a pure functional environment, but Raku is multi-paradigm, no?
>
> Now to be "safe" (as in fail fast) I have to always
>
> say "launching drone";
> # this intermediate variable is important defensive programming, else it
> will not explode on Nil if there are stupid errors in engine()
> my $engine = $drone.engine;
> $engine.start;
> say "engine started";
>
> which is the opposite of concise.
>
> But Raku is Raku, there is surely a way to make sure that my Nil explodes
> in my code. Is there a `use FailingNil`?
>
> Concerning documentation: I do not know where there is an appropriate
> place to warn about this behavior. There where we teach how methods are
> called? Surely it would not have found me. I look up a lot in
> documentation, but not such trivial stuff.
>
> Cheers
>
> Konrad
>
> From: Ralph Mellor 
> Sent: Saturday, 5 December 2020 15:58
> To: Konrad Bucheli 
> Cc: perl6-users 
> Subject: Re: Missing NullPointerException
>
> On Thu, Dec 3, 2020 at 10:20 PM Konrad Bucheli via perl6-users
>  wrote:
> >
> > What is actually the rationale for such a behaviour?
>
> Ergonomically sound null safety.
>
> First, consider what other languages have. Quoting
> https://en.wikipedia.org/wiki/Safe_navigation_operator:
>
> > In object-oriented programming, the safe navigation operator
> > ... is used to avoid sequential explicit null checks ...
> ...
> > In programming languages where the navigation operator
> > (e.g. ".") leads to an error if applied to a null object, the safe
> > navigation operator stops the evaluation of a method/field
> > chain and returns null as the value of the chain expression.
> ...
> > It is currently supported in languages such as Apex, Groovy,
> > Swift, Ruby, C#, Kotlin, CoffeeScript, Scala, Dart and others.
> ...
> > The main advantage of using this operator is that it avoids the
> > pyramid of doom. ...
>
> Many aspects of Raku's design are better solutions than are found
> in older PLs like those listed above. This is an example. Instead of
> devs having unsafe operations by default, and having to write `?.`
> to get safety, in Raku one just writes `.` and always gets safety.
>
> > For me it was an unexpected trap
>
> This statement couples deep wisdom (the "for me" qualification,,
> deferring it till after you'd first asked about what the rationale was,
> and sharing your experience) with a Canby.[1]
>
> It's clear that you were missing some knowledge, and that it
> bit you, and are now exploring how best to learn from that.
>
> I accept without reservation the claim it was "unexpected". (That
> is the sort of thing that is typically experienced and reported by
> request of our right hemispheres, and it is generally reliable.)
>
> I also recognize what I imagine as a negative effect associated
> with classifying this experience / situation as a "trap", and the
> negative affect associated with applying that classification, which
> is to say your right hemisphere's experience of that classification.
>
> With that said, I now wish to engage our respective unreliable
> left hemispheres, the ones that drive classification, and wish to
> suggest another way to view this situation.
>
> I would argue that you are classifying safe navigation as a trap,
> and thus likely experiencing it negatively. Perhaps for you this
> can/will instead become a gift (perhaps also unexpected)?
>
> A fundamental part of human experience is interpreting one's
> reactions to things in the light of further knowledge and/or
> experience. Larry has made it clear to me that this is one of
> the keys to his approach to life, and to PL design, in both the
> sense of how he approaches a PL's design and how the PL's
> designed features reward those who think the same way. (I
> have found this endlessly inspiring.)
>
> Applying that to your experience, you could alternately view
> what happened as a surprise that arises from Raku's default
> of safety, which is about freedom (avoiding both the extensive
> boilerplate of the pyramid of doom, and the modern shorter
> but still boilerplate additional ?), and not, it could reasonably
> be argued, about a trap.
>
> cf my discussion of what Vadim Belman had classified as a WAT in
> 

Re: Raku modules in Gentoo's Portage

2020-12-01 Thread Brad Gilbert
I suspect that the right way to do this may be to do something like having
a subclass of
CompUnit::* which does things the Gentoo way.

I would assume that the lock is so that only one copy of Rakudo is changing
the repository at a time.
Presumably Gentoo already prevents more than one thing installing at a time.
So that would be one thing that a Gento specific subclass would change.

On Tue, Dec 1, 2020 at 4:15 AM p.spek via perl6-users 
wrote:

> Hi, fellow Rakoons,
>
> I've been looking into the creation of a Portage tree for Gentoo, to allow
> installation of Raku modules through the default package manager.
>
> There's currently two issues I need to iron out, and I have no clue how to
> fix
> either at this point. The first one deals with the installation mechanics
> of
> Raku, which I don't grasp completely yet. The other issue isn't really
> relevant
> if I can't get a module installed in the first place, so I'm going to
> stick to
> just the first problem.
>
> I'm using this small bit of Raku code to handle the actual installation:
>
> my $repository =
> CompUnit::RepositoryRegistry.repository-for-name('site');
> my $meta-file = $path.add('META6.json');
> my $dist = Distribution::Path.new($path, :$meta-file);
>
> $repository.install($dist, :$force);
>
> This works in general, but it fails when enabling the sandbox feature on
> Portage. This is a feature I generally have enabled, and seems to be
> common to
> have enabled among Gentoo users.
>
> When installing the module this way, it tries to access
> /usr/local/share/perl6/site/repo.lock. It is not allowed to leave it's
> installation sanbox at /var/tmp/portage/dev-raku/io-path-xdg-0.2.0 (I'm
> testing
> with IO::Path::XDG).
>
> I'm assuming it's making this lock file in order to ensure it can do a
> certain
> operation without interference from other installations. Which operation is
> this, and is it possible to work around this somehow?
>
> With Perl (and most other languages, really), it's just dropping some
> files in
> the right directory, which then gets merged into the root filesystem. I'd
> preferably use a similar approach with Raku modules.
>
> I've seen that installed modules generally have hashed filenames. If I can
> just
> generate the "right" hashes and drop them into the right directory, that
> would
> be good enough for me. If there's more to it, I would greatly appreciate
> some
> explanation on how this works, so I can consider if it's worth my time.
>
> Thanks in advance for any help!
>
> --
> With kind regards,
>
> Patrick Spek
>
>
> www:  https://www.tyil.nl/
> mail: p.s...@tyil.nl
> pgp:  1660 F6A2 DFA7 5347 322A  4DC0 7A6A C285 E2D9 8827
>
> social: https://soc.fglt.nl/tyil
> git:https://home.tyil.nl/git
>


Re: \n and array question

2020-11-14 Thread Brad Gilbert


is the same as

Q :single :words < a b c >

Note that :single means it acts like single quotes.

Single quotes don't do anything to convert '\n' into anything other than a
literal '\n'.

If you want that to be converted to a linefeed you need to use double quote
semantics (or at least turn on :backslash).

Q :double :words < a\n b\n c >

Of course that also doesn't do what you want because a linefeed character
is also whitespace, so it gets removed along with the rest of the
whitespace.

What you want to do use is :quotewords and "".

Q :quotewords < "a\n" "b\n" c >

The short way to write that is

<< "a\n" "b\n" c >>

Although if you are going to append a newline to every element I would
consider writing it this way:

< a b c > X~ "\n"

or

< a b c > »~» "\n"

On Sat, Nov 14, 2020 at 1:21 PM ToddAndMargo via perl6-users <
perl6-us...@perl.org> wrote:

>  >> On Nov 14, 2020, at 14:12, ToddAndMargo via perl6-users
>  wrote:
>  >>
>  >> On 2020-11-14 11:08, Curt Tilmes wrote:
>  >>> On Sat, Nov 14, 2020 at 2:03 PM ToddAndMargo via perl6-users
>  >>>  wrote:
>   Just out of curiosity, why is the \n printed out literally here?
>   p6 'my @x = <"aaa\n","bbb\n","ccc\n">; for @x {print @_};'
>  >>> Your 'word quoting' <> is sort of like single quotes -- it keeps the
>  >>> literal stuff.  You could
>  >>> use <<>> which is more like double quotes,
>  >>> Curt
>  >>
>  >> or remove the commas.  I put everything in [0]
>  >>
>  >>
>  >> $ p6 'my @x = ; for @x {print "$_\n";}'
>  >> aaa\n
>  >> bbb\n
>  >> ccc\n
>  >>
>  >> $ p6 'my @x = <>; for @x {print "$_\n";}'
>  >> aaa
>  >> bbb
>  >> ccc
>  >>
>  >> $ p6 'my @x = <>; for @x {print "$_";}'
>  >> aaabbbccc
>  >>
>  >> What am I missing?
>  >>
>  >> -T
>
>
> On 2020-11-14 11:18, Matthew Stuckwisch wrote:
> > The <…> and «…» constructors break on whitespace.
> >
> > So  will actually produce the following array:
> >
> >  ["a,b,c,d,e,f"]
> >
> > It's only one item.  If we placed space after the comma, that is,  c, d, e, f>, you'd get a six item list, but with the commas attached to all
> but the final:
> >
> > ["a,", "b,", "c,", "d,", "e,", "f"]
> >
> > By replacing the commas with spaces, e.g., , you allow it
> to break into ["a", "b", "c", "d", "e", "f"]
> >
> > Matéu
> >
>
> Ya, I caught that booboo.  :'(
>
> Question still stands.  Why is the \n working as a CR/LF and
> being printed as a litteral?
>


Re: spurt and array question

2020-11-14 Thread Brad Gilbert
Actually no I'm not “forgetting that spurt comes with an `:append` option”.
That is a slightly different use case.
It is where you are appending to an existing file once, and then never
touching it again.

(Or maybe you might be touching it again in a few hours.)

---

Given that this is what you wrote:

unlink( $Leafpadrc );
for @LeafpadrcNew -> $Line  { spurt( $Leafpadrc, $Line ~ "\n", :append
); }

I want to know how this is the hard way:

given $Leafpadrc.IO.open(:w) {
for @LeafpadrcNew -> $Line  { .put: $Line }
.close;
}

or

given $Leafpadrc.IO.open(:w) -> $*OUT {
for @LeafpadrcNew -> $Line  { put $Line }
$*OUT.close;
}

or

given $Leafpadrc.IO.open(:w) -> $*OUT {
.put for @LeafpadrcNew;
$*OUT.close;
}

or

given $Leafpadrc.IO.open(:w, :!out-buffer) -> $*OUT {
.put for @LeafpadrcNew;
}



On Sat, Nov 14, 2020 at 1:07 PM ToddAndMargo via perl6-users <
perl6-us...@perl.org> wrote:

> On 2020-11-14 06:00, Brad Gilbert wrote:
> > The purpose of `spurt` is to:
> > 1. open a NEW file to write to
> > 2. print a single string
> > 3. close the file
> >
> > If you are calling `spurt` more than once on a given file, you are doing
> > it wrong.
>
> You are forgetting that spurt comes with an `:append` option.
>
> > If you give `spurt` an array, you are probably doing it wrong
> > unless you want the array turned into a single string first.
>
> Ya, doing things the hard way.
>


Re: spurt and array question

2020-11-14 Thread Brad Gilbert
The purpose of `spurt` is to:
1. open a NEW file to write to
2. print a single string
3. close the file

If you are calling `spurt` more than once on a given file, you are doing it
wrong.
If you give `spurt` an array, you are probably doing it wrong; unless you
want the array turned into a single string first.

`spurt` is the dual of `slurp`.

The purpose of `slurp` is to:
1. open an existing file to read from
2. read the whole file into a single string
3. close the file

That is they are only short-cuts for a simple combination of operations.

If you are opening a file for only the express purpose of reading ALL of
its contents into a SINGLE STRING, use `slurp`.
If you are opening a file for only the express purpose of writing ALL of
its contents from a SINGLE STRING, use `spurt`.

If you are doing anything else, use something else.

---

Assuming you want to loop over a bunch of strings to print to a file, use
`open` and `print`/`put`/`say`.
This is also faster than calling `spurt` more than once because you only
open and close the file once.

If you want there to be only one call, turn your array into the appropriate
single string first.

On Sat, Nov 14, 2020 at 1:59 AM ToddAndMargo via perl6-users <
perl6-us...@perl.org> wrote:

> Hi All,
>
> I am writing out an array of text lines to a file.
> I just can't help but thinking I am doing it the
> hard way.
>
> unlink( $Leafpadrc );
> for @LeafpadrcNew -> $Line  { spurt( $Leafpadrc, $Line ~ "\n",
> :append ); }
>
> If I spurt the array, it converts the array into a
> single text line.
>
> The test file looks like this:
>
>  ./.config/leafpad/leafpadrc
>  $ cat leafpadrc
>  0.8.18.1
>  500
>  190
>  Monospace 12
>  1
>  1
>  0
>
> Your thoughts?
>
> -T
>
> --
> ~~
> Computers are like air conditioners.
> They malfunction when you open windows
> ~~
>


Re: Subset w/ Inline::Perl5 RE as constraint

2020-11-06 Thread Brad Gilbert
I'm pretty sure you need to use single quotes for your example, as Raku
will replace the @_[0] before Perl has a chance to do anything with it.

On Thu, Nov 5, 2020, 10:23 PM Paul Procacci  wrote:

> https://github.com/niner/Inline-Perl5
>
> use Inline::Perl5;
>
> subset test of Str where EVAL "sub {@_[0] ~= m/\w+/}", :lang;
>
>
> Question:  Can you pass whatever {*} into eval for use in Inline::Perl5 a
> la subset?
> The above example is incomplete, I understand, however I'm looking to find
> a method of constraining Str's w/ >perl5.8 RE's in subset's without it
> getting too crazy.
>
> The RE's that come w/ raku proper are are much older version of RE and
> cannot accomplish what I need.
>
> Thanks in Advance,
> ~Paul
>
> --
> __
>
> :(){ :|:& };:
>


Re: Constructing a number from digits in an arbitrary base

2020-11-02 Thread Brad Gilbert
I believe this is what you were looking for

sum 46, 20, 26, 87, 11 Z* (1, 101, 101² … *)

sum 1234567890.polymod(101 xx *) Z* (1, 101, 101² … *)

On Mon, Nov 2, 2020 at 2:12 PM Sean McAfee  wrote:

> On Fri, Oct 30, 2020 at 2:19 PM Elizabeth Mattijsen 
> wrote:
>
>> > On 30 Oct 2020, at 22:11, Sean McAfee  wrote:
>> > With polymod, I can get the values of digits even in large bases like
>> 101:
>> >
>> > > 1234567890.polymod(101 xx *)
>> > (46 20 26 87 11)
>> >
>> > Given a list of digit values like that, and the base, I want to
>> reconstruct the original number.
>
>
> So you'd basically need a sub that takes a List, and a base factor, and
>> does the necessary arithmetic for you.  I don't think that's in core.  I'd
>> be glad if someone proved me wrong  :-)
>>
>
> Found it!  The "trick" is to use square braces after the colon and base.
> For example, :101[11,87,26,20,46] evaluates to 1234567890.
>
> The digit values have to be supplied most-significant to
> least-significant, the opposite of the order returned by polymod, and the
> base must be known at compile time, but this is definitely the construction
> I was trying to recall originally.  Even nicer for my golfing purposes, the
> list elements are coerced to numbers automatically, so for example :2[True,
> False, True, False] evaluates to 10.
>
> I can't locate any documentation on this feature, but then I couldn't find
> documentation on the dynamic string-parsing version (eg. :2($str)) when I
> looked either, only the literal form, like :2<10101>.
>
>


Re: Language Design: 'special casing' of split()? (i.e. .split performs concomitant .join? )

2020-10-10 Thread Brad Gilbert
Functions in Raku tend to have one job and one job only.

`split` splits a string.

So if you call `split` on something that is not a string it gets turned
into one if it can.

This happens for most functions.

Having `split` be the only function that auto-vectorizes against an array
would be very confusing.

If it isn't the only function, then you have to come up with some list of
functions which do vectorize.

Then every single person has to memorize that list in its entirety. Which
can be difficult even for experts.

Perl has a similar list of functions which automatically work on `$_`, and
almost no one has that list memorized.
Raku very specifically did not copy that idea.

---

Raku instead has high level concepts that it uses consistently.

One of those concepts is that functions have one job and one job only.

So if you call `chars` on anything it gets turned into a string first.

On Sat, Oct 10, 2020 at 4:23 PM William Michels via perl6-users <
perl6-us...@perl.org> wrote:

> So I guess the first question I have is whether the 'auto-joining' of
> array elements is specc'ed or not.
>
> What you seem to be saying is that when calling a function on an array,
> the first response is for Raku to call something similar to 'cat' on the
> array, then proceed to process the function call. As it is my understanding
> that Raku incorporates a lot of different programming paradigms
> (imperative, object-oriented, functional, etc.), I'm not sure where this
> behavior falls on the 'paradigm ladder'.
>
> I can point to the (functional) R-programming language to show what
> happens there. When manipulating "array-like" (i.e. vector) objects in R,
> you can do nested function calls, or sequential (piped) function calls, and
> still get the same data structure out at the end. So a 10-element input
> gives a 10-element output. In the R-GUI (i.e. REPL):
>
> > 0:9
>  [1] 0 1 2 3 4 5 6 7 8 9
> > x <- 0:9
> > is.vector(x)
> [1] TRUE
> > length(x)
> [1] 10
> > # using base-R:
> > sqrt(tan(cos(sin(x
>  [1] 1.2479614276 0.8867679488 0.8398446968 1.2344525173 0.9431819962
> 0.8044843661 1.1966884594
>  [8] 1.0064589934 0.7823305851 1.1415611482
> > x ->.; sin(.) ->.; cos(.) ->.; tan(.) ->.; sqrt(.)
>  [1] 1.2479614276 0.8867679488 0.8398446968 1.2344525173 0.9431819962
> 0.8044843661 1.1966884594
>  [8] 1.0064589934 0.7823305851 1.1415611482
> > library(magrittr) # add a "piping" library:
> > x %>% sin %>% cos %>% tan %>% sqrt
>  [1] 1.2479614276 0.8867679488 0.8398446968 1.2344525173 0.9431819962
> 0.8044843661 1.1966884594
>  [8] 1.0064589934 0.7823305851 1.1415611482
> > y <- x %>% sin %>% cos %>% tan %>% sqrt
> > is.vector(y)
> [1] TRUE
> > length(y)
> [1] 10
> >
>
> Now it's true that R has a greatly simplified memory/storage model
> compared to Raku. But it's not hard to follow the R-code above, even if you
> don't know the language. If at the end of all your function calls you want
> to stringify and 'collapse' your 10 element vector into a single element
> string, you call paste() on your object, which has a user-definable
> 'collapse' argument that defaults to NULL. [For anyone worried about
> formatting actual output, R has print() and sprintf() and cat() functions
> as well]:
>
> > length(paste(0:9, y))
> [1] 10
> > paste(0:9, y)
>  [1] "0 1.24796142755091"  "1 0.886767948777031" "2 0.839844696795443" "3
> 1.23445251727454"
>  [5] "4 0.943181996210625" "5 0.804484366108825" "6 1.19668845937773"  "7
> 1.00645899343325"
>  [9] "8 0.782330585082487" "9 1.14156114815661"
> > length(paste(0:9, "=", y, collapse= ";  "))
> [1] 1
> > paste(0:9, "=", y, collapse= ";  ")
> [1] "0 = 1.24796142755091;  1 = 0.886767948777031;  2 = 0.839844696795443;
>  3 = 1.23445251727454;  4 = 0.943181996210625;  5 = 0.804484366108825;  6 =
> 1.19668845937773;  7 = 1.00645899343325;  8 = 0.782330585082487;  9 =
> 1.14156114815661"
> >
>
> When I started learning Perl6/Raku a few years ago I actually wondered
> where the different programming paradigms would be delineated. Would
> imperative/structural/procedural code be 'closer to the metal' while
> functional code would be applied to higher-order data structures like
> arrays, arrays-of-lists, arrays-of-hashes, and arrays-of-arrays? And those
> higher-order data structures would then be utilized in object-oriented
> code, i.e. the programmer would be manipulating classes and class-based
> objects of varying complexity to produce a robust and secure program? Or
> would Raku implement a different (i.e. better) paradigm hierarchy that I
> hadn't anticipated?
>
> Best Regards, Bill.
>
> W. Michels, Ph.D.
>
>
>
>
>
> On Tue, Oct 6, 2020 at 1:59 PM Tobias Boege  wrote:
>
>> On Tue, 06 Oct 2020, William Michels via perl6-users wrote:
>> > [...]
>> >
>> > So my question regards "special-casing" of split/join in Raku. Is the
>> first
>> > result on comma-delimited data the default, i.e. joining disparate
>> elements
>> > of an array together head-to-tail? Or is the second result on
>> > 

Re: "ICU - International Components for Unicode"

2020-09-24 Thread Brad Gilbert
Rakudo does not use ICU

It used to though.

Rakudo used to run on Parrot.
Parrot used ICU for its Unicode features.

(Well maybe the JVM backend does currently, I don't actually know.)

MoarVM just has Unicode as one of its features.
Basically it has something similar to ICU already.

---

The purpose of ICU is to be able to add Unicode abilities to systems that
don't already have them.

As such, it does not really make sense to add support for the ICU library
in Raku as I don't think it adds anything that isn't already present.

If there is some feature that ICU has that Raku doesn't then it would make
more sense to add that feature directly to Raku itself.

On Thu, Sep 24, 2020 at 2:15 PM William Michels via perl6-users <
perl6-us...@perl.org> wrote:

> Thanks everyone for the replies. I guess the two questions I have
> pertain mainly to 1) lineage and 2) versioning:
>
> Regarding lineage, I'm interested in knowing if
> Pugs/Parrot/Niecza/STD/Perlito/viv/JVM/Rakudo ever used the ICU
> Libraries--even if now that data has been extracted into a Raku-native
> data structure. I'm fairly certain one principal Rakudo developer is a
> C++ expert, so this idea isn't too far fetched.
>
> Regarding versioning, it would be great to tell people that Raku
> conforms to the latest-and-greatest ICU Library version, currently
> sitting at version# ICU_67. That way when people are weighing Raku vs
> Ruby or Python or Haskell or Go, we can tell them "Raku v6.d extracts
> ICU_67 thus it conforms to the most current (and most widely accepted)
> Unicode Library release (ICU 67 / CLDR 37 locale data / Unicode 13)."
> I've read over Daniel's blog post but I don't recall explicit mention
> of Unicode version 12, or 13, etc., although it does seem that
> following his links takes you to references for Unicode 13.0.0 (see
> https://www.unicode.org/reports/tr44/). Does Rakudo roll it's own UCD?
> Is there no reliance on ICU?
>
> Anyway, If Daniel or Samantha or Joseph or Liz can confirm/refute
> Raku's use of the (widely-adopted) ICU C-Library and/or Java-Library,
> I will have learned something.
>
> Thanks, Bill.
>
> http://site.icu-project.org/download/67
>
> "ICU 67 updates to CLDR 37 locale data with many additions and
> corrections. This release also includes the updates to Unicode 13,
> subsuming the special CLDR 36.1 and ICU 66 releases. ICU 67 includes
> many bug fixes for date and number formatting, including enhanced
> support for user preferences in the locale identifier. The
> LocaleMatcher code and data are improved, and number skeletons have a
> new “concise” form that can be used in MessageFormat strings. This is
> the first regular release after ICU 65. ICU 66 was a low-impact
> release with just Unicode 13 and a few bug fixes."
>
>
> Library/Language support for ICU:
>
> Objective C CocoaICU A set of Objective-C classes that encapsulate parts
> of ICU.
> C# GenICUWrapper A tool that generates a rudimentary C# wrapper around
> the C API of ICU4C. This could be used to generate headers for other
> ICU wrappers.
> C# ICU Dotnet - .NET bindings for ICU
> D Mango.icu is a set of wrappers for the D programming language
> Erlang icu4e is a set of bindings for Erlang to ICU4C
> Cobol COBOL A page on how ICU could be used from a COBOL application.
> Go icu4go provides a Go binding for the icu4c library
> Haskell Data.Text.ICU Haskell bindings for ICU4C.
> Lua ICU-Lua ICU for the Lua language
> Pascal ICU4PAS An Object Pascal wrapper around ICU4C.
> Perl PICU Perl wrapper for ICU
> PHP PHP intl A PHP wrapper around core ICU4C APIs.
> Python PyICU A Python extension wrapper around ICU4C.
> R stringi An R language wrapper of for ICU4C.
> Ruby icu4r ICU4C binding for MRI ruby.
> Smalltalk VA Smalltalk Wrappers
> Parrot Virtual Machine This is a virtual machine for Perl 6 and other
> various programming languages. ICU4C is used to improve the Unicode
> support.
> PHP The upcoming PHP 6 language is expected to support Unicode through
> ICU4C.
>
> Companies and Organizations using ICU:
>
> ABAS Software, Adobe, Amazon (Kindle), Amdocs, Apache, Appian, Apple,
> Argonne National Laboratory, Avaya, BAE Systems Geospatial
> eXploitation Products, BEA, BluePhoenix Solutions, BMC Software,
> Boost, BroadJump, Business Objects, caris, CERN, CouchDB, Debian
> Linux, Dell, Eclipse, eBay, EMC Corporation, ESRI, Facebook (HHVM),
> Firebird RDBMS, FreeBSD, Gentoo Linux, Google, GroundWork Open Source,
> GTK+, Harman/Becker Automotive Systems GmbH, HP, Hyperion, IBM,
> Inktomi, Innodata Isogen, Informatica, Intel, Interlogics, IONA, IXOS,
> Jikes, Library of Congress, LibreOffice, Mathworks, Microsoft,
> Mozilla, Netezza, Node.js, Oracle (Solaris, Java), Lawson Software,
> Leica Geosystems GIS & Mapping LLC, Mandrake Linux, OCLC, Progress
> Software, Python, QNX, Rogue Wave, SAP, SIL, SPSS, Software AG, SuSE,
> Sybase, Symantec, Teradata (NCR), ToolAware, Trend Micro, Virage,
> webMethods, Wine, WMS Gaming, XyEnterprise, Yahoo!, Vuo, and 

Re: How to I modify what is a new line in lines?

2020-08-30 Thread Brad Gilbert
$file.IO.lines( :nl-in(…), :chomp, … )

is actually short for

$file.IO.open( :nl-in(…), :chomp ).lines( … )

On Sun, Aug 30, 2020 at 10:43 AM yary  wrote:

> You were close!
>
> First, you were looking at the docs for Path's "lines", but you are using
> a string "lines" and those docs say
>
> multi method lines(Str:D: $limit, :$chomp = True)
> multi method lines(Str:D: :$chomp = True)
>
> Files get "nl-in" due to the special case of text files having various
> line endings to tweak.
>
> Strings already have "split" and "comb" for all the flexibility one may
> need there, and what you're playing with is more naturally
> dd $_ for $x.split("\t"); # "a","b", ... removes \t
> dd $_ for $x.split(//); "a\t","b\t", 
>
> Now back to the Path lines, which DOES let you specify line endings
>
> method lines(IO::Path:D: :$chomp = True, :$enc = 'utf8', :$nl-in = ["\x0A"
> , "\r\n"], |c --> Seq:D)
>
> $ cat line0-10.txt
> Line 0
> Line 1
> Line 2
> ...
>
> let's pretend that the letter "i" is a line ending.
> named arguments can be conveniently written colon pairs :-)
>
> my $nl-in="i"; dd $_ for 'line0-10.txt'.IO.lines(:$nl-in)[0..3];
> "L"
> "ne 0\nL"
> "ne 1\nL"
> "ne 2\nL"
>
> How about splitting on either "i" or "\n", and not chomping
>
> my $nl-in=("i","\n"); dd $_ for 'line0-10.txt'.IO.lines(:$nl-in,
> :!chomp)[0..3];
> "Li"
> "ne 0\n"
> "Li"
> "ne 1\n"
>
> To put in line endings without having a variable of the same name as the
> naed arg, use the full form of the colon pair
> dd $_ for 'line0-10.txt'.IO.lines(:nl-in["i","\n"], :!chomp)[0..3];
> "Li"
> "ne 0\n"
> "Li"
> "ne 1\n"
>
>
>
> -y
>
>
> On Sun, Aug 30, 2020 at 2:58 AM ToddAndMargo via perl6-users <
> perl6-us...@perl.org> wrote:
>
>> Hi All,
>>
>> https://docs.raku.org/type/IO::Path#method_lines
>>
>> method lines(IO::Path:D: :$chomp = True, :$enc = 'utf8', :$nl-in =
>> ["\x0A", "\r\n"], |c --> Seq:D)
>>
>> How do I change what lines sees as a new line.  Is it
>> :$nl-in?  A tab in this case.
>>
>> Some of my missteps:
>>
>> $ p6 'my $x="a\tb\tc\td\t"; dd $x; for $x.lines(:!chomp, "\t") {dd $_};'
>> Str $x = "a\tb\tc\td\t"
>>
>>
>> $ p6 'my $x="a\tb\tc\td\t"; dd $x; for $x.lines(:!chomp, :$nl-in =
>> ["\x0A", "\r\n"]) {dd $_};'
>> ===SORRY!=== Error while compiling -e
>> Variable '$nl-in' is not declared
>> at -e:1
>> --> tc\td\t"; dd $x; for $x.lines(:!chomp, :⏏$nl-in = ["\x0A",
>> "\r\n"]) {dd $_};
>>
>> $ p6 'my $x="a\tb\tc\td\t"; dd $x; for $x.lines(:!chomp, :nl-in =
>> ["\x0A", "\r\n"]) {dd $_};'
>> Str $x = "a\tb\tc\td\t"
>> Cannot modify an immutable Pair (nl-in => True)
>>in block  at -e line 1
>>
>>
>> Many thanks,
>> -T
>>
>


Re: lines :$nl-in question

2020-08-30 Thread Brad Gilbert
Invocant is in the dictionary though.

In fact it is from Latin.

Origin & history:
  Derived from in- + vocō ("I call").

Verb:
  I invoke
  I call (by name)

In fact that is pretty close to the same meaning as it is used in the Raku
docs.

It is the object that we are calling (aka invoking) a method on.

On Sat, Aug 29, 2020 at 6:39 PM ToddAndMargo via perl6-users <
perl6-us...@perl.org> wrote:

> On 2020-08-28 23:51, Tobias Boege wrote:
> > On Fri, 28 Aug 2020, ToddAndMargo via perl6-users wrote:
> >> https://docs.raku.org/type/IO::Path#method_lines
> >>
> >> (IO::Path) method lines
> >>
> >> Defined as:
> >>
> >> method lines(IO::Path:D: :$chomp = True, :$enc = 'utf8', :$nl-in =
> ["\x0A", "\r\n"], |c --> Seq:D)
> >>
> >> Opens the invocant and returns its lines.
> >>
> >> The behavior is equivalent to opening the file specified
> >> by the invocant, forwarding the :$chomp, :$enc,
> >> and :$nl-in arguments to IO::Handle.open, then calling
> >> IO::Handle.lines on that handle, forwarding any of the
> >> remaining arguments to that method, and returning the
> >> resultant Seq.
> >>
> >> And if I am not pushing it, what is `|c`?
> >>
> >> [...]
> >> I do not understand
> >
> > The description of this method says that it shall do two things:
> >
> >- open the invocant path (IIRC you like to use the phrase
> >  "what is fed into it" instead of "invocant")
>
> What ???  Okay, you know me.
>
> You do realize "invocant" is not even in the dictionary
> (esoteric or requiring special knowledge)?
>
>   “Anyone who can only think of one way to spell a
>   word obviously lacks imagination.”
>  -- Mark Twain
>
> I do have to look at it twice when I see it, but I do figure
> it out.  So is okay with me.
>
> > which returns
> >  an IO::Handle,
> >
> >- then call the lines method on this IO::Handle, resulting
> >  in a sequence of lines (Seq in Raku), and it should return
> >  this same Seq value.
> >
> > The lines method on an IO::Path does the same as the lines method on an
> > IO::Handle, except that it has to open the path before to get a handle.
> >
> > The arguments to the IO::Path.lines method therefore split into two
> groups:
> >
> >- :$chomp, :$enc, :$nl-in which are passed on to the open call
> >  in the first bullet point above,
> >
> >- all the remaining arguments, whatever they are, are *captured*
> >  by the syntax |c and will be forwarded to the IO::Handle.lines
> >  call in the second bullet point above.
> >
> > The |c is a so-called capture parameter [1]. It is used in a signature
> > (what you stubbornly call "cryptogram") when a method wants to inspect
> > some (or none) of the arguments it got but keep all the others in a
> > black box, named c here. The capture black box allows forwarding these
> > extra arguments to some other call. The point is that the IO::Path.lines
> > method does not need to know which arguments the target IO::Handle.lines
> > method accepts. It only needs to take everything in and pass it on.
> >
> > It follows that you read about the meaning of the individual arguments or
> > which arguments it makes sense to pass to IO::Path.lines in the
> documentation
> > pages for the IO::Handle.open and IO::Handle.lines methods, which are
> linked
> > to in the text. Really, everything that IO::Path.lines does is
> redistribute
> > its arguments to two other method calls.
> >
> > The documentation of lines does not tell you that |c is a capture
> parameter,
> > but it described what it is used for with the slide-in
> >
> >[...] forwarding any of the remaining arguments to that method [...]
> >
> > in the paragraph you quoted. The connection of that slide-in with the
> > "|c thing" is a matter of text comprehension.
> >
> > Best,
> > Tobias
> >
> > [1] https://docs.raku.org/type/Signature#Capture_parameters
> >
>
> Hi Tobias,
>
> That was a wonderful explanation.  I am writing it down!
> Thank you!
>
> -T
>
> I will probably forget the term "Signature" several more
> times.  :'(
>


Re: lines :$nl-in question

2020-08-30 Thread Brad Gilbert
There are no variables that begin with :

There are variable declarations in signatures that begin with :

:$foo is exactly the same as :foo($foo)

sub bar ( :$foo ) {…}
sub bar ( :foo($foo) ){…}

:$foo in a signature is a shortcut for declaring a named argument :foo()
and a variable with the same base name $foo

:$foo also does the same thing as an argument

my $foo = 1;

bar( :$foo )
bar( :foo($foo) )
bar( foo => $foo )

Note that forms with : can be outside of the signature

bar( ) :$foo
bar( ) :foo($foo)

On Sat, Aug 29, 2020 at 9:05 PM ToddAndMargo via perl6-users <
perl6-us...@perl.org> wrote:

> On 2020-08-29 17:04, ToddAndMargo via perl6-users wrote:
> > On 2020-08-28 23:51, Tobias Boege wrote:
> >>- :$chomp, :$enc, :$nl-in which are passed on to the open call
> >>  in the first bullet point above,
> >
> > Hi Tobias,
> >
> > I am in process of revising my keeper on lines.
> > May I talk you out of examples of the syntax used
> > by :$chomp, :$enc, and :$nl-in?
> >
> > Many thanks,
> > -T
>
> And if you would not mind, what is the official name
> of variables that begin with ":"
>


Re: Raku User's Survey 2020 out now....

2020-08-28 Thread Brad Gilbert
Daniel, the thing about Todd is that his brain doesn't process the written
word the way most people do.
That is according to him by the way.

He is under the assumption that it is because of how he was taught to read.
I think the issue is different.

I think that he might be on the Autistic Spectrum like me. (And possibly
Larry Wall himself.)

The thing about Autistics is that their brains can be very different to
Allistic people.

I am not saying that is bad, only different.

Parts of their brain can be more developed at the expense of other parts of
the brain.
That can mean that they have to use other parts of their brain to
compensate for the underdeveloped parts.

For example there is a woman on YouTube that processes language by thinking
in pictures.
Which can mean that she has difficulty remembering exactly what was said or
written.

If she heard the sentence “He took his dog for a walk”, she might picture
the Gorton's Fisherman taking a beagle for a walk.
So then if you asked her to repeat the sentence she might say something
almost completely different.

Anyway the problem is that Raku was designed by a linguist. So if you have
difficulties with linguistic content you might be very confused.
Again, according to Todd, he has difficulty with the linguistic content of
the written word.

I think that for me both the language and visual centers are overly
expressed and highly connected so Raku is very easy for me.
I often don't have to read the descriptions of the functions at all. Just
the names and function signature is enough for me to figure it out.

So something like his keepers would be completely pointless for me.
Todd however needs those keepers to compensate for how his brain works
differently.

Again, I am not saying that is bad, only different.

---

Now with all of that said, it is little wonder why Todd has difficulties
with the function descriptions where others don't.

I also think that if we just replaced what we have for something that works
for Todd it might make it more difficult for others.
Again because his brain is more unique than most.

What we could do is try to include things from both groups.

We want to be an inclusive community after all.
There is a reason our mascot was designed to be appealing to youngsters.

On Thu, Aug 27, 2020 at 6:59 PM Daniel Long Sockwell <
dan...@codesections.com> wrote:

>
> Hi Todd,
>
> Thanks for your detailed reply; it really helped me to understand your
> perspective on all this.  I have a few responses to particular points
> you raise
>
> > My perspective on Raku's docs are that they are meant
> > as a refresher for those that already know what they
> > are doing.
>
> My perspective is _very_ different.  I first started programming Raku
> less than two months ago.  In that time, I've learned almost entirely
> from the official docs (supplemented by some of the wonderful Advent
> blog posts, the occasional Stack Overflow question, and some truly kind
> people answering questions on IRC – but I didn't buy any books and, like
> you, have had the official docs open nearly contentiously as I
> programmed Raku).  Throughout that learning process, I found the docs
> helpful and informative. Even when I wasn't all that familiar with Raku,
> I could follow the docs -- I didn't grasp *everything* when I was just
> getting started, of course, but I learned enough to keep going.  And, as
> I did, I was able to dive into some of the more obscure corners of the
> docs and learn a tremendous amount.
>
> >[They seem to have the attitude that]
> >"If you don't understand the Docs, it is because
> >you don't know what you are doing."
>
> I 100% agree with you that "if you don't understand the docs, it's
> because you don't know what you are doing" isn't a good approach to
> take.  All I can say is that I _never_ got the sense that anyone
> involved in Raku's docs had that attitude, and I found the docs
> refreshingly easy to understand -- even when I was brand new to Raku.
> >
> > Lets go to operator classification:
> > https://docs.raku.org/languag/operators#Operator_classification
> >
> > "Operators are just subroutines with funny names. The
> > funny names are composed of the category name (infix,
> > prefix, postfix, circumfix, postcircumfix), followed
> > by a colon, and a list of the operator name or names
> > (two components in the case of circumfix and
> > postcircumfix). A expanded explanation of all these
> > operators and what they mean is included in this table:
> > https://docs.raku.org/language/operators#Operator_classification;
> >
> > Okay, "funny names" means they are "esoteric"
> > https://www.wordnik.com/words/esoteric
> >
> > adjective: Intended for or understood by only a small
> > group, especially one with specialized knowledge
>
> A few thoughts on this example.  First, it appears to be from an older
> version of the documentation: the current
> docs.raku.org/language/operators 

Re: Associative class for any key, any value

2020-08-26 Thread Brad Gilbert
On Wed, Aug 26, 2020 at 9:56 PM yary  wrote:

> Map and its descendants like Hash relate "from *string* keys to values of
> *arbitrary* types"
> QuantHash and its descendants like Mix, Bag, Set "provide *object* hashes
> whose values are *limited* in some way"
>
> Is there an associative class where both the keys and values are arbitrary?
>

Hash[Any,Any]

my Any %h{ Any }


Re: Extended identifiers in named attributes

2020-08-26 Thread Brad Gilbert
The problem is that often adverbs are chained without a comma.

my %h = (a => 1);

%h{'a'}:exists:delete # True
say %h.keys; # ()

---

my %h = (a => 1);

postcircumfix:< { } >( %h{'a'}, :exists:delete ) # True
say %h.keys; # ()

On Wed, Aug 26, 2020 at 7:31 AM Marcel Timmerman  wrote:

> Hi everyone,
>
> I was experimenting with extended identifiers and found that it is not
> possible to use it in named attributes. E.g.
>
> > sub a (:$x:y) { say $x:y; }
> ===SORRY!=== Error while compiling:
> Unsupported use of y///.  In Raku please use: tr///.
> --> sub a (:$x:y⏏) { say $x:y; }
>
>
> > sub a (:$abc:def) { say $abc:def; }
> ===SORRY!=== Error while compiling:
> Invalid typename 'def' in parameter declaration.
> --> sub a (:$abc:def⏏) { say $abc:def; }
>
>
> Is there a trick of some sort to get this done? At the moment I can only
> use a slurpy hash and check for its keys. This is good enough for me but
> out of curiosity I ask. If not possible, an extra note in the documentation
> on named arguments would be necessary.
>
> regards,
> Marcel
>
>
>


Re: 2020.07 just hit

2020-08-01 Thread Brad Gilbert
There doesn't need to be an ASCII equivalent of ≢, because you can combine
(==) with the ! metaop to come up with !(==)

On Sat, Aug 1, 2020 at 4:58 PM yary  wrote:

> For every Unicode operator, there's a "Texas" ASCII equivalent
> (==) for  ≡
> but... none that I can find for ≢
> is this an oversight or am I not finding it?
>
> -y
> On Wed, Jul 22, 2020 at 3:06 PM Aureliano Guedes <
> guedes.aureli...@gmail.com> wrote:
>
>> Nice, Daniel,
>>
>> But, I admit, sometimes I don't like too much some symbols not too
>> intuitive to do on the keyboard like  ≡ and ≢
>>
>> Here, I see a lot of codes with weirdo symbols and I need to search how
>> to do. Anyway, the operator itself seems nice.
>>
>> On Wed, Jul 22, 2020 at 12:42 AM  wrote:
>>
>>> > $ raku --version
>>> > This is Rakudo version 2020.07 built on MoarVM version 2020.07
>>> > implementing Raku 6.d.
>>> > Whats is new??
>>>
>>> Release notes are at
>>> https://github.com/rakudo/rakudo/blob/master/docs/announce/2020.07.md
>>>
>>> I'm most excited for new the Unicode operators, ≡ and ≢ (though the
>>> permutations speedup
>>> is pretty cool too).
>>>
>>
>>
>> --
>> Aureliano Guedes
>> skype: aureliano.guedes
>> contato:  (11) 94292-6110
>> whatsapp +5511942926110
>>
>


Re: Learning the "ff" (flipflop) infix operator? (was Re: Raku version of "The top 10 tricks... .")

2020-07-28 Thread Brad Gilbert
A regex doesn't have to match the entire string.

'abcd' ~~ / bc /
# 「bc」

A string has to match exactly with the smart-match. (`ff` and `fff` do
smart-match)

'abcd' ~~ 'bc' # False
'abcd' ~~ 'abcd' # True

A string inside of a regex only makes that a single atom, it does not make
it match like just a string.

'abcd' ~~ / 'bc' /
# 「bc」

 'aBaBaB' ~~ / aB+ /
「aB」

 'aBaBaB' ~~ / "aB"+ /
「aBaBaB」

In fact a string inside of a regex doesn't do much more than square
brackets.

 'aBaBaB' ~~ / [aB]+ /
「aBaBaB」

If you want the regex to match fully, add a beginning of string and end of
string marker.

'abcd' ~~ / ^ bc $ /
# Nil

'abcd' ~~ / ^ abcd $ /
# 「abcd」

---

Since `ff` can begin and end at the same time, the following is turning on
and off at almost every iteration of the loop after it starts.

$ raku -ne '.put if /star {print q[on ]}/ ff /start {print q[off ]}/ ;'
startling.txt
on star
on off start
on off startl
on off startli
on off startlin
on off startling

On Tue, Jul 28, 2020 at 1:43 PM William Michels 
wrote:

> Thank you, Brad and Larry, for explaining the "ff" and "fff" infix
> operators in Raku to me!
>
> I have to admit that I'm still fuzzy on the particulars between "ff"
> and "fff", since I am not familiar with the sed function. I can
> certainly understand how useful these functions could be to 'pull out
> all PGP signatures' from a file (which was the Perl5 example given in
> the Oracle Linux Blog). So I can now  pull out the html "head" section
> from the page _ https://raku.org/fun/ _ (saved locally as file
> "fun.txt") using the following Raku code:
>
> user@mbook:~$ raku -ne '.put if Q[] ff Q[]' fun.txt
> 
> 
> 
> 
> Raku is optimized for fun!
>
>
> 
> 
> 
> 
>
> 
> user@mbook:~$
>
> What I'm less clear on is how the code below is functioning. I first
> print out file named "startling.txt" with 'cat':  it's supposed to
> stand in for a text delimited linewise by "header 1", "header 2", etc.
> After the 'cat' example, I show three examples with Perl(v5.26.3) and
> three examples with Raku(2020.06), generally comparing literal vs
> regex arguments.
>
> The first two Perl5 examples returns nothing; the third Perl5 example
> returns everything after the "star" line. For the Raku code, the
> 'DWIMmiest' output below is the first Raku example, which returns two
> lines, "star" and "start". This is what I expected/desired. But I'm
> not really understanding what's happening with the other 2 Raku
> examples (which return everything after the "star" line):
>
> user@mbook:~$ cat startling.txt
> s
> st
> sta
> star
> start
> startl
> startli
> startlin
> startling
>
> user@mbook:~$ perl -nE 'print if "star" .. "start" ;' startling.txt
> user@mbook:~$ perl -nE 'print if /"star"/ .. /"start"/ ;' startling.txt
> user@mbook:~$ perl -nE 'print if /star/ .. /start/ ;' startling.txt
> star
> start
> startl
> startli
> startlin
> startling
> user@mbook:~$ raku -ne '.put if "star" ff "start" ;' startling.txt
> star
> start
> user@mbook:~$ raku -ne '.put if /"star"/ ff /"start"/ ;' startling.txt
> star
> start
> startl
> startli
> startlin
> startling
> user@mbook:~$ raku -ne '.put if /star/ ff /start/ ;' startling.txt
> star
> start
> startl
> startli
> startlin
> startling
> user@mbook:~$
>
> I'm all in favor of improving the "ff" and "fff" functions in Raku
> over their Perl5 counterparts, but I'm hoping to gain a better
> (mnemonic?) way of remembering the expected return values with literal
> vs regex arguments.
>
> Any assistance appreciated, Bill.
>
>
>
>
>
>
> On Sun, Jul 26, 2020 at 10:04 AM Larry Wall  wrote:
> >
> > On Sat, Jul 25, 2020 at 04:32:02PM -0500, Brad Gilbert wrote:
> > : In the above two cases ff and fff would behave identically.
> > :
> > : The difference shines when the beginning marker can look like the end
> > : marker.
> >
> > The way I think of it is this:  You come to the end of "ff" sooner, so
> you
> > do the end test immediately after passing the start test.  You come to
> the
> > end of "fff" later, so the end test is delayed to the next iteration from
> > the start test.  (Same mnemonic for .. and ... in Perl, by the way, since
> > ff and fff were modeled on .. and ... (in their scalar form), but we
> stole
> > .. and ... in Raku for ranges and sequences so we needed something else.)
> >
> > I suppose if you're musical you can come up with mnemonics based on "fff"
> > being louder than "ff", so it echoes longer before it stops...  :)
> >
> > Larry
>


Re: Learning the "ff" (flipflop) infix operator? (was Re: Raku version of "The top 10 tricks... .")

2020-07-25 Thread Brad Gilbert
There's the ff operator and the fff operator.

The ff operator allows both endpoints to match at the same time.
The fff operator doesn't.

On Sat, Jul 25, 2020 at 3:16 PM William Michels via perl6-users <
perl6-us...@perl.org> wrote:

> Hello,
>
> I'm trying to learn the "ff" (flipflop) infix operator, generally
> taking examples from the docs (below):
>
> https://docs.raku.org/routine/ff
>
> I tried adding in an "m:1st" adverb and an "m:2nd" adverb, but the
> output isn't what I expect with the "m:2nd" adverb (examples #3 and
> #5):
>
> say "\n1. ";
> for  {
> say $_ if /A/ ff /B/;  # OUTPUT: «AB␤»
> }
>

You should probably use the fff operator instead

for  {
say $_ if /A/ fff /B/;  # OUTPUT: «AB␤C␤D␤B␤»
}


> say "\n2. ";
> #mine
> for  {
> say $_ if /A/ ff m:1st/B/;  # OUTPUT: «AB␤»
> }
>

I don't know why you would think that :1st would work that way.
:1st doesn't really do anything.
It makes it so that it matches at the first occurrence, which is the
default anyway.

'ABcdeFB' ~~ m:1st/.B/; # 「AB」
'ABcdeFB' ~~ m:2nd/.B/; # 「FB」

The /.B/ can match in two different places in the string, :1st makes it so
that it matches the first occurrence.
:2nd makes it match the second occurence.

At any rate it doesn't do anything special when used as part of a ff
operator.

If you wanted the 'B' to match at the first position, you need to indicate
that.
Generally you would use `^` for beginning of string.

say $_ if /A/ ff /^B/; # OUTPUT: «AB␤C␤D␤B␤»


> say "\n3. ";
> #mine
> for  {
> say $_ if /A/ ff m:2nd/B/;  # OUTPUT: «AB␤C␤D␤B␤E␤F␤»
> }


None of those strings can match 'B' more than once, so m:2nd/B/ will always
fail.
Which means that the ff operator will not stop.


> say "\n4. ";
> for  {
> say $_ if /C/ ff *;# OUTPUT: «C␤D␤B␤E␤F␤»
> }
>

Generally * matches everything.
In this case if it is on the right side of ff, it actually means don't stop.
(If it were on the left it would mean always start)

say "\n5. ";
> #mine
> for  {
> say $_ if m:2nd/B/ ff *;# OUTPUT: blank
> }
>

Again there is nothing for :2nd to match, so it never does.

I'm wondering if I'm using the correct "flipflop" operator, since
> "ff", "ff^", "fff", and "fff^" are all provided in Raku.
>

I will say that fff is slightly easier to understand, but your real failure
to understand seems to be with :2nd.


Anyway it is intended to be more like:

for < A B start C D E F end G H I J start K L M N O end P Q R S T U V W
X Y Z > {
  .say if "start" fff "end";
}
start
C
D
E
F
end
start
K
L
M
N
O
end

If you want to ignore the "start" you can use ^fff
If you want to ignore the "end" you can use fff^
If you want to ignore both use ^fff^

Same for ff  ( ^ff  ff^  ^ff^ )
And for .. ( ^..  ..^  ^..^ )

for < A B start C D E F end G H I J start K L M N O end P Q R S T U V W
X Y Z > {
  .say if "start" ^fff^ "end";
}
C
D
E
F
K
L
M
N
O

In the above two cases ff and fff would behave identically.

The difference shines when the beginning marker can look like the end
marker.

for 1..20 {
  .say if * %% 3 ff * %% 3
}
3 # matches both endpoints
6 # ditto
9
12
15
18

for 1..20 {
.say if * %% 3 fff * %% 3
}
3 # matches beginning (left)
4
5
6 # matches ending (right)
9 # begin
10
11
12 # end
15 # begin
16
17
18 # end


Re: perl streaming framework

2020-07-14 Thread Brad Gilbert
If you really want a streaming framework for Perl, the mailing list for
Raku users might not be the best place to ask.
(Raku used to be known as Perl6, and we haven't done anything to change the
name of this mailing list.)

Raku has a very similar syntax to Perl. (It used to be called Perl6 after
all.)
But it is different enough that it would take experience Perl programmers a
while to get used to.
(It might actually be easier for Perl novices to get used to it.)

It would probably be a better idea to go to a place that Perl programmers
frequent.
PerlMonks might be a good starting place.

On Tue, Jul 14, 2020 at 3:55 AM Warren Pang  wrote:

> Hello
>
> We are already using perl PDL and something similar.
> The streaming framework is mainly used for real time data analysis.
> Tyler from Apache Beam project has wrote a great book about streaming
> system:
> http://streamingsystems.net/
> So I have interest to know if there is the perl implementation for that.
>
> Thank you.
>
>
>
> On Tue, Jul 14, 2020 at 3:39 PM Shlomi Fish 
> wrote:
>
>> Hi Warren!
>>
>> Please reply to list.
>>
>> On Tue, 14 Jul 2020 10:34:57 +0800
>> Warren Pang  wrote:
>>
>> > Hi
>> >
>> > Does perl have a stream computing framework?
>> > I know Java/python have many, such as spark, flink, beam etc.
>> > But I am looking for a perl alternative, since most of our team members
>> > have been using perl for data analysis.
>> >
>>
>> 1. Do you want one for Raku which was formerly known as "Perl 6" (see
>> https://en.wikipedia.org/wiki/Raku_(programming_language) ) or for "perl
>> 5"?
>>
>> 2. What do you mean by "stream computing framework"? Is there a
>> wikipedia/etc.
>> page for them?
>>
>> 3. Can you link to some examples?
>>
>> 4. Do you mean something like http://pdl.perl.org/ (or numpy for python)?
>>
>>
>> > Thank you.
>>
>>
>>
>> --
>>
>> Shlomi Fish   https://www.shlomifish.org/
>> Why I Love Perl - https://shlom.in/joy-of-perl
>>
>> The reason the Messiah has not come yet, is because Chuck Norris keeps
>> finding
>> faults in God’s plan for his coming.
>> — https://www.shlomifish.org/humour/bits/facts/Chuck-Norris/
>>
>> Please reply to list if it's a mailing list post - https://shlom.in/reply
>> .
>>
>


Re: cannot create an instance of subset type

2020-07-10 Thread Brad Gilbert
Subset types are not object types.

A subset is basically a bit of checking code and base type associated with
a new type name.

In something like:

my ABC $a .= new;

That is exactly the same as:

my ABC $a = ABC.new;

Well there is no functional `.new` method on any subset types, so
`DEF.new()` isn't going to do anything.

DEF.new # ERROR

---

The worst part of your code is that you are using a `subset` without a
`where` clause. Which is almost completely pointless.

I honestly think that there is an argument to be made that it shouldn't
even be possible to write a `subset` without a `where` clause.

It isn't like other languages where you can create something like a
lightweight clone or lightweight subclass of a type.
It also isn't an alias.

It's whole purpose is to attach a `where` clause as an extra check to type
based things.



If you want an alias, use an alias

my constant DEF = ABC;

my constant DEF = ABC:D;

If you want a lightweight subclass, create a lightweight subclass.

my class DEF is ABC {}

If you want an extra check, then and only then does it make sense to use a
`subset`.

my subset GHI of Int where -10 ≤ $_ ≤ 10;

---

A `subset` without a `where` clause only makes certain language features
become unavailable.
Unless that is exactly what you want to accomplish, use something else.

On Fri, Jul 10, 2020 at 3:18 PM Marcel Timmerman  wrote:

> Hi,
>
> Using the next code I get an error on the instantiation of $d2;
>
> ---
> use v6;
>
> class ABC {
>method s ( Int $i ) { say $i + 10; }
> }
>
> subset DEF of ABC;
>
> my ABC $a .= new;
> $a.s(10);   # 20
>
> my DEF $d1 = $a;
> $d1.s(11);  # 21
>
> my DEF $d2 .= new;
> $d2.s(12);
> ---
>
> Error is
>
> You cannot create an instance of this type (DEF)
>in block  at xt/subset-test.pl6 line 15
>
> Why is this?
>
> Regards,
> Marcel
>


Re: an error I don't understand

2020-06-27 Thread Brad Gilbert
I don't know why you are getting an error.

But I think that this is one case where you should be writing `BUILD`
instead of `TWEAK`.
Note though that you can only have one `BUILD` or `TWEAK` per class.

---

Or maybe you want a multi method `new` instead?

multi method new ( :$native-object! ) {
samewith( x => $native-object.x, y => $native-object.y )
}

Assuming that `x` and `y` are actually public attributes you could pull
them out of the object in the signature.

multi method new ( :$native-object! (:$x, :$y) ) {
samewith( :$x, :$y )
}

If you need to throw out other public attributes, add `*%`

multi method new ( :$native-object! (:$x, :$y, *%) ) {
samewith( :$x, :$y )
}

---

Honestly I do not understand why you are passing in an already constructed
object, and I don't know anything about it either.

If you gave us answers for those two questions, we may be able to help you
better.


On Sat, Jun 27, 2020 at 10:56 AM Marcel Timmerman  wrote:

> Hi,
>
> I am getting an error and don't know why it happens, it might even be a
> bug. It is about an assignment to a CStruct variable.
>
> The structure is defined like;
>
> class cairo_path_data_point_t is repr('CStruct') is export {
>has num64 $.x;
>has num64 $.y;
>
>submethod TWEAK ( :$native-object ) {
>  $!x = $native-object.x;
>  $!y = $native-object.y;
>}
> }
>
>
> The error is generated when typed variables are used (below, $x is also
> a cairo_path_data_point_t);
>
> my cairo_path_data_point_t $p1 = $x;
>
> or
>
> my cairo_path_data_point_t $p1 =
> cairo_path_data_point_t.new(:native-object($x));
>
> but not with
>
> my cairo_path_data_point_t $p1 .= new(:native-object($x));
>
> or
>
> my $p1 = $x;
>
> After which all fields in the structure are happely accessable using $p1!
>
>
> The error is
>
> Type check failed in assignment to $p1; expected cairo_path_data_point_t
> but got cairo_path_data_point_t.new(x => 0e0, y => 0e0)
>
>
> Raku version: 2020.06-7-gf1960baa9 built on MoarVM version
> 2020.06-6-gbf6af07de
> implementing Raku 6.d.
>
> The content of the structure does not matter, I've seen it with other
> structures too.
>
> Regards,
> Marcel
>


Re: Playing with protos and phasers

2020-06-25 Thread Brad Gilbert
While {*} is only useful in a proto, the compiler detects it no matter
where you write it.

> my $block = {*};
===SORRY!=== Error while compiling:
{*} may only appear in proto
at line 2
--> ⏏

On Thu, Jun 25, 2020 at 3:48 PM Fernando Santagata <
nando.santag...@gmail.com> wrote:

> On Thu, Jun 25, 2020 at 8:10 PM Brad Gilbert  wrote:
>
>> {*} is specially handled by the compiler as a term.
>>
>
> Thank you!
>
> I guess that handling is peculiar to proto, and maybe it's worth
> documenting it.
>
> --
> Fernando Santagata
>


Re: Playing with protos and phasers

2020-06-25 Thread Brad Gilbert
{*} is specially handled by the compiler as a term.

Let's say you have a class named Foo:

class Foo {…}

You wouldn't expect to be able to use it like this:

F o o.new()

It is the same thing with {*}.
The only difference is that {*} is meant to look like a Block { } combined
with a Whatever *.
It was meant to be both visually distinctive, and visually similar to how
you might think about it.

---

If you were allowed to add spaces to the {*} term, it would be annoying if
you wanted to create a lambda that returned a Whatever.

my $block = { * };

say $block.() ~~ Whatever; # True.

On Thu, Jun 25, 2020 at 2:47 AM Fernando Santagata <
nando.santag...@gmail.com> wrote:

> Hi *,
> I was trying to see if one can delegate phasers to a proto, like this:
>
> proto sub foo(|) {
>   ENTER { say 'In' }
>   LEAVE { say 'Out' }
>   {*}
> }
> multi sub foo(Int $a) {
>   $a
> }
> multi sub foo(Str $a) {
>   $a
> }
>
> say foo(1);
> say foo('hello');
>
> Yes indeed, it outputs:
>
> In
> Out
> 1
> In
> Out
> hello
>
> But at first it didn't work, because I added a space on both sides of the
> '*':
>
> proto sub foo(|) {
>   ENTER { say 'In' }
>   LEAVE { say 'Out' }
>   { * }
> }
>
> It outputs:
>
> In
> Out
> *
> In
> Out
> *
>
> If I add a return:
>
> proto sub foo(|) {
>   ENTER { say 'In' }
>   LEAVE { say 'Out' }
>   return { * }
> }
>
> it outputs:
>
> In
> Out
> -> ;; $_? is raw = OUTER::<$_> { #`(Block|94038346387904) ... }
> In
> Out
> -> ;; $_? is raw = OUTER::<$_> { #`(Block|94038346388120) ... }
>
> Why are spaces significant in this case?
>
> If this behavior is intentional, can this be a trap worth being documented?
>
> --
> Fernando Santagata
>


Re: junctions and parenthesis

2020-06-24 Thread Brad Gilbert
It does actually make sense to call any on any

say (1, 2, 3).any + (4, 5, 6).any
# any(any(5, 6, 7), any(6, 7, 8), any(7, 8, 9))

On Wed, Jun 24, 2020 at 6:22 PM William Michels via perl6-users <
perl6-us...@perl.org> wrote:

> I evaluated Joe's code using Patrick's explanation of parentheses-less
> parsing (in the REPL):
>
> > say(so(any( eq any(;
> False
> > say any( eq any());
> any(any(False, False))
> >
>
> Q1. Does it make any sense to call "any" on "any" (i.e. nested "any"
> calls)? Could this anti-pattern be used to generate a warning, i.e.
> 'Useless use of nested any-junctions, did you mean...' or something
> similar?
>
> > say any( eq any());
> any(any(False, False))
> > say any( eq any());
> any(any(False, False, False))
> >
>
> Q2. Swapping the first argument  to the binary infix operator
> 'eq' with the second argument  results in two different code
> evaluations (above). Can this be used to alert the user to a potential
> violation of the commutative property of equality? Again, maybe useful
> for generating a warning (at least in the REPL), " Warning:
> Commutativity--code without parentheses evaluates differently based on
> LHS vs RHS ordering of arguments to "eq" operator... ."
>
> (note, the second suggestion won't help if each argument to the "any"
> calls surrounding 'eq' are an equivalent number of elements).
>
> HTH, Bill.
>
>
>
> On Sun, Jun 21, 2020 at 8:12 PM Patrick R. Michaud 
> wrote:
> >
> > The "any" function is just like any other function taking an arbitrary
> list of arguments (including user-defined functions).  As such it parses
> with lower precedence than comparison operators -- so "eq" binds more
> tightly than "any".
> >
> > Thus
> >
> >say so any  eq any ;
> >
> > parses like
> >
> >say(so(any( eq any(;
> >
> > which is indeed False.
> >
> > I'm not exactly sure what sort of warning should go here, or how it'd be
> detected.  But perhaps others have ideas.
> >
> > Pm
> >
> >
> > On Sun, Jun 21, 2020 at 07:00:23PM -0700, Joseph Brenner wrote:
> > > I was just playing around with junctions a bit today, and I
> > > noticed that if you weren't religious about using parenthesis
> > > with them you could get quietly tripped up:
> > >
> > > say so any() eq any();   # True   (as expected)
> > > say so any() eq any(); # False  (as expected)
> > > say so any  eq any ; # False(something's wrong)
> > >
> > > Basically, you need the parens on that first use of any.
> > >
> > > Is there a reason you don't at least get a warning if you don't?
>


Re: interpolating the return from embedded code in a regexp

2020-06-15 Thread Brad Gilbert
You don't want to use <{…}>, you want to use ""

if $line ~~ / (^P\d+) \s+ {} "%products{$0}" / {

Note that {} is there to update $/ so that $0 works the way you would expect

Although I would do something like this instead:

my ($code,$desc) = $line.split( /\s+/, 2 );
if %products{$code} eq $desc {

On Sun, Jun 14, 2020 at 6:44 PM Joseph Brenner  wrote:

> In part because of the recent discussion here, I decided to
> play around with using Raku code embedded in a regexp.
> I came up with a contrived example where I was going to
> examine a product listing in a text block to see if the product
> descriptions matched the product codes.  The valid associations
> I have in a hash, so I'm (1) matching for product codes; (2)
> using embedded code to look-up the associated description in the hash;
> (3) using the returned description inside the regex.
>
> my %products = ( 'P123' => "Green Labels That Say Magenta",
>  'P666' => 'Darkseid For President Bumpersticker',
>  'P912' => "Corn dogs",
>  );
>
> my $text =  q:to/END/;
> P123  Viridian Green Label Saying Magenta
> P666  Yoda puppets
> P912  Corn dogs
> END
>
> my @lines = $text.lines;
> say @lines;
>
> for @lines -> $line {
>say "checking line: $line";
>## This line works, but it's not a complete solution:
>if $line ~~ / (^P\d+) \s+ <{ %products{$0}.subst(/\s+/, '\s', :g) }> / {
>say "Matched, line looks good";
>}
>else {
>say "NO: bad line.";
>}
> }
>
> I'd thought that a line like this would work:
>
> if $line ~~ / (^P\d+) \s+ <{ %products{$0} }> / {
>
> The trouble though is I've got spaces inside the descriptions,
> so if the returned string is treated as a regexp, I get these
> warnings:
>
>Potential difficulties:
>Space is not significant here; please use quotes or :s
> (:sigspace) modifier (or, to suppress this warning, omit the space, or
> otherwise change the spacing)
>
> Reading a bit, I thought this should work
>
> if $line ~~ / (^P\d+) \s+ $( %products{$0} ) / {
>
> That's supposed to use the return string as a literal match.
> Instead I get a lot of strange messages like:
>
>Use of Nil in string context   in regex
>
> Flailing around I considered lots of variations like this:
>
>if $line ~~ / (^P\d+) \s+ Q[<{ %products{$0}}>] / {
>
> But I think that ends up treating everything inside the Q[]
> literally, so you never do the hash lookup.
>
> Another thing that might solve this problem is some sort of
> regexp quote function I could use inside the code before
> returning the string, but I don't know what that would be...
>


Re: regex interpolation of array

2020-06-13 Thread Brad Gilbert
On Sat, Jun 13, 2020 at 1:27 PM Sean McAfee  wrote:

> On Sat, Jun 13, 2020 at 10:21 AM Brad Gilbert  wrote:
>
>> That was just a dumb example.
>> An incredibly dumb example.
>>
>> So what happens is that `Bool.pick` chooses The Bool values of either
>> `True` or `False`.
>> It does this at every position in the string.
>>
>> 'TrueFalse' ~~ / <{ Bool.pick }>
>>
>
> I saw this and figured that maybe a state variable could help:
>
> 'TrueFalse' ~~ /<{ $ //= Bool.pick }>/
>
> ...but it doesn't.  I suppose that means the bracketed code is not
> compiled just once, like an anonymous subroutine, but is fully re-evaluated
> on every match attempt.  Is that the intended behavior?
>

`state` variables act like they were declared in the next outer lexical
scope.

{   {   state $v;  $v++   }   }
{   my $v;   {   $v++   }   }

The next outer lexical scope that we see for `<{ }>` is the regex itself;

/ <{   $   //= Bool.pick   }> /
/ <{  (state $v)  //= Bool.pick }> /

That last one is almost like this:

/ :my $v;  <{  $v //= Bool.pick }> /

Almost.

It really acts like there is a scope defined by the <> and a separate one
defined by the {}.

(This may be just an implementation detail that is leaking out.)

---

At any rate the right way to fix it is to actually run `Bool.pick` exactly
once at the beginning.

/ :my $to-match = ~Bool.pick;  <{ $to-match }> /
/ :my $to-match = ~Bool.pick;  "$to-match" /


Re: regex interpolation of array

2020-06-13 Thread Brad Gilbert
That was just a dumb example.
An incredibly dumb example.

So what happens is that `Bool.pick` chooses The Bool values of either
`True` or `False`.
It does this at every position in the string.

'TrueFalse' ~~ / <{ Bool.pick }>

Let's say that initially `Bool.pick` chooses `False`.
That value then gets temporarily inserted into the regex.
Obviously { "True" ne "False" } so it fails at the first position.

So then the regex tries to match at the second position.
`Bool.pick` gets run again, and picks one of the values.
Neither "True" nor "False" can match here so it doesn't matter which is
chosen.

It keeps doing that until it finally matches or reaches the end of the
string.

Let's take a look at what happens at the fifth position.
We obviously didn't match `True` at the start, because otherwise we would
get this far.
You may be expecting it to match `False` then.
The only thing is that the code inside of <{ }> gets run again.
This time it picks `True`.
{ "True" ne "False" } so it fails again.

It then keeps trying to find a match, only we've gotten so far into the
string that there are no matches left.
So then it just fails.

---

There is a 50% chance that it will return "True" if `Bool.pick` chooses
`True` the first time.
A 25% chance that it will return "False" if it picks `False` at the fifth
position.
And another 25% chance it will fail to match anything.

You can play around with the odds by changing the string your matching
against.
There will always be a chance that it will fail to match though.

On Sat, Jun 13, 2020 at 11:54 AM William Michels 
wrote:

> Hi,
>
> I seem to be having some problems with Brad's code. The 'boolean pick'
> code seems far too clever for me to have intuited it on my own, so
> (to expand my Raku/Perl6 vocabulary), I played around with matching
> extra 'True' or 'False' values--as well as played around with seeing
> if similar 'boolean elems' code would work. However the code (even
> Brad's code) returned 'Nil' with alarming frequency (all code below
> tested in the Raku/Perl6 REPL):
>
> mbook:~ homedir$ perl6
> To exit type 'exit' or '^D'
> > 'TrueFalse' ~~ / <{ Bool.pick }> /
> 「False」
> > 'FalseTrueFalse' ~~ / <{ Bool.pick }> /
> 「False」
> > 'TrueFalseTrue' ~~ / <{ Bool.pick }> /
> Nil
> > 'TrueFalseTrue' ~~ / <{ Bool.elems }> /
> Nil
> > 'TrueFalse' ~~ / <{ Bool.elems }> /
> Nil
> > 'TrueFalse' ~~ / <{ Bool.pick }> /
> Nil
> > 'TrueFalse' ~~ / <{ Bool }> /
> Cannot resolve caller INTERPOLATE_ASSERTION(Match:D: Bool:U, BOOTInt,
> BOOTInt, BOOTInt, BOOTInt, PseudoStash:D); none of these signatures
> match:
> (Match: Associative:D, $, $, $, $, $, *%_)
> (Match: Iterable:D \var, int \im, int \monkey, int \s, $, \context,
> *%_)
> (Match: Mu:D \var, int \im, int \monkey, $, $, \context, *%_)
>   in block  at  line 1
>
> > 'TrueFalse' ~~ / <{ Bool.say }> /
> (Bool)
> > say $*VM
> moar (2020.02.1)
> > exit
> mbook:~ homedir$ perl6 --version
> This is Rakudo version 2020.02.1..1 built on MoarVM version 2020.02.1
> implementing Raku 6.d.
> mbook:~ homedir$
>
> Any help appreciated, Bill.
>
>
> On Sat, Jun 13, 2020 at 6:42 AM Brad Gilbert  wrote:
> >
> > Inside of a regex `{…}` will just run some regular Raku code.
> > Code inside of it will most likely have no effect on what the regex
> matches.
> >
> > What you should have written was:
> >
> > $ = "@W[3]"
> >
> > The thing you were thinking of was:
> >
> > $ = <{ @W[3] }>
> >
> > Which could have been written as:
> >
> > 
> >
> > ---
> >
> > To have the result of regular Raku code have an effect on the match, it
> has to have <…> around it
> >
> > 'TrueFalse' ~~ / <{ Bool.pick }> /
> >
> > I think it is better if you use "…" if you are just interpolating a
> variable, because that is something you might do outside of a regex as well.
> >
> > ---
> >
> > The reason your code matched is that an empty regex always matches.
> >
> > 'abc' ~~ / "" /
> > 'abc' ~~ / {} /
> > 'abc' ~~ / {'def'} / # still an empty regex as far as the regex
> engine is concerned
> >
> > On Sat, Jun 13, 2020 at 5:35 AM Richard Hainsworth <
> rnhainswo...@gmail.com> wrote:
> >>
> >> I was playing with a regex and array interpolation.
> >>
> >> From the documentation I thought the following comparisons would be the
> same, but they are not.
> >>
> >> What am I missing?
> >>
> >> my @W = ;
> >> my $S = 'perlchallengeextrathingswithweeklysome' ; # randomly
> concatenate the words without spaces
> >> say 'yes' if $S ~~ / $=( { @W[3] } ) /;
> >> say $;
> >> my $sol = @W[3]; # with
> >> say 'yes' if $S ~~ / $=( $sol ) /;
> >> say $;
> >>
> >> 
> >> yes
> >> 「」
> >> yes
> >> 「with」
> >>
> >>
> >>
>


Re: regex interpolation of array

2020-06-13 Thread Brad Gilbert
Inside of a regex `{…}` will just run some regular Raku code.
Code inside of it will most likely have no effect on what the regex matches.

What you should have written was:

$ = "@W[3]"

The thing you were thinking of was:

$ = <{ @W[3] }>

Which could have been written as:



---

To have the result of regular Raku code have an effect on the match, it has
to have <…> around it

'TrueFalse' ~~ / <{ Bool.pick }> /

I think it is better if you use "…" if you are just interpolating a
variable, because that is something you might do outside of a regex as well.

---

The reason your code matched is that an empty regex always matches.

'abc' ~~ / "" /
'abc' ~~ / {} /
'abc' ~~ / {'def'} / # still an empty regex as far as the regex engine
is concerned

On Sat, Jun 13, 2020 at 5:35 AM Richard Hainsworth 
wrote:

> I was playing with a regex and array interpolation.
>
> From the documentation I thought the following comparisons would be the
> same, but they are not.
>
> What am I missing?
>
> my @W = ;my $S = 
> 'perlchallengeextrathingswithweeklysome' ; # randomly concatenate the words 
> without spacessay 'yes' if $S ~~ / $=( { @W[3] } ) /;say $;my $sol 
> = @W[3]; # withsay 'yes' if $S ~~ / $=( $sol ) /;say $;
>
> 
> yes
> 「」
> yes
> 「with」
>
>
>
>
>


Re: question about the multi in method

2020-06-07 Thread Brad Gilbert
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

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?
>
> Many thanks,
> -T
>


Re: I need a second pair of eyes

2020-05-27 Thread Brad Gilbert
The point was that 「say」 will print undefined values without complaining.

Really debug statements should be more like:

$*STDERR.put: 「%CommandLine = 」, %CommandLine;

Or more succinctly:

dd %CommandLine;

On Wed, May 27, 2020 at 1:39 AM Peter Pentchev  wrote:

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


Re: I need help testing for Nil

2020-05-26 Thread Brad Gilbert
There are various equality operators.

「==」 Tests for numeric equality
「eq」 Tests for string equality
「===」 Tests for value identity
「=:=」 Tests for pointer equality (Note that it looks a bit like 「:=」)
「eqv」 Tests for structure equivalence.

The 「==」 and 「eq」 operators are special because they force their values to
be numbers or strings before they do anything else.

There are similarly a variety of comparison operators.

On Tue, May 26, 2020 at 5:06 PM ToddAndMargo via perl6-users <
perl6-us...@perl.org> wrote:

> >> On Tue, May 26, 2020 at 4:24 PM ToddAndMargo via perl6-users
> >> mailto:perl6-us...@perl.org>> wrote:
> >>
> >> Hi All,
> >>
> >> How do I turn this:
> >>
> >> $ raku -e 'my $x="abc"; say $x.index( "q" );'
> >> Nil
> >>
> >> into a test?
> >>
> >> $ raku -e 'my $x="abc"; if $x.index( "q" ) eq Nil {say
> "Nil"}else{say
> >> "Exists";}'
> >> Use of Nil in string context
> >> in block  at -e line 1
> >> Use of Nil in string context
> >> in block  at -e line 1
> >> Nil
> >>
> >>
> >> Many thanks,
> >> -T
> >>
>
> On 2020-05-26 15:00, Brad Gilbert wrote:
> > Generally you don't need to test for 「Nil」.
> > You can just test for defined-ness.
>
> True enough
>
> >
> >  $ raku -e 'my $x="abc"; with $x.index( "q" ) {say "Exists"} else
> > {say "Nil";}'
> >
> > Also 「Nil」 is not a 「Str」, so why would you use 「eq」?
>
> Because == did not work
>
>
> >  $ raku -e 'Nil.Str'
> >  Use of Nil in string context
> >
> > If you really need to check specifically for 「Nil」 (which you probably
> > don't), then you can use 「===」.
> >
> >  for Str, Int, Nil {
> >  say 'Nil' if $_ === Nil;
> >  }
> >
> > The 「//」 operator can also be useful to deal with undefined values such
> > as 「Nil」.
> >
> >  my $x = 'abc';
> >  say $x.index('q') // 'cannot find the index of 「q」';
> >
> >
>
> Hi Brad,
>
> Did not know about the triple =
>
> Thank you!
>
> -T
>
>
> $ raku -e 'my $x="abc"; if $x.index( "q" ) === Nil {say "Nil"}else{say
> "Exists";}'
> Nil
>
> $ raku -e 'my $x="abc"; if $x.index( "a" ) === Nil {say "Nil"}else{say
> "Exists";}'
> Exists
>
> And I found buried in my Nil notes that `=:=` works too
>
> $ raku -e 'my $x="abc"; if $x.index( "q" ) =:= Nil {say "Nil"}else{say
> "Exists";}'
> Nil
>
> $ raku -e 'my $x="abc"; if $x.index( "b" ) =:= Nil {say "Nil"}else{say
> "Exists";}'
> Exists
>


Re: Regexps using 'after' and 'before' like ^ and $

2020-05-26 Thread Brad Gilbert
I'm not sure that is the best way to look at 「」 and 「」.

> 'abcd123abcd' ~~ / > .+ > /
「123」

In the above code 「>」 makes sure that the first thing that
「.+」 matches is a 「」
And 「>」 makes sure that the last thing 「.+」 matches is also
a 「」

The 「>」 is written in front of the 「.+」 so it starts at
that position

It does the thing that 「」 would normally do.

' a b c d 1 2 3 a b c d '
' _ _ _ _^1^_ _ _ _ _ _ '

The thing is, 「」 resets the position to what it was immediately
before the successful 「」 match.

' a b c d 1 2 3 a b c d '
' _ _ _ _^_ _ _ _ _ _ _ '

The 「.+」 then tries to grab everything

' a b c d 1 2 3 a b c d '
' _ _ _ _^1 2 3 a b c d^'

Then  「>」 gets to tell it that it can't do that.

The reason is that 「」 looks backwards from the current position. The
current position is at the very end.
It obviously isn't a 「」, so 「.+」 has to keep giving up characters
until its last value is a 「」.

' a b c d 1 2 3 a b c d '
' _ _ _ _^1 2 3^_ _ _ _ '

---

You can use 「」 to check that is at the beginning.

 'abc' ~~ /  b /
 Nil

The reason is that if the current position is anywhere other than the
beginning 「.」 would match.
Since we used 「!」 that won't fly.

「」 should probably also prevent the position from being at the
end.

It does work if you write it differently

'abc' ~~ / b  /
Nil

Note that 「」 and 「」 are really just function calls.

It does seem like there could be a bug here.

---

All of that said, I don't think it is useful to tell new Raku programmers
that you can use those features that way.

It make them think that these two regexes are doing something similar.

/ ^ ... /
/  ... /

They match the same three characters, but for entirely different reasons.

The 「^」 version is basically the same as:

/  ... /

While the other one is something like:

/  ... /

(The 「try」 is needed because 「.substr( -1 )」 is a Failure.)

So then these:

/ ... $ /
/ ... 

Would be

/ ...  /
/ ...  /

---

What I think is happening is that the 「」 works because the
「.substr( -1, 1)」 creates a Failure.

The thing is that 「'abc'.substr( 3, 1 )」 doesn't create a Failure, it just
gives you an empty Str.

(The second argument is the maximum number of characters to return.)

On Mon, May 25, 2020 at 4:10 PM Joseph Brenner  wrote:

> Given this string:
>my $str = "Romp romp ROMP";
>
> We can match just the first or last by using the usual pinning
> features, '^' or '$':
>
>say $str ~~ m:i:g/^romp/;   ## (「Romp」)
>say $str ~~ m:i:g/romp$/;   ## (「ROMP」)
>
> Moritz Lenz (Section 3.8 of 'Parsing', p32) makes the point you
> can use 'after' to do something like '^' pinning:
>
>say $str ~~ m:i:g/  romp /;   ## (「Romp」)
>
> That makes sense:  the BOL is "not after any character"
> So: I wondered if there was a way to use 'before' to do
> something like '$' pinning:
>
>   say $str ~~ m:i:g/ romp  /;  ## (「Romp」 「romp」)
>
> That was unexpected: it filters out the one I was trying to
> match for, though the logic seemed reasonable: the EOL is "not
> before any character".
>
> What if we flip this and do a positive before match?
>
>   say $str ~~ m:i:g/ romp  /;  ## (「Romp」 「romp」)
>
> That does exactly the same thing, but here the logic makes
> sense to me: the first two are "before some character",
> but the last one isn't.
>


Re: I need a second pair of eyes

2020-05-26 Thread Brad Gilbert
This is more of how I would structure it

with %CommandLine {
.say;
# if /^ '['  .*? ']' / {
   if .starts-with('[') && .contains(']') {
...
}
} else {
say 'no backup path given'
}

We can skip checking 「.starts-with」 and 「.contains」 if there isn't anything
to start with.

On Tue, May 26, 2020 at 4:54 PM yary  wrote:

> From this much
>
> 158: Cannot resolve caller
> index(Str:U: Str:D); none of these signatures match:
>
> "index" is being called with the 1st arg undefined, 2nd arg defined. There
> is no "index" multi handling the 1st undefined arg, is my guess.
>
> -y
>
>
> On Tue, May 26, 2020 at 4:41 AM ToddAndMargo via perl6-users <
> perl6-us...@perl.org> wrote:
>
>> On 2020-05-26 01:37, ToddAndMargo via perl6-users wrote:
>> > 155: A:\YourDocs\backup1
>> >  156: No
>> >   157: No
>> >
>> > 158: Cannot resolve caller
>> > index(Str:U: Str:D); none of these signatures match:
>> >   (List:D: Cool:D $needle, *%_)
>>
>>
>> I wonder what that was all about.  Looked fine on my screen:
>>
>> 155: A:\YourDocs\backup1
>> 156: No
>> 157: No
>>
>> 158: Cannot resolve caller
>> index(Str:U: Str:D); none of these signatures match:
>> ...
>> (List:D: Cool:D $needle, *%_)
>> in sub GatherOptions at CobianWrapper.pl6 line 158
>>
>


Re: I need help testing for Nil

2020-05-26 Thread Brad Gilbert
Generally you don't need to test for 「Nil」.
You can just test for defined-ness.

$ raku -e 'my $x="abc"; with $x.index( "q" ) {say "Exists"} else {say
"Nil";}'

Also 「Nil」 is not a 「Str」, so why would you use 「eq」?

$ raku -e 'Nil.Str'
Use of Nil in string context

If you really need to check specifically for 「Nil」 (which you probably
don't), then you can use 「===」.

for Str, Int, Nil {
say 'Nil' if $_ === Nil;
}

The 「//」 operator can also be useful to deal with undefined values such as
「Nil」.

my $x = 'abc';
say $x.index('q') // 'cannot find the index of 「q」';


On Tue, May 26, 2020 at 4:24 PM ToddAndMargo via perl6-users <
perl6-us...@perl.org> wrote:

> Hi All,
>
> How do I turn this:
>
> $ raku -e 'my $x="abc"; say $x.index( "q" );'
> Nil
>
> into a test?
>
> $ raku -e 'my $x="abc"; if $x.index( "q" ) eq Nil {say "Nil"}else{say
> "Exists";}'
> Use of Nil in string context
>in block  at -e line 1
> Use of Nil in string context
>in block  at -e line 1
> Nil
>
>
> Many thanks,
> -T
>


Re: I do not understand method":"

2020-05-25 Thread Brad Gilbert
A lambda is a function that doesn't have a name, or a location.

my $var =  *.raku();

say $var.( Date.today );
# Date.new(2020,5,25)

The long way to write that would be:

my $var = anon sub ( $_ ) { .raku() };

So this is passing in a function to sort, to calculate the value that is to
be sorted with:

<5 2 1 33 22>.sort( *.Version )

sub call-Version ( $_ ) { .Version }
<5 2 1 33 22>.sort(  );

What sort does in this case is call .Version on each of the values to be
sorted, and sorts it based on those values.

So it is something like the following:

my @to-sort;
for <5 2 1 33 22> {
   push @to-sort, [.Version, .self]
}

my @sorted = @to-sort.sort();

my @result;
for @sorted {
  push @result, .[1]
}

say @result

---

Note that the following two lines are identical.

<5 2 1 33 22>.sort.Version
<5 2 1 33 22>.sort( ).Version( )

Which sorts using the default sort.
The result is a Seq.
Then it tries to call a method named Version on that Seq.

On Mon, May 25, 2020 at 4:41 PM ToddAndMargo via perl6-users <
perl6-us...@perl.org> wrote:

> >> On Mon, May 25, 2020 at 1:24 PM ToddAndMargo via perl6-users
> >> mailto:perl6-us...@perl.org>> wrote:
> >>
> >> Hi All,
> >>
> >> Looking at the following:
> >>
> >>   > my @things = .sort: *.Version;
> dd
> >> @things; for @things {say $_;}
> >>
> >> Array @things = ["a1b33", "a1", "a2rc2", "a2.3", "a5.1", "b1a23"]
> >>
> >> a1b33
> >> a1
> >> a2rc2
> >> a2.3
> >> a5.1
> >> b1a23
> >>
> >> Other than not quite getting the alpha, beta, and
> >> release candidate thing down, I do not understand:
> >>
> >> .sort: *.Version
> >>
> >> 1) What does the `:` do?
> >>
> >> 2) Why the space?
> >>
> >> 3) What does the `*` do?
> >>
> >> 4) Is the dot before Version mean something other
> >> than .Version being a method?
> >>
> >> Yours in confusion,
> >> -T
> >>
>
> On 2020-05-25 14:00, Brad Gilbert wrote:
> >
> > In the following the 「:」 makes it so you don't need parenthesis
> >
> >  (…).sort: …
> >
> >  (…).sort(…)
> >
> > The reason there needs to be a space is so it isn't confused for an
> adverb.
> >
> > 「*.Version」 is a method call turned into a lambda.
> > Basically it creates a lambda where the only thing it does is call a
> > method named 「Version」
> >
> > A 「*」 where a term is expected is an instance of Whatever.
> >
> > If you use that with an operator it becomes a WhateverCode lambda.
> >
> >  sub say-the-type ( $_ ) {
> >say .^name
> >  }
> >
> >  say-the-type  *;  # Whatever
> >
> >  say -the-type *.method; # WhateverCode
> >
> >
>
>
> Hi Brad,
>
> Thank you!
>
> So the same as
>  > my @things = <5 2 1 33 22>.sort( *.Version )
>  [1 2 5 22 33]
>
>
> Why don't these two work?  Or at least give the
> wrong answer.  I thought Version was a method.
>
>  > my @things = <5 2 1 33 22>.sort.Version
> No such method 'Version' for invocant of type 'Seq'
>in block  at  line 1
>
>  > my @things = <5 2 1 33 22>.Version.sort
> No such method 'Version' for invocant of type 'List'
>in block  at  line 1
>
>
> What is a "lambda" λ?
>
> -T
>


Re: I do not understand method":"

2020-05-25 Thread Brad Gilbert
In the following the 「:」 makes it so you don't need parenthesis

(…).sort: …

(…).sort(…)

The reason there needs to be a space is so it isn't confused for an adverb.

「*.Version」 is a method call turned into a lambda.
Basically it creates a lambda where the only thing it does is call a method
named 「Version」

A 「*」 where a term is expected is an instance of Whatever.

If you use that with an operator it becomes a WhateverCode lambda.

sub say-the-type ( $_ ) {
  say .^name
}

say-the-type  *;  # Whatever

say -the-type *.method; # WhateverCode


On Mon, May 25, 2020 at 1:24 PM ToddAndMargo via perl6-users <
perl6-us...@perl.org> wrote:

> Hi All,
>
> Looking at the following:
>
>  > my @things = .sort: *.Version; dd
> @things; for @things {say $_;}
>
> Array @things = ["a1b33", "a1", "a2rc2", "a2.3", "a5.1", "b1a23"]
>
> a1b33
> a1
> a2rc2
> a2.3
> a5.1
> b1a23
>
> Other than not quite getting the alpha, beta, and
> release candidate thing down, I do not understand:
>
> .sort: *.Version
>
> 1) What does the `:` do?
>
> 2) Why the space?
>
> 3) What does the `*` do?
>
> 4) Is the dot before Version mean something other
> than .Version being a method?
>
> Yours in confusion,
> -T
>


Re: Different return values with "say" vs "put" (Nil representation... )

2020-05-18 Thread Brad Gilbert
You are misunderstanding what `put` does.

It does not print the internal representation.

What it does do is turn the value into a `Str` object, then print it with a
trailing newline.

It just so happens that objects will by default return something that looks
like an internal representation when you coerce it to a `Str`.

class Point {
has ($.x, $.y);
}
put Point.new( x => 1, y => 2 ).Str
# Point<94102525076384>

put Point.new( x => 1, y => 2 ).gist
# Point.new(x => 1, y => 2)

put Point.new( x => 1, y => 2 ).raku
# Point.new(x => 1, y => 2)

Unless they have a `.Str` method that returns something more sensible.

class Point {
has ($.x, $.y);
method Str () {
"[$!x,$!y]"
}
}
put Point.new( x => 1, y => 2 ).Str
# [1,2]

put Point.new( x => 1, y => 2 ).gist
# Point.new(x => 1, y => 2)

put Point.new( x => 1, y => 2 ).raku
# Point.new(x => 1, y => 2)

Note that the default of `.gist` is do the same thing as calling `.raku`.
(Many/Most built-in objects have a `.gist` method that returns something
different.)

---

`s///` and `S///` are both intended as working on `Str` objects. So when
you give them something that is not a `Str`, they turn it into a `Str`
first.
Actually all operations that are `Str` operations will turn it into a `Str`
first.
Like `.starts-with`, `.ends-with`, `.chars`, `.codes`, `.index`, `.substr`,
`print`, and `put`

What `say` does, is that instead of calling `.Str` it calls `.gist`

`.gist` is defined as giving enough information for a human to be able to
figure out what object was printed.
(Which is why the default is to return the same thing as `.raku` for
defined objects)

Actually almost all operations are intended for one type of object, and
will coerce to that type.

> say ['a', 'b', 'c']   +   %( d => 10, e => 20 )
5

---

Many objects will throw an error if you call `.Str` on them when they are
undefined.

> Bool.Str
Use of uninitialized value of type Bool in string context.
Methods .^name, .raku, .gist, or .say can be used to stringify it to
something meaningful.
  in block  at  line 1

> Nil.Str
Use of Nil in string context
  in block  at  line 1

Which means they also throw an error if you try to use one of the methods
intended for `Str` objects on them.

> Bool.substr(0,1)
Use of uninitialized value of type Bool in string context.
Methods .^name, .raku, .gist, or .say can be used to stringify it to
something meaningful.
  in block  at  line 1

> Bool.^name.substr(0,1)
B

The reason for it generating an error is that generally when you try to
turn an undefined object into a Str, there is likely a bug somewhere.

---

Since `.gist` is for a human, it doesn't matter if the returned value is a
little wrong, so it doesn't fail.
(A human can notice if something is wrong. A program that only does what
you told it to, generally doesn't.)

> Bool.gist
(Bool)

Note that the reason it puts ( and ) around the name of the object is so
that you know that you might have a problem somewhere in your code.

---

Further, Nil is actually the most basic of the Failure objects.

> for Failure.^mro { say .^name }
Failure
Nil
Cool
Any
Mu

If you get a Nil, there is probably some sort of failure somewhere.

> say ( 1, 2, 3, 4 ).first( 'one' )
Nil

Which means that if you try to use a Nil as a Str, there is definitely a
bug in your code.

On Mon, May 18, 2020 at 2:00 AM William Michels via perl6-users <
perl6-us...@perl.org> wrote:

> Hello,
>
> I'm interested in knowing the differences between the return values
> when "say" is used compared to "put". My understanding is that "put"
> returns Raku's internal representation of a value held by a variable,
> while "say" is merely "put" with the .gist method called on it (a
> "human readable", often-abbreviated return value).
>
> Below I do "S///" (non-destructive) and "s///" (destructive) text
> replacement on a three line text file in bash line [1]. In bash line
> [2], the full substituted text file is correctly returned; in bash
> line [3] using "say" only the $/ match string is returned. So far so
> good. However, a virtually-identical call in bash line [4] using "put"
> instead of "say" returns an error for the first line of the target
> text file: "Use of Nil in string context in block  at -e line 1".
>
> [1] homedir$ cat demo1.txt
> this is a test,
> I love Unix,
> I like Linux too,
>
> [2] homedir$ perl6 -ne 'say S/love|like/admire/;' demo1.txt
> this is a test,
> I admire Unix,
> I admire Linux too,
>
> [3] homedir$ perl6 -ne 'say s/love|like/admire/;' demo1.txt
> Nil
> 「love」
> 「like」
>
> [4] homedir$ perl6 -ne 'put s/love|like/admire/;' demo1.txt
> Use of Nil in string context
>   in block  at -e line 1
>
> love
> like
>
> [5] homedir$
>
> I'm really trying to understand this error message:  doesn't Raku know
> that this is a text 

Re: How to find if a drive letter exists?

2020-05-17 Thread Brad Gilbert
Why do you have `.Bool` on all of the `.e` tests?

A file or directory either exists or it doesn't. So `.e` always returns a
Bool.
So there is zero reason to try to coerce it to a Bool.

You can look at the return value of `.e`.

> say '.'.IO.can('e').head.signature
(IO::Path:D: *%_ --> Bool)

If you don't trust that, you can look at the source
https://github.com/rakudo/rakudo/blob/fc88b9c2d2e71ab7fa492a53f0f90847c945bfcd/src/core.c/IO/Path.pm6#L738-L740

method e(IO::Path:D: --> Bool:D) {
nqp::hllbool(Rakudo::Internals.FILETEST-E(self.absolute)) }

It says it returns a Bool. It even uses `nqp::hllbool` which coerces the
value to `Bool`.

One of the design ethos of Raku is to reduce busy-work.
That is work that you don't really need to do.

I really can't understand why you insist on doing that busy-work anyway.


On Sun, May 17, 2020 at 4:56 AM ToddAndMargo via perl6-users <
perl6-us...@perl.org> wrote:

> On 2020-05-17 00:52, ToddAndMargo via perl6-users wrote:
> > Hi All,
> >
> > Windows 7 & 10
> >
> > I want to know if a drive letter exists:
> >
> >
> > K:\Windows\NtUtil>df -kPT
> > Filesystem   Type  1024-blocks  Used Available Capacity
> > Mounted on
> > C:/Program Files/Git ntfs 40585620  15044068  25541552  38% /
> > D:   udf   5294394   5294394 0 100% /d
> > E:   ntfs 8188  3908  4280  48% /e
> > F:   ntfs10236  3908  6328  39% /f
> > J:   smbfs   951048868 514547660 436501208  55% /j
> > K:   smbfs   951048868 514547680 436501188  55% /k
> > L:   smbfs   951048868 514547700 436501168  55% /l
> >
> > K:\Windows\NtUtil>dir e:
> >   Volume in drive E is DRIVERS
> >   Volume Serial Number is 44EB-5181
> >
> >   Directory of E:\
> >
> > File Not Found
> >
> > This exists:
> > K:\Windows\NtUtil>raku -e "say 'H:'.IO.d.Bool;"
> > True
> >
> > This does not:
> > K:\Windows\NtUtil>raku -e "say 'Z:'.IO.d.Bool;"
> > True
> >
> >
> > Many thanks,
> > -T
> >
> >
>
> Follow up:
>
> Hi All,
>
> Prince213 on the chat line helped me figure this out.
>
> This is from my IO keeper:
>
> Drive (letter) exists (Windows only):
> use `IO.e.Bool`
>
> # forward slashes
> >raku -e "say 'X:/'.IO.e.Bool;"
> False
>
> >raku -e "say 'D:/'.IO.e.Bool;"
> True
>
> >raku -e "say 'd:/'.IO.e.Bool;"
> True
>
> >raku -e "say 'Z:/'.IO.e.Bool;"
> False
>
> # back slashes
> >raku -e "say 'd:\\'.IO.e.Bool;"
> True
>
> >raku -e "say Q[d:\].IO.e.Bool;"
> True
>
> >raku -e "say Q[z:\].IO.e.Bool;"
> False
>
>
> -T
>


Re: Raku -npe command line usage

2020-05-08 Thread Brad Gilbert
The 「@i」 is defined within the 「BEGIN」 block, so it is scoped to the
「BEGIN」 block.

If you didn't want that, don't use a *block* with 「BEGIN」.

BEGIN my @i;

Also you wrote the 「if」 wrong.
There shouldn't be a 「;」 before the 「if」.
You also don't need to use 「$_ ~~ 」 with 「/^WARN/」 as that would
automatically happen.

@i.push($_) if /^WARN/;

You probably also want the lines to be written each to to their own lines.
So you probably want one of the following.

@i.sort.map( *.say )
.say for @i.sort

Again you don't need to use a block with 「END」 either.

So together that would be:

raku -ne 'BEGIN my @i; @i.push($_) if /^WARN/; END .say for @i.sort'

---

That said, I wouldn't use -n in this case.

raku -e 'lines.grep( /^WARN/ ).sort.map( *.say )'

Currently regexes are a bit slow. You can use 「.starts-with」 instead to
make it faster.

raku -e 'lines.grep( *.starts-with(q[WARN]) ).sort.map( *.say )'

(Note that 「 'abc' 」 is short for 「 q'abc' 」 which can also be written as 「
q[abc] 」.
The latter is useful on the command line so that it doesn't interfere with
the command processor quoting rules.)

On Fri, May 8, 2020 at 7:16 AM WFB  wrote:

> Hi,
>
> I am trying to write an one-liner to go through all lines in a logfile and
> look for an certain key word, store the line and sort them before printing
> them out.
>
> My approach was:
> raku -ne "BEGIN {my @i }; @i.push($_); if $_ ~~ /^WARN/; END { @i.sort.say
> }"
> That does not work because @i does not exist in the if clause. I tried our
> @i as well with no luck.
>
> How can I store data that can be accessed in the END phaser? Or is there
> another way to archive it? TIMTOWTDI^^
>
> One hint I found was the variable $ and @ respectively. But those
> variables are created for each line new...
>
>
> I did not found a help or examples for -npe except raku -h. Is there more
> helpful stuff somewhere in doc.raku.org? If so I could'nt find it.
>
> Thanks,
> Wolfgang
>


Re: readchars, seek back, and readchars again

2020-04-24 Thread Brad Gilbert
In UTF8 characters can be 1 to 4 bytes long.

UTF8 was designed so that 7-bit ASCII is a subset of it.

Any 8bit byte that has its most significant bit set cannot be ASCII.
So multi-byte codepoints have the most significant bit set for all of the
bytes.
The first byte can tell you the number of bytes that follow it.

That is how a singe codepoint is stored.

A character can be made of several codepoints.

"\c[LATIN SMALL LETTER E]\c[COMBINING ACUTE ACCENT]"
"é"

So Rakudo has to read the next codepoint to make sure that it isn't a
combining codepoint.

It is probably faking up the reads to look right when reading ASCII, but
failing to do that for wider codepoints.

On Fri, Apr 24, 2020 at 1:34 PM Joseph Brenner  wrote:

> I thought that doing a readchars on a filehandle, seeking backwards
> the width of the char in bytes and then doing another read
> would always get the same character.  That works for ascii-range
> characters (1-byte in utf-8 encoding) but not multi-byte "wide"
> characters (commonly 3-bytes in utf-8).
>
> The question then, is why do I need a $nudge of 3 for wide chars, but
> not ascii-range ones?
>
> use v6;
> use Test;
>
> my $tmpdir = IO::Spec::Unix.tmpdir;
> my $file = "$tmpdir/scratch_file.txt";
> my $unichar_str = "\x[1200]\x[2D80]\x[4DFC]\x[]\x[2CA4]\x[2C8E]";  #
> ሀⶀ䷼ꪪⲤⲎ
> my $ascii_str =   "ABCDEFGHI";
>
> subtest {
> my $nudge = 3;
> test_read_and_read_again($unichar_str, $file, $nudge);
> }, "Wide unicode chars: $unichar_str";
>
> subtest {
> my $nudge = 0;
> test_read_and_read_again($ascii_str, $file, $nudge);
> }, "Ascii-range chars: $ascii_str";
>
> # write given string to file, then read the third character twice and check
> sub test_read_and_read_again($str, $file, $nudge = 0) {
> spurt $file, $str;
> my $fh = $file.IO.open;
> $fh.readchars(2);  # skip a few
> my $chr_1 =  $fh.readchars(1);
> my $width = $chr_1.encode('UTF-8').bytes;  # for our purposes, always
> 1 or 3
> my $step_back = $width + $nudge;
> $fh.seek: -$step_back, SeekFromCurrent;
> my $chr_2 =  $fh.readchars(1);
> is( $chr_1, $chr_2,
> "read, seek back, and read again gets same char with nudge of
> $nudge" );
> }
>


Re: sleep 3600 vs task scheduler

2020-04-07 Thread Brad Gilbert
Run code once an hour:

react whenever Supply.interval(60 * 60) {
say "it's been an hour"
}

Right now that gets about 0.01 seconds slower every time the interval runs.
(At least on my computer.)
So it will get 1 second later every 4 days.


Or if you want more precise control, you could do something like:

Here is an example that is more accurate, and happens at the top of the
hour:

sub every-hour ( --> Supply:D ) {
supply {
sub add-next ( $hour --> Nil ) {
whenever Promise.at( $hour.Instant ) {
emit $hour;
add-next( $hour.later(:1hour) );
}
}

add-next( DateTime.now.truncated-to('hour').later( :1hour ) );
}
}


react whenever every-hour() {
say "it's been an hour";
say "the time is $_"
}



Honestly it would probably be better to use something native to the system
to run it once an hour, in case the program dies.


On Tue, Apr 7, 2020 at 6:02 AM ToddAndMargo via perl6-users <
perl6-us...@perl.org> wrote:

> Hi All,
>
> Windows 7/10
>
> Another piece of the puzzle.
>
> I want to loop Raku program once an hour.
>
> Is it better use `sleep 3600` or let the program
> die and restart every hour from the Task Scheduler.
> By better, I mean less of a CPU footprint.
>
> `sleep` would allow the user to cancel the program
> and not have it come back.
>
> Many thanks,
> -T
>


Re: How to read a particular environmental variable?

2020-04-07 Thread Brad Gilbert
Of course %*ENV is case sensitive, hashes are case sensitive.

say %*ENV.^name; # Hash

%*ENV gets populated with the values before your code runs.
Other than that it is fairly ordinary.

On Tue, Apr 7, 2020 at 7:20 PM ToddAndMargo via perl6-users <
perl6-us...@perl.org> wrote:

> >> On Tue, Apr 7, 2020 at 6:48 PM ToddAndMargo via perl6-users
> >> mailto:perl6-us...@perl.org>> wrote:
> >>
> >> Hi All,
> >>
> >> $ raku -e 'say %*ENV;'
> >>
> >> Gives me ALL of them.  Is there a way to just ask for
> >> a particular one, such as %appdata%, or %userprofile%
> >> in Windows or $HOME is Linux?
> >>
> >> Many thanks,
> >> -T
> >>
>
> On 2020-04-07 16:05, Gerard ONeill wrote:
> > It’s still a hash — the * twigil tweaks it’s scope, but it is still a %
> > — so %*ENV works (windows)
> >
> >
> Hi Gerald,
>
> Ah Ha!  Thank you!
>
> Windows 10:
>
> raku -e "say %*ENV;"
> C:\Users\todd\AppData\Roaming
>
>
> Fedora:
> $ raku -e 'say %*ENV;'
> /home/tony
>
> Oh, and both WIndows and Fedora (Linux) are case
> sensititive
>
> Love Hashes.  My favorite variable structure.
>
> -T
>


Re: Can a sub be released?

2020-04-07 Thread Brad Gilbert
You do NOT want to use `fork`.
MoarVM has several threads that are running, and `fork` doesn't handle that.

A simple way is to just use the `start` statement prefix

sub child-process () {
sleep 2;
say 'child says hi'
}

say 'starting child';
start child-process();

for ^10 {
say ++$;
sleep .5;
}
say 'ending program';

Which will result in something like:

starting child
1
2
3
4
child says hi
5
6
7
8
9
10
ending program

The program will exit when the mainline finishes. So if you didn't have the
loop, the program will exit before the child prints anything.

You could directly call `$*SCHEDULER.cue()` instead.
Which has adverbs such as `every`, `times`, `at`, `in`, and `catch`

If you use one of the adverbs other than `catch`, it will return
a Cancellation object which would allow you to stop a thread that hasn't
started running yet.

On Tue, Apr 7, 2020 at 4:19 PM yary  wrote:

> They way I remember it (taught to me waaay back when) is that, you fork
> twice, and the grandchild process that lives on becomes a daemon whose
> parent is the system "init" process, PID 1, after the parent and
> 1st-generation child process exit. Found general concept at
> http://www.farhadsaberi.com/perl/2013/02/perl-detach-process-daemon.html
>
> How to implement that in raku, and if it works as intended in Windows...
> is left as an exercise to the reader!
>
> -y
>
>
> On Tue, Apr 7, 2020 at 2:42 PM Paul Procacci  wrote:
>
>> https://docs.perl6.org/language/5to6-perlfunc#fork
>> https://docs.perl6.org/type/Thread
>>
>> I haven't tried myself but it's conceivable that you can start a new
>> thread that exec's some external program.
>>
>> On Tue, Apr 7, 2020 at 7:21 AM ToddAndMargo via perl6-users <
>> perl6-us...@perl.org> wrote:
>>
>>> Hi All,
>>>
>>> Can a subroutine be released from the main program
>>> to go off on its own?  (Is this called "forked"?)
>>>
>>> If not how do I do a `qqx` or a `run` that releases
>>> the program to go off on its own?
>>>
>>> Many thanks,
>>> -T
>>>
>>
>>
>> --
>> __
>>
>> :(){ :|:& };:
>>
>


Re: unflattering flat

2020-04-06 Thread Brad Gilbert
[*] is also a meta prefix op

say [*] 4, 3, 2; # 24

But it also looks exactly the same as the [*] postfix combination of
operators

my @a = 1,2,3;

say @a[*]; # (1 2 3)

There is supposed to be one that looks like [**]

my @b = [1,], [1,2], [1,2,3];

say @b[**]; # (1 1 2 1 2 3)

Really @a[*] is

say postfix:« [ ] »( @a, Whatever )

And @b[**] is

say postfix:« [ ] »( @b, HyperWhatever )

---

say *.WHAT.^name; # Whatever

say **.WHAT.^name; # HyperWhatever

On Mon, Apr 6, 2020 at 7:05 PM yary  wrote:

> Question- what am I missing from the below two replies?
>
> Larry's answer came through my browser with munged Unicode, it looks like
> this
>
> [image: image.png]
> - with the Chinese character for "garlic" after the word "values"
>
> Then Ralph says "[**] will be a wonderful thing when it's implemented" but
> as far as I can tell, [**] is exponentiation (math) as a hyper-op, nothing
> to do with flattening. From https://docs.raku.org/language/operators
>
> say [**] 4, 3, 2; # 4**3**2 = 4**(3**2) = 262144
>
>
>
>


Re: How do I open Raku in the background?

2020-03-30 Thread Brad Gilbert
There is a bit in the executable that tells windows to open a terminal.

If you copy the executable to say rakudo_no_terminal.exe and change that
bit in the copy, then Windows won't show you a terminal.

On Mon, Mar 30, 2020 at 8:14 PM ToddAndMargo via perl6-users <
perl6-us...@perl.org> wrote:

> >> On Sun, Mar 29, 2020 at 8:44 PM ToddAndMargo via perl6-users
> >> mailto:perl6-us...@perl.org>> wrote:
> >>
> >> Hi All,
> >>
> >> Windows 10-1909 Pro
> >>
> >> raku -v
> >> This is Rakudo version 2020.01 built on MoarVM version
> >> 2020.01.1 implementing Perl 6.d.
> >>
> >> I am opening Raku from the registry with
> >>
> >> [HKEY_CLASSES_ROOT\*\shell\OpenWithFileAttributes.pl6\command]
> >> @="\"C:\\rakudo\\bin\\raku.exe\"
> >> \"K:\\Windows\\NtUtil\\FileAttributes.pl6\" \"%1\""
> >>
> >> Problem: up pops a big black box with Raku running it in.
> >> Is there a way to rid myself of the big black box?
> >> (I have pops for the information that is reported to
> >> the user.)
> >>
> >>
> >> Many thanks,
> >> -T
> >>
>
> On 2020-03-30 08:04, yary wrote:
> > This is a Windows explorer/shell issue. Search the web; this is one
> > approach - use cmd with some switches to start with the window minimized
> >
> https://stackoverflow.com/questions/4277963/how-to-call-cmd-without-opening-a-window
> >
> > I'm a fan of Emacs on all my platforms; their solution in Windows is a
> > tiny executable that opens Emacs without having the secondary shell
> > window, if I understand correctly.
> >
> > -y
>
> Rats.  I was hoping it was something in Raku's run string.
>
> Thank you for the CMD tip!
>
> -T
>


Re: perl6 vs ruby

2020-03-05 Thread Brad Gilbert
There isn't currently a way to compile to a single file, but there was a
GSOC project that started on it.

On Thu, Mar 5, 2020, 7:17 AM Aureliano Guedes 
wrote:

> I have another question for you. Maybe it must be better done in another
> thread...
> But, there is a way to compile Raku code in a binary capable to run in a
> system without a Raku installation?
>
> On Thu, Mar 5, 2020 at 6:17 AM Elizabeth Mattijsen  wrote:
>
>> Well, internally many parts still have Perl 6 in them.  Renaming those
>> is...  an interesting task.
>>
>> Online, most resources have been renamed, but some still need to be
>> done.  This mailing list being one of them.  Unfortunately, it is part of
>> the crumbling Perl infrastructure, so it's unclear what would be the best
>> course forward on this.
>>
>> > On 5 Mar 2020, at 10:09, Wyatt Chun  wrote:
>> >
>> > Hi
>> >
>> > Is perl6 totall renamed to raku?
>> >
>> > regards
>> >
>> > On Wed, Mar 4, 2020 at 4:15 AM Fields, Christopher J <
>> cjfie...@illinois.edu> wrote:
>> > A few people had started a port of some BioPerl code to Perl6 a while
>> ago; I tested this recently and it still passed tests.
>> >
>> > https://github.com/cjfields/bioperl6
>> >
>> > It should be renamed to bioraku!
>> >
>> > Chris
>> >
>> > Sent from my iPhone
>> >
>> >> On Mar 3, 2020, at 11:41 AM, Parrot Raiser <1parr...@gmail.com> wrote:
>> >>
>> >> 
>> >>> we use ruby for Biological data analysis. I wish perl6 should have
>> got that capability.
>> >>
>> >> Would you like to give us a sample problem,, to see if someone can
>> >> show a potential solution?
>>
>
>
> --
> Aureliano Guedes
> skype: aureliano.guedes
> contato:  (11) 94292-6110
> whatsapp +5511942926110
>


Re: PCRE -> Perl 6 RE

2020-02-18 Thread Brad Gilbert
The \p{L} syntax is done by using :L inside of <> instead

/\p{L}/
/<:L>/

You can combine them

/[\p{L}\p{Z}\p{N}]/
/<:L + :Z + :N>/

Character classes are also done inside of <>

/[_.:/=+\-@]/
/<[_.:/=+\-@]>/

They of course can also be combined with the previous discussed feature.

/[\p{L}\p{Z}\p{N}_.:/=+\-@]+/
/<:L + :Z + :N + [_.:/=+\-@] >+/

So that is the translation of your regex.

---

It might be considered a bug that you can't just use :P5, as your regex
works just fine in Perl5.

On Tue, Feb 18, 2020 at 10:03 PM Paul Procacci  wrote:

> Hey Guys,
>
> I've got a bunch of source files with PCRE's like the following:
>
> [\p{L}\p{Z}\p{N}_.:/=+\-@]+
>
> I have a program that generates other perl6 source files, by way of
> reading the initial source files.
> It was my intention to simply pass along this regex to the resulting
> output file for use in subset's like the following:
>
> subset ThisType of Str where * ~~ m:P5/[\p{L}\p{Z}\p{N}_.:/=+\-@]+/;
>
> I was going to at first hope add a PCRE adverb of sorts but that doesn't
> exist.
> I then was going to stick the Perl5 adverb on it ... but again no luck as
> it pukes on the escaped p's.
>
> Is there anything smart enough to translate these tokens into either:
>
> a) perl5 syntax for use with the Perl5 adverb or
> b) perl6 syntax for use with built-in perl6 re's.
> c) A module that anyone's familiar with that isn't publish or
> d) I'm simply SOL?
>
> Thanks,
> Paul
>
> --
> __
>
> :(){ :|:& };:
>


Re: Metamethods: WHERE

2020-02-12 Thread Brad Gilbert
If you want to find out if two variables are bound to the same data, there
is an operator for that

my $a = 3;
my $b = 3;
say $a =:= $b; # False

my $c := $b;
say $b =:= $c; # True

On Wed, Feb 12, 2020 at 7:27 AM Aureliano Guedes 
wrote:

> Thank you.
>
> So, I'd like to find a way to test if two variables are bound or not,
> especially concerning their memory address.
>
> If the address is not fixed for a lifetime, I must be able to test it in
> just one cycle.
> > $a.WHERE == $b.WHERE   # I expected FALSE
> True
>
> To a bound variable, I expect the same address, but to an unbounded
> variable, this garbage collector behavior seams assing to the same memory
> location two unbounded variables with the same value. It is right? Must
> reduce memory usage but is a quiet weirdo.
>
> On Wed, Feb 12, 2020 at 10:13 AM Elizabeth Mattijsen 
> wrote:
>
>>
>>
>> > On 12 Feb 2020, at 13:44, Aureliano Guedes 
>> wrote:
>> >
>> > What "WHERE" should return?
>> >
>> > I was trying to find a method to return the memory address of some data.
>> > Then I find the WHERE statement.
>> > https://rosettacode.org/wiki/Address_of_a_variable#Perl_6
>> > https://docs.perl6.org/language/mop#WHERE
>>
>> Please note that the memory address is *NOT* fixed for the lifetime of an
>> object.  Garbage collection may move it to another memory location at *any*
>> time.  I've therefore adapted the documentation of .WHERE to:
>>
>> Returns an C representing the memory address of the object.  Please
>> note
>> that in the Rakudo implementation of Raku, and possibly other
>> implementations,
>> the memory location of an object is B fixed for the lifetime of the
>> object.  So it has limited use for applications, and is intended as a
>> debugging
>> tool only.
>>
>> https://github.com/Raku/doc/commit/3e6270d197
>
>
>
> --
> Aureliano Guedes
> skype: aureliano.guedes
> contato:  (11) 94292-6110
> whatsapp +5511942926110
>


Re: Question about Blob and Buf

2020-02-11 Thread Brad Gilbert
The problem is that you are using ~ with an uninitialized Buf/Blob

my Buf $read;
$read ~ Buf.new;
# Use of uninitialized value element of type Buf in string context.

Note that it is not complaining about it being a Buf. It is complaining
about it being uninitialized.

If you initialize it then it works just fine.

my Buf $read .= new;
$read ~ Buf.new;

It will also work with ~=

my Buf $read .= new;
$read ~= Buf.new( 'a'.ord, 'b'.ord );
$read ~= Blob.new( 'c'.ord, 'd'.ord );
say $read.decode; # abcd

It also works with Blob, but you may not want to do that if you plan on
modifying the contents with something like `.subbuf-rw()`.

On Tue, Feb 11, 2020 at 3:56 AM David Santiago  wrote:

> A 11 de fevereiro de 2020 10:47:34 CET, David Santiago 
> escreveu:
> >A 11 de fevereiro de 2020 09:46:06 CET, David Santiago <
> deman...@gmail.com> escreveu:
> >>
> >>Hi!
> >>
> >>Can someone explain me why this doesn't work:
> >>
> >>my Blob $read;
> >>$read ~= $socket.read(1024);
> >>
> >>Dies with error:
> >>
> >>X::Buf::AsStr: Cannot use a Buf as a string, but you called the Stringy
> method on it
> >>
> >>This also doesn't work:
> >>
> >>my Buf $read;
> >>$read ~= $socket.read(1024);
> >>
> >>Dies with the same error as above.
> >>
> >>
> >>But this works?
> >>
> >>my Blob $read = Buf.new;
> >>$read ~= $socket.read(1024);
> >>
> >>
> >>Best regards,
> >>David Santiago
> >
> >
> >Hi!
> >
> >Can someone explain me why this doesn't work:
> >
> >my Blob $read;
> >$read ~= $socket.read(1024);
> >
> >Dies with error:
> >
> >X::Buf::AsStr: Cannot use a Buf as a string, but you called the Stringy
> method on it
> >
> >This also doesn't work:
> >
> >my Buf $read;
> >$read ~= $socket.read(1024);
> >
> >Dies with the same error as above.
> >
> >
> >But this works?
> >
> >my Blob $read = Buf.new;
> >$read ~= $socket.read(1024);
> >
> >
> >Best regards,
> >David Santiago
>
>
> Hi!
>
> Can someone explain me why this doesn't work:
>
> my Blob $read;
> $read ~= $socket.read(1024);
>
> Dies with error:
>
> X::Buf::AsStr: Cannot use a Buf as a string, but you called the Stringy
> method on it
>
> This also doesn't work:
>
> my Buf $read;
> $read ~= $socket.read(1024);
>
> Dies with the same error as above.
>
>
> But this works?
>
> my Blob $read = Buf.new;
> $read ~= $socket.read(1024);
>
>
> Best regards,
> David Santiago
>
> --
> Sent from my Android device with K-9 Mail. Please excuse my brevity.
>


Re: Hash Constraints w/in subset's

2020-02-01 Thread Brad Gilbert
I wouldn't use a subset like this:

subset PhoneBook of Hash[Int, Str];

I would instead use a constant:

constant PhoneBook = Hash[Int, Str];

Then you can use that for creating new instances.

PhoneBook.new(); # Hash[Int, Str].new()
# or
my %pb is PhoneBook; # my Int %pb{Str};

I might even consider creating a class:

class PhoneBook is Hash[Int, Str] {
}

my %pb is PhoneBook;

---

Both the constant and new class have the benefit that you can state in your
code what the %pb variable is actually used for.

Even better is that if you use the constant consistently, you can
transition to the class style easily.
Which is useful if you want to add methods.

---

Note that none of the above allow you to use it like this:

sub foo ( PhoneBook %pb ){…}

You have to do one of these:

sub foo ( PhoneBook $pb ){…}
sub foo ( PhoneBook \pb ){…}

sub foo ( Int %pb{Str} ){…} # only with constant or subset

On Sat, Feb 1, 2020 at 3:25 AM Tobias Boege  wrote:

> On Sat, 01 Feb 2020, Paul Procacci wrote:
> > Hey ladies/gents,
> >
> > How would one go about defining a subset of a Hash who's key's and values
> > are both constrained by something 
> >
> > I've read https://docs.perl6.org/type/Hash and it does make mention of
> > constraining keys and values, but not within the context of a subset.
> > Before I go ripping my hair out, I want to make sure I'm doing things
> right.
> >
> > For instance, what if I want to define a subset that uses a Hash as it's
> > base class, in which I want to add the constraint that it's keys must be
> > strings yet it's values are constrained to only accept Int's?
> >
>
> You would make a subset of Hash if you are getting Hashes and you want
> to give some common code that checks the validity of the Hash a name.
> If you want a new type that you can actually create objects from, the
> solution is subclassing, not subsetting, but works similarly to below.
> (Just to make sure you're not surprised when you can't call .new on
> your subset later.)
>
> With a subset you could do:
>
> subset PhoneBook of Hash[Int, Str];
>
> my Int %pb{Str};
> %pb   = +49_123_4567_6789;  # good
> try %pb = "unknown";  # fails
>
> dd %pb  #= Hash[Int,Str] %pb = (my Int %{Str} = :tobias(4912345676789))
> say %pb ~~ PhoneBook  #= True
>
> to the same effect.
>
> Note that if you subset PhoneBook of Hash[Int, Str], then your hashes
> really must be typed. An ordinary Hash that just happens to always map
> strings to integers is not sufficient and will fail the type check.
> You could make a looser subset of Hash with a where clause that checks
> compatibility of all keys with Str and of all values with Int as well,
> but that would be more expensive.
>
> To answer your question: Hash does the Associative role which is
> parameterized by the key and value type, but *in reverse order*.
> Hash[Int, Str] is the type that maps Int <-- Str, just like in the
> neat `my Int %pb{Str}` declaration.
>
> Regards,
> Tobias
>
> --
> "There's an old saying: Don't change anything... ever!" -- Mr. Monk
>


Re: troubles with with base(2)

2020-01-20 Thread Brad Gilbert
Why would you think that?

The numeric binary xor operator is +^.

my $v = 0b00101101 +^ 0b1001; say $v.base(2);
# 100100

^ is the junctive xor operator.

   my $v = 1 ^ 2 ^ 'a';
  $v eq 'a'; # True
  $v == 1; # True
  $v == 2; # True
  $v == 3; # False

There is also the stringy binary xor operator.

say 'A' ~^ '%'; # D

On Mon, Jan 20, 2020 at 3:57 PM ToddAndMargo via perl6-users <
perl6-us...@perl.org> wrote:

> Hi All,
>
> Now what am I doing wrong?
>
>  my $v = 0b00101101 ^ 0b1001; say $v.base(2);
>  one(101101, 1001)
>
> It should be
>  100100
>
>
> Many thanks,
> -T
>


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

2020-01-20 Thread Brad Gilbert
.say for lines

On Mon, Jan 20, 2020 at 1:59 AM William Michels via perl6-users <
perl6-us...@perl.org> wrote:

> Hi Yary (and Todd),
>
> Thank you both for your responses. Yary, the problem seems to be with
> "get". I can change 'while' to 'for' below, but using 'get' raku/perl6
> actually returns fewer lines with "for" than it did with "while":
>
> [1]mydir$ cat testthis_abc_def.txt
> a
> b
> c
>
> d
> e
> f
> [2]mydir$ perl6 -e '.say while $_ = $*IN.get;' < testthis_abc_def.txt
> a
> b
> c
> [3]mydir$ perl6 -e '.say for $_ = $*IN.get;' < testthis_abc_def.txt
> a
>
> I assumed 'get' was looking at EOF but that's incorrect--apparently
> 'get' acts more like a glorified call to lines[0], reading one line of
> an input file and then stopping. I can read my whole test file by
> explicitly testing for EOF (note the redeclaration of $*IN below).
> Otherwise, my best course of action is replacing 'get' with 'lines',
> and using either 'while' or 'for' ('.say for $*IN.lines;' replicates
> 'cat' behavior the best):
>
> [4]mydir$ perl6 -e 'while not($*IN.eof) -> {$*IN.get.say };' <
> testthis_abc_def.txt
> a
> b
> c
>
> d
> e
> f
> [5]mydir$ perl6 -e '.say while $_ =$*IN.lines;' < testthis_abc_def.txt
> (a b c  d e f)
> [6]mydir$ perl6 -e '.say for $_ = $*IN.lines;' < testthis_abc_def.txt
> (a b c  d e f)
> [7]mydir$ perl6 -e '.say for $*IN.lines;' < testthis_abc_def.txt
> a
> b
> c
>
> d
> e
> f
>
> HTH, Bill.
>
>
>
>
>
> On Sat, Jan 18, 2020 at 5:55 PM yary  wrote:
> >
> > "while" is the wrong looping construct for going over file lines, and
> that's across a great many computer languages. It will stop when it
> encounters a false line- typically an empty line or '0'
> >
> > Try "for"
> >
> > -y
> >
> >
> > On Sat, Jan 18, 2020 at 4:45 PM William Michels 
> wrote:
> >>
> >> Hello All,
> >>
> >> I've been reviewing literature that discusses using raku/perl6 as a
> >> replacement for common unix utilities. One important unix utility is
> >> "cat". I looked at docs/blogs and found a recommendation to use "$*IN"
> >> along with "slurp" (references at bottom). Using a seven-line test
> >> file "testthis_abc_def.txt" below (1), the recommended "slurp" code
> >> works as expected (2).
> >>
> >> However, another recommendation to use "$*IN" along with the "get"
> >> method fails when a blank line is encountered, only returning
> >> truncated output (3). I tried correcting truncated output seen with
> >> "get" by playing with the command-line arguments "-ne" (4) and "-pe"
> >> (5), but only ended up mangling output even further.
> >>
> >> Can "get" be used in when writing raku/perl6 replacement code for "cat"?
> >>
> >> Any advice appreciated,
> >>
> >> Bill.
> >>
> >>
> >> [1]mydir$ cat testthis_abc_def.txt
> >> a
> >> b
> >> c
> >>
> >> d
> >> e
> >> f
> >> [2]mydir$ perl6 -e 'say $*IN.slurp;' < testthis_abc_def.txt
> >> a
> >> b
> >> c
> >>
> >> d
> >> e
> >> f
> >>
> >> [3]mydir$ perl6 -e '.say while $_ = $*IN.get;' < testthis_abc_def.txt
> >> a
> >> b
> >> c
> >> [4]mydir$ perl6 -ne '.say while $_ = $*IN.get;' < testthis_abc_def.txt
> >> b
> >> c
> >> e
> >> f
> >> [5]mydir$ perl6 -pe '.say while $_ = $*IN.get;' < testthis_abc_def.txt
> >> b
> >> c
> >>
> >> e
> >> f
> >> (Mu)
> >> [6]mydir$
> >>
> >>
> >> REFERENCES:
> >> 1. https://docs.raku.org/routine/slurp
> >> 2. https://docs.raku.org/routine/get
> >> 3.
> https://andrewshitov.com/2019/09/09/the-cat-utility-written-in-perl-6/
> >> 4.
> https://stackoverflow.com/questions/52597984/catching-exception-of-a-shell-command-in-perl-6
>


Re: definition confusion of + and +^

2020-01-18 Thread Brad Gilbert
Most operators in Raku are subroutines.

1 + 2
infix:<+>( 1, 2 )

-1
prefix:<->( 1 )

You can add your own operators by creating such a subroutine.

sub postfix: ( UInt \n ) { [×] 2..n }

say 5!; # 120

Because it is so easy to add operators. Operators only do one thing.

1 + 2

That operator is for doing numeric addition.
If the two things are not numbers they get turned into numbers

['a'] + ['b', 'c'] # exactly the same as 1 + 2

The +^ operator is about Integers. So if you give it something that is not
an integer it becomes one.

1.2 +^ 1; # exactly the same as 1 +^ 1

---

Note that Int:D does NOT do any coercions.

Int:D() does do coercions.

Specifically Int:D() is short for Int:D(Any). Which means it coerces from
Any to Int, and the result must be defined.

On Sat, Jan 18, 2020 at 2:39 PM ToddAndMargo via perl6-users <
perl6-us...@perl.org> wrote:

> Hi All,
>
> Okay, I clearly do not understand what is
> going on with these definitions, so please
> correct my assumptions!
>
>
> https://docs.raku.org/language/operators#infix_+
> https://docs.raku.org/routine/+$CIRCUMFLEX_ACCENT
>
> Question: would some kind soul please tell me how:
>
>   multi sub infix:<+>($a, $b --> Numeric:D)
>   multi sub infix:<+^>($a, $b --> Int:D)
>
> gets turned into
>
>   $c = $a +  $b,   and
>   $c = $a +^ $b
>
>
> This is what I understand so far about
> the definition lines:
>
> 1)  "multi" means there a several way to do things
>
> 2)  "sub" means subroutine:  $c = +($a, $b)
>
>  my $a=2; my $b=3; my $c = +($a, $b)
>  2
>
>   And a participation trophy for the wrong answer.
>
>  my $a=2; my $b=3; my $c = +^($a, $b)
>  -3
>
>   And I just won two a participation trophies!
>
>
> 3)  <> is a form of literal quote
>
> 4)  infix:<+> means you can call it as a sub that
>  gives you back the wrong answer.
>
>  $c = +($a, $b)
>  $c = +^($a, $b)
>
> 5)  --> Numeric:D means it return a Numeric and
>  --> Int:D means it "coerces" your stuff and
>  return an Int, like it or not.
>
> Yours in confusion,
> -T
>


Re: Bug to report: cardinal called an integer

2020-01-13 Thread Brad Gilbert
Ok looking into it, zero is inside of the set of cardinal numbers.

It is still wrong to call a uint a cardinal number.
It's just wrong for a different reason.

Looking through various definitions, a cardinal number is a number which
represents a count of sets.

So a uint could be used to represent a cardinal number, but it could just
as easily be a number that represents something other than a count.

If it is being used to index into a list it would be an ordinal number.
(And so definitely not a cardinal number.)

Calling them cardinal numbers would imply something about them that may or
may not be true.

If it is being used to store a bitmask, then it would be wrong to call it a
cardinal, ordinal, or even a natural number.

It may also be wrong to call it an integer, but at least that is what CPU
designers call it.


On Mon, Jan 13, 2020 at 1:51 PM ToddAndMargo via perl6-users <
perl6-us...@perl.org> wrote:

> On 2020-01-13 11:10, ToddAndMargo via perl6-users wrote:
> >
> > https://docs.raku.org/type/UInt
> > Subset UInt
> > Unsigned integer (arbitrary-precision)
> > The UInt is defined as a subset of Int:
> > my subset UInt of Int where {not .defined or $_ >= 0};
> > Consequently, it cannot be instantiated or subclassed;
> > however, that shouldn't affect most normal uses
>
> Trivia:
>
> In https://docs.raku.org/type/UInt, a cardinal (uint)
> is a subset
>
> In https://docs.raku.org/language/nativetypes, a
> cardinal (unit) gets their own "native type".
>
> Life in the documentation lane!
>
> :-)
>


Re: Bug to report: cardinal called an integer

2020-01-13 Thread Brad Gilbert
According to the description you copied, a cardinal can never be zero.

any of the numbers
that express amount, as one, two, three, etc.

So it is more accurate to call it an integer.

On Mon, Jan 13, 2020 at 1:32 AM ToddAndMargo via perl6-users <
perl6-us...@perl.org> wrote:

> On 2020-01-12 20:03, Darren Duncan wrote:
> > On 2020-01-09 10:10 a.m., ToddAndMargo via perl6-users wrote:
> >> A bug to report:
> >>
> >> $ p6 'my uint32 $c; $c = "ABC";'
> >> This type cannot unbox to a native integer: P6opaque, Str
> >>in block  at -e line 1
> >>
> >> "uint32" is not an "integer".  It is a cardinal.  If
> >> they really want to use the word "integer" for cardinal,
> >> they should change the wording to "unsigned integer".
> >>
> >> Picky, picky, picky
> >
> > ToddAndMargo, you are wrong on this.
> >
> > A uint32 is NOT specifically a cardinal.
>
> Hi Darren,
>
> Since a uint32 ca not be negative or a fraction,
> it is a cardinal.  Other operating system do call
> them cardinals, such as Modula2. Pascal, C++ (I
> think C too), Java, and so on and so forth.
>
> > At best you can say it can be characterized by a cardinal or be
> > isomorphic to one.
>
> https://www.dictionary.com/browse/isomorphism
> isomorphism
>  noun
>  Mathematics. a one-to-one relation onto the map
>  between two sets, which preserves the relations
>  existing between elements in its domain.
>
> I am not following what you are getting at.
>
> > A uint32 is just as much an ordinal as a cardinal, so insisting on
> > calling it a cardinal means the type can't be used as an ordinal, or a
> > variety of other things.
>
> https://www.dictionary.com/browse/ordinal-number
> ordinal number
> noun
> Also called ordinal numeral. any of the numbers that
> express degree, quality, or position in a series, as
> first, second, and third *(distinguished from cardinal
> number)*.
>
> Mathematics. a symbol denoting both the cardinal number
> and the ordering of a given set, being identical for
> two ordered sets having elements that can be placed
> into one-to-one correspondence, the correspondence
> preserving the order of the elements.
>
> https://www.dictionary.com/browse/cardinal-number
> cardinal number
> noun
> Also called cardinal numeral. any of the numbers
> that express amount, as one, two, three, etc.
> *(distinguished from ordinal number)*.
>
> No idea how you are mixing these two.  I can see
> how yo would use a cardinal in programming to
> denote an ordinal, if that is what you are getting at.
>
>
> > Calling this an unsigned integer (u int) is much more accurate as it
> > doesn't presume a particular semantics such as that we are storing a
> > count rather than a position for example, it says what we actually know,
> > and no more.
>
> I am sorry, I have no idea what you are trying to say.  I do not care if
> you call a cardinal an unsigned integer.  Just
> don't call it an integer.  The high bit in a cardinal is
> part of the number and denotes a negative number in an integer.
>
> >
> > You are also wrong on saying that the values one can store in a uint32
> > are not integers; they definitely ARE integers.  Every cardinal is an
> > integer.
>
> Where do you get that.  A cardinal can not be negative.  An
> Integer can.  And the structure is even different:  the high
> bit in an integer denote the sign of the integer; the high bit
> in a cardinal is just a higher positive number.  So they
> are not the same by any shake.
>
>
> > If you want to be precise, calling a uint32 an "unsigned integer" or
> > "cardinal" is inaccurate in the same way that calling it an "integer"
> > is.
>
> Perfectly accurate.  Unsigned integer and a cardinal are
> exactly the same thing.   The only difference is the
> amount of letter you need to use to describe them.
> Sort of like "associative array" and "hash"
>
> > In either case, the variable can only hold a proper subset of
> > either type, not all of them.  If you're calling integer wrong then one
> > will have to call the type something like "integers in the range
> > 0..^2**32".
> >
> > -- Darren Duncan
>
> The difference between a cardinal and an integer is
> the high bit.  Both are whole numbers.  An integer
> can be negative.  A cardinal can not.
>
> If you are going to error out something, say the proper
> variable type you are error out on.  Cardinal or unsigned
> integer, I don't care which you call a cardinal.  Whatever
> floats your boat.  Both descriptions are correct.  Just
> be correct.
>
> -T
>
> p.s. in assembly, they call a cardinal an unsigned integer.
>


Re: How do I convert integer to cardinal on the fly?

2020-01-07 Thread Brad Gilbert
  my int16 $x = 0xABCD;
  my uint16 $y = $x;

  say $x.base(16);
  say $y.base(16)

  -5433
  ABCD

If you just want to coerce to uint16

(my uint16 $ = $x)

say (my uint16 $ = $x).base(16)

On Tue, Jan 7, 2020 at 10:20 AM ToddAndMargo via perl6-users <
perl6-us...@perl.org> wrote:

> On 2020-01-06 22:54, ToddAndMargo via perl6-users wrote:
> > Hi All,
> >
> > What am I doing wrong here?
> >
> >  > my int16 $x = 0xABCD;
> > -21555
> >
> >  > say $x.base(16);
> > -5433
> >
> >  > my uint16 $y = $x.uint16;
> > No such method 'uint16' for invocant of type 'Int'
> >in block  at  line 1
> >
> > Many thanks,
> > -T
>
>
> Came up with a work around:
>
>   my int16 $x = 0xABCD;
>   my uint16 $y = $x +| 0x;
>   say $x.base(16);
>   say $y.base(16)
>
>   -5433
>   ABCD
>
> What is the proper way?
>


Re: null and native call question

2019-12-27 Thread Brad Gilbert
A Null pointer is just a pointer that points to the address 0.

So if you are dealing with it as an integer it will be 0.

On Fri, Dec 27, 2019 at 6:06 AM ToddAndMargo via perl6-users <
perl6-us...@perl.org> wrote:

> Hi All,
>
> https://docs.perl6.org/language/nativecall
>
>   "As you may have predicted by now, a NULL pointer
>   is represented by the type object of the struct type."
>
>
> https://docs.microsoft.com/en-us/windows/win32/api/winreg/nf-winreg-regqueryvalueexw
>
>   C++
>   LSTATUS RegQueryValueExW(
> HKEYhKey,
> LPCWSTR lpValueName,
> LPDWORD lpReserved,
> LPDWORD lpType,
> LPBYTE  lpData,
> LPDWORD lpcbData
>   );
>
>   lpReserved
>   This parameter is reserved and must be NULL.
>
> With "native", how do I satisfy the "NULL" requirement?
>
> constant WCHAR   := uint16;
>
> constant DWORD   := int32;
>
>
> sub RegQueryValueExW( DWORD, WCHARS, DWORD, DWORD, DWORD is rw, DWORD is
> rw ) is native("Kernel32.dll") returns DWORD { * };
>
> $RtnCode = RegQueryValueExW( $Handle, $lpValueName, int32, REG_DWORD,
> $lpData, $lpcbData );
>
> "int32" returns:
>
>  Cannot unbox a type object (int32) to int in method
>  CALL-ME at C:\rakudo\share\perl6\sources \947BDAB9F96E0E5FCCB383124F9
>  23A6BF6F8D76B (NativeCall) line 587
>
>
> Many thanks,
> -T
>


Re: about 'use v6.d'

2019-12-13 Thread Brad Gilbert
There should probably be a way to require a minimum version of the compiler.

use rakudo v2019.07;

On Fri, Dec 13, 2019, 3:14 AM MT  wrote:

> Hello all,
>
> In the light of renaming to Raku I was wondering if the statement 'use
> v6.*' is still useful.
>
> First there is no version 6 of Raku (should be version 0, but that's
> another story) and the 'use v5' in the past used for perl5 is also not
> used anymore (I think) (it is, I believe, more common to 'use
> Inline::Perl5').
>
> Also the 'd' of the Diwali version is a nice touch but my experience is
> that this is not accurate enough. I've used some new things of Raku
> introduced somewhere in summer 2019 but the version is still 6d. Also
> many bugs are fixed which requires newer versions to run right.
>
> So I must warn potential users of the software to install the newest
> Raku version, otherwise the programs/modules will run into problems.
>
> It would be nice to have this version extended, or maybe better, the
> version spec in META6.json so that the zef module installer could hold
> back the installation if the users Raku version is older. It is not
> enough to let tests fail on something the Raku compiler cannot handle
> because it is does not show that the compiler is too old when zef is
> installing modules.
>
> Regards
> Marcel
>


Re: Precedence: assignment vs smartmatch? (...was Re: where is my map typo)

2019-12-09 Thread Brad Gilbert
I meant that $_ is set to the left value while the right value is being
evaluated, and also while .ACCEPTS is called.

LEFT ~~ RIGHT

(Where LEFT and RIGHT represent some expression to be executed during
runtime.)

Imagine that underneath the hood, something like this is happening:

my $L-value = LEFT.evaluate();

given $L-value {
# $_ is temporarily the result of the LEFT expression

my $R-value = RIGHT.evaluate();
return $R-value.ACCEPTS($L-value);
}

So this:

« a b c ».join()   ~~   S/b/y/

is functionally the same as:

do given « a b c ».join() {
my $R-value = S/b/y/;
$R-value.ACCEPTS($_)
}

Note that $R-value will be "ayc"

"ayc".ACCEPTS("abc") == False

---

> $_.say
(Any)

> « a b c ».join()   ~~   -> $a { say "\$a = $a\n\$_ = $_" }
$a = abc
$_ = abc


> « a b c ».join()   ~~   ($_.say, -> $a { say "\$a = $a\n\$_ = $_"
}).tail
abc
$a = abc
$_ = abc

> $_.say
(Any)


On Mon, Dec 9, 2019 at 7:34 PM William Michels 
wrote:

> Thank you Brad, for your in-depth reply.
>
> There are parts of your reply that make perfect sense to me, and also
> parts where I am still confused. I feel I understand your first three
> examples (1,2,3) explaining how the smartmatch operator relates to
> ACCEPTS(). However in the second three examples explaining "S///"
> (also numbered 1,2,3), I'm confused on Your Step 2. I've tried
> numerous examples, a few of which are reproduced below:
>
> mbook:~ homedir$ perl6
> To exit type 'exit' or '^D'
> 1> my $a = « a b c ».join()
> abc
> 2> say $a ~~ s/b/y/
> 「b」
> 3> say $a
> ayc
> 4> my $probe = "AGCT"
> AGCT
> 5 > say $/ if $probe ~~ /"TCGA"/ ;
> ()
> 6> say $/ if $probe ~~ /"AGCT"/ ;
> 「AGCT」
> 7> say $/ if $probe ~~ s/"AGCT"/"TCGA"/ ;
> 「AGCT」
> 8> say $probe
> "TCGA"
> 9> say $/ if $probe ~~ S/"TCGA"/"AGCT"/ ;
> Potential difficulties:
> Smartmatch with S/// is not useful. You can use given instead:
> S/// given $foo
> --> say $/ if $probe ~~ S/"TCGA"/"AGCT"/ ;
> ()
> 10> say $probe
> "TCGA"
> 11> say $_
> abc
> 12> $*VM
> moar (2019.07.1)
> >
>
> For "S///" in your Step 1 the LHS is evaluated first (your Join
> example) and the LHS is temporarily set to $_. Then (your Step 2) the
> RHS is evaluated. Do you mean the RHS is evaluated in the context of
> $_ from the LHS?? Using your "abc" example I don't understand--if you
> **solely** look at the "S/b/./" operation--how  the letters "a" and
> "c" show up in your Step 2 intermediate result. Of course, Raku/Perl6
> may be far cleverer than I imagined--clever enough based on position
> and regex-rules (maybe) to simplify the two sides of the "S///"
> operator into a simple formula that can then be applied to the LHS.
>
> So in pseudocode, are you saying the following regarding "s///"
> (destructive-substitution) operation?
>
> 1. LHS:
> eval( "probe" ) --> $_ ;
>
> 2. RHS regex "target" between first two solidi of s/// or S/// :
> eval( "target".ACCEPTS( $_) );
>
> 3. for s///, if above evaluates to TRUE match from above gets assigned
> to $/ and LHS "probe" gets overwritten with appropriate "substitution"
> characters between second two solidi of s/// or S/// :
> ( "match" --> $/ ) ; ( RHS_"substitution" --> "probe" ) ;
>
> [ 4. for S///, there is no possibility that Step 2 will evaluate to
> TRUE, so $/ is Nil and LHS "probe" remains as unchanged ].
>
> If I'm close, please let me know. Meanwhile I will: 1) read over what
> you wrote again, and 2) play around with a little more example code,
> to gain a better understanding of what Raku/Perl6 is doing
> under-the-hood.
>
> Best Regards, Bill.
>
>
>
> On Sun, Dec 8, 2019 at 12:42 PM Brad Gilbert  wrote:
> >
> > smartmatch is among the most complex parts of the language.
> >
> > That complexity has to managed or it will be too complex to use
> effectively.
> >
> > To that end, the rules and order of operations are never altered.
> >
> > 1. The left side is evaluated first, and the resulting value captured
> >
> > > say('left') ~~ say('right')
> > left
> > right
> >
> > 2. $_ is temporarily set to that value, and the right side is executed
> >
> > > 'ab' ~ 'c'   ~~ say($_)
> > abc
>

Re: How do I do literal quotes in a regex?

2019-12-08 Thread Brad Gilbert
I like to use them, but I am not you.

On Sun, Dec 8, 2019 at 8:19 PM ToddAndMargo via perl6-users <
perl6-us...@perl.org> wrote:

> On 2019-12-08 18:04, Brad Gilbert wrote:
> > I do not quite understand the question.
> >
> > I told you how to directly enter unicode by remembering the codepoint.
> >
> > It's still the same characters.
> >
> > I would definitely recommend setting up, and getting used to Compose
> keys.
> >
> > I use them all the time for things like « » ‘ ’ “ ” ¹²³⁴⁵⁶⁷⁸⁹⁰¯⁺≠
>
> I was not asking if they were any good or not.
>
> I was asking if you thought someone like me, who
> would have to look the them up every time, should
> just stick with the what is on the keyboard.
>
> At times I have just had a list of them I could just
> copy and paste.
>
> Be nice if Geany would have an insert character function.
> (I use Geany as it is ssh X11 friendly.)
>


Re: How do I do literal quotes in a regex?

2019-12-08 Thread Brad Gilbert
I do not quite understand the question.

I told you how to directly enter unicode by remembering the codepoint.

It's still the same characters.

I would definitely recommend setting up, and getting used to Compose keys.

I use them all the time for things like « » ‘ ’ “ ” ¹²³⁴⁵⁶⁷⁸⁹⁰¯⁺≠

On Sun, Dec 8, 2019 at 6:46 PM ToddAndMargo via perl6-users <
perl6-us...@perl.org> wrote:

> On 2019-12-08 06:22, Brad Gilbert wrote:
> > Personally though I just use 「Ctrl+Shift+u f f 6 2 Space」 and
> > 「Ctrl+Shift+u f f 6 3 Space」
> >
>
> Hi Brad,
>
> Your technical opinion: is it better for maintainability
> to stick with escape sequences or to use the unicodes?
>
> I ask as I will never remember them.  I can only program
> on occasion as I am a jack of all trades.
>
> On the other hand, I currently have 190 keeper files
> (no fooling, I do not liek Raku's documentation) like
> the one I copied in these parts on the hashes.  191
> on unicodes would not hurt.  And I do have to reference
> the other 190 a lot, so it is not like it would be any
> extra work. Although, I an type and when my mind gets
> racing and my fingers can keep up, I really don't
> like to be slowed down.
>
> -T
>


Re: pass by reference

2019-12-08 Thread Brad Gilbert
Either use `rw` or `raw`

Use `rw` if you need it to be mutable.

Use `raw` if you just want to make sure you are getting the actual variable.

That really only applies to `$` parameters though.

---

`@` and `%` parameters are `raw` already.

sub pop-random( @_ ) {
@_.splice( (0..@_.elems).pick, 1 )
}

my @deck = 1..10;
say pop-random @deck; # 7
say @deck; # [1 2 3 4 5 6 8 9 10]


On Sun, Dec 8, 2019 at 1:26 PM Joseph Brenner  wrote:

> What's the sub signature incantation to
> pass-by-reference do you can act directly
> on the structure passed in without juggling
> an alias yourself?
>
>   # deal from middle
>   my $card = pop_random( @deck );
>


Re: Perl6 vs Julia

2019-12-08 Thread Brad Gilbert
>> The belief that Yet Another Programming Language is the answer to the
>> world's problems is a persistent, but (IMNSHO) a naive one.

Some people might think that applies to Raku.
Not me, but some people.

On Sun, Dec 8, 2019 at 2:09 PM Parrot Raiser <1parr...@gmail.com> wrote:

> Who initiated the project, and why?
> What deficiencies in existing languages are they trying to address?
>
> The belief that Yet Another Programming Language is the answer to the
> world's problems is a persistent, but (IMNSHO) a naive one.
>
> On 12/8/19, Andrew Shitov  wrote:
> > Let’s not hide the fact that Julia development raised 4.6 million dollars
> > and the language is production-ready.
> >
> > On Sun, 8 Dec 2019 at 12:46, JJ Merelo  wrote:
> >
> >> It might have been, but syntax is more Python-like to the point that in
> >> some cases it's exactly the same. It's got a very extensive macro
> >> systems,
> >> which enables it to work concurrently, for instance. It's more
> >> scientific-computing oriented, which means that there are all sort of
> >> mathematical modules for it, and not so many for web, databases, or
> >> things
> >> like that.
> >>
> >> El dom., 8 dic. 2019 a las 4:38, Tom Blackwood ( >)
> >> escribió:
> >>
> >>> Hello
> >>>
> >>> How do you think of Julia language?
> >>>
> >>> https://en.wikipedia.org/wiki/Julia_(programming_language)
> >>>
> >>> It says it is also influenced by perl language.
> >>>
> >>> Regards
> >>>
> >>
> >>
> >> --
> >> JJ
> >>
> > --
> > Andrew Shitov
> > __
> > a...@shitov.ru | http://shitov.ru
> >
>


Re: Precedence: assignment vs smartmatch? (...was Re: where is my map typo)

2019-12-08 Thread Brad Gilbert
has said): "smartmatch with S///
> > (or TR///) is not useful." Conversely, I've also found another
> > smartmatch construct that is useless (i.e. disallowed):
> >
> > > my $r = 'abc' ~~ { S/b/./ }
> > a.c
> > > my $s = 'abc' ~~ { s/b/./ }
> > Cannot modify an immutable Str (abc)
> >   in block  at  line 1
> > >
> >
> > No matter how "discouraged' a particular syntax is, people are going
> > to run into these disallowed syntaxes and wonder why. Could it be due
> > to precedence? These two prohibited operations beg the question: can a
> > definitive statement be made regarding the precedence of the
> > smartmatch operator relative to either lowercase-triple-solidus
> > operators such as s/// and tr/// , or relative to
> > uppercase-triple-solidus operators such as S/// and TR/// ?
> >
> > This really makes me wonder if anyone has plans to add "~~" (the
> > smartmatch operator) to the precedence table that can be found
> > below--and where in the table the smartmatch operator would precisely
> > sit:
> >
> > https://docs.raku.org/language/operators#Operator_precedence
> >
> > Best Regards, Bill.
> >
> >
> >
> >
> > On Sat, Dec 7, 2019 at 7:53 AM Brad Gilbert  wrote:
> > >
> > > The return value of s/// is the same as $/
> > >
> > > If you want the resulting string instead you can use S/// instead.
> > >
> > > > $_ = 'abc'
> > > > my $r = S/b/./
> > > > say $r
> > > a.c
> > >
> > > Note that it warns you try to use S/// with ~~
> > >
> > > > my $r = 'abc' ~~ S/b/./
> > > Potential difficulties:
> > > Smartmatch with S/// is not useful. You can use given instead:
> S/// given $foo
> > > --> my $r = 'abc' ~~ S/b/./
> > > False
> > >
> > > Which gives you an indicator of how to fix it
> > >
> > > > my $r = S/b/./ given 'abc'
> > > a.c
> > >
> > > Note that the `given` happens before the `=`
> > >
> > > So it works the same as
> > >
> > > > my $r = ( S/b/./ given 'abc' )
> > > a.c
> > >
> > > ---
> > >
> > > The reason ~~ doesn't work with S/// has to do with the dual pass
> nature of ~~.
> > >
> > > Without getting into details, you can avoid that by delaying the S///
> until the second pass.
> > >
> > > > my $r = 'abc' ~~ { S/b/./ }
> > > a.c
> > >
> > > Or you can just set $_ to the value.
> > > (Which is basically what the previous line is doing.)
> > >
> > > > my $r = S/b/./ given 'abc'
> > >
> > > > given 'abc' {
> > > >   my $r = S/b/./
> > > >   …
> > > > }
> > >
> > > > my $_ = 'abc'
> > > > my $r = S/b/./
> > >
> > > > my $r = 'abc' ~~ -> $_ { S/b/./ }
> > >
> > > > my $r = 'abc' ~~ sub ( $_ ) { S/b/./ }
> > >
> > > > my $r = 'abc' ~~ anon sub foo ( $_ ) { S/b/./ }
> > > ---
> > >
> > > One of design goals of Raku is to have as few special cases as
> possible.
> > > Which is why ~~ and S/// haven't been made to just work.
> > >
> > > (It could be argued that in this case an exception could be made. But
> I'm not going to argue for it.)
> > >
> > > On Fri, Dec 6, 2019 at 10:37 PM William Michels via perl6-users <
> perl6-us...@perl.org> wrote:
> > >>
> > >> Hello All,
> > >>
> > >> Todd put up some interesting code yesterday using the Raku/Perl6 REPL,
> > >> which I reproduced with no problem. Additionally I tried some
> > >> variations removing and/or moving parentheses to a different location,
> > >> and have numbered the relevant REPL lines 1 through 6:
> > >>
> > >> mbook:~ homedir$ perl6
> > >> To exit type 'exit' or '^D'
> > >> 1> my $x = Q[word] ;
> > >> word
> > >> 2> (my $y = $x) ~~ s/ '<' .* //; say $/; say $x; say $y;
> > >> 「」
> > >> word
> > >> word
> > >> 3> my $a = Q[word] ;
> > >> word
> > >> 4> my $b = ($a ~~ s/ '<' .* //); say $/; say $a; say $b;
> > >> 「」
> > >> word
> > >> 「」
> > >> > my $c = Q[word] ;
> > >>

Re: How do I do literal quotes in a regex?

2019-12-08 Thread Brad Gilbert
I would recommend setting up a compose key.

But that is not enough because I don't think it has a binding for those two
characters.

So you would also have to modify the config to include them.

I think that 「Compose [ [ 」 and 「Compose ] ] 」 might be what I would set
them as.

Note that 「‘」 is 「Compose < ' 」 and  「’」 is 「Compose > ' 」 along with 「“」
and 「”」 being 「Compose < " 」 and 「Compose > " 」



Personally though I just use 「Ctrl+Shift+u f f 6 2 Space」 and 「Ctrl+Shift+u
f f 6 3 Space」

So basically I just remember how to directly type in Unicode codepoints,
and those the two codepoints.

On Sun, Dec 8, 2019 at 6:56 AM ToddAndMargo via perl6-users <
perl6-us...@perl.org> wrote:

>  > On Sat, Dec 7, 2019 at 12:51 AM ToddAndMargo via perl6-users
>  > mailto:perl6-us...@perl.org>> wrote:
>  >
>  > Hi All,
>  >
>  > Is there a `Q[]` that can be used in a regex?
>  >
>  > I am looking for how to get around
>  >
>  > my $x = Q[\:\\::]; ( my $y = $x ) ~~ s/ '' /x/; say $y
>  > \:x::
>  >
>  > This does not work:
>  > my $x = Q[\:\\::]; ( my $y = $x ) ~~ s/ Q[\\] /x/; say $y
>  > \:\\::
>  >
>  > Nor does this:
>  > my $x = Q[\:\\::]; ( my $y = $x ) ~~ s/ [\\] /x/; say $y
>  > x:\\::
>  >
>  > Many thanks,
>  > -T
>
> On 2019-12-07 07:02, Brad Gilbert wrote:
> > The shortcut spelling of Q[…] is to use 「 and 」 (U+FF62  and U+FF63)
> >
> >  my $x = 「\:\\::」; ( my $y = $x ) ~~ s/ 「\\」 /x/; say $y
> >  \:\\::
> >
> > The case could be made that \Q[\\] should work as well. (It would need
> > to be added).
> > (Along with \q[…] and \qq[…])
> >
> > Note that \Q[…] doesn't work in string literals currently either. While
> > \q[…] and \qq[…] do.
> >
> >  > "\q[\n]\n"
> >  \n␤
> >
> >  > '\n\qq[\n]'
> >  \n␤
> >
> > Note that single and double quotes also work in regexs.
> >
> > The three of them ('…' "…" 「…」) have a few jobs.
> >
> > 1. They escape spaces and other non-alphanumerics.
> >
> >  > 'a b c' ~~ / 'a b c' /
> >  Nil
> >  > 'a b c  A B C' ~~ / :i  'a b c' /
> >  A B C
> >
> >  > 'a b c' ~~ / 'a . c' /
> >  Nil
> >  > 'a . c' ~~ / 'a . c' /
> >  a . c
> >
> > Note that the rules for the string literal still apply.
> >
> > > "abc\n" ~~ / 'abc\n' /
> > Nil
> > > "abc\n" ~~ / "abc\n" /
> > abc␤
> >
> > 2. They group characters as a single atom.
> > (Meaning they behave a bit like [] in a regex)
> >
> >  > 'abccd' ~~ / 'abc'+ d /
> >  Nil
> >  > 'abccd' ~~ / [abc]+ d /
> >  Nil
> >
> >  > 'abccd' ~~ / abc+ d /
> >  abccd
> >
> >  > 'abccd   abcABCabcd' ~~ / :i 'abc'+ d /
> >  abcABCabcd
> >  > 'abccd   abcABCabcd' ~~ / :i [abc]+ d /
> >  abcABCabcd
> >
> > Note that '…' in a regex behaves like '…' outside of one, as well as "…"
> > behaving like "…" and 「…」 behaving like 「…」
>
> Hi Brad,
>
>That was above and beyond!  Thank you!
>
> my $x = Q[\:\\::]; ( my $y = $x ) ~~ s/ 「\\」 /x/; say $y
> \:x::
>
> What is the easiest way to get those weird brackets in Fedora31?
>
> -T
>


Re: Precedence: assignment vs smartmatch? (...was Re: where is my map typo)

2019-12-07 Thread Brad Gilbert
The return value of s/// is the same as $/

If you want the resulting string instead you can use S/// instead.

> $_ = 'abc'
> my $r = S/b/./
> say $r
a.c

Note that it warns you try to use S/// with ~~

> my $r = 'abc' ~~ S/b/./
Potential difficulties:
Smartmatch with S/// is not useful. You can use given instead: S///
given $foo
--> my $r = 'abc' ~~ ⏏S/b/./
False

Which gives you an indicator of how to fix it

> my $r = S/b/./ given 'abc'
a.c

Note that the `given` happens before the `=`

So it works the same as

> my $r = ( S/b/./ given 'abc' )
a.c

---

The reason ~~ doesn't work with S/// has to do with the dual pass nature of
~~.

Without getting into details, you can avoid that by delaying the S/// until
the second pass.

> my $r = 'abc' ~~ { S/b/./ }
a.c

Or you can just set $_ to the value.
(Which is basically what the previous line is doing.)

> my $r = S/b/./ given 'abc'

> given 'abc' {
>   my $r = S/b/./
>   …
> }

> my $_ = 'abc'
> my $r = S/b/./

> my $r = 'abc' ~~ -> $_ { S/b/./ }

> my $r = 'abc' ~~ sub ( $_ ) { S/b/./ }

> my $r = 'abc' ~~ anon sub foo ( $_ ) { S/b/./ }
---

One of design goals of Raku is to have as few special cases as possible.
Which is why ~~ and S/// haven't been made to just work.

(It could be argued that in this case an exception could be made. But I'm
not going to argue for it.)

On Fri, Dec 6, 2019 at 10:37 PM William Michels via perl6-users <
perl6-us...@perl.org> wrote:

> Hello All,
>
> Todd put up some interesting code yesterday using the Raku/Perl6 REPL,
> which I reproduced with no problem. Additionally I tried some
> variations removing and/or moving parentheses to a different location,
> and have numbered the relevant REPL lines 1 through 6:
>
> mbook:~ homedir$ perl6
> To exit type 'exit' or '^D'
> 1> my $x = Q[word] ;
> word
> 2> (my $y = $x) ~~ s/ '<' .* //; say $/; say $x; say $y;
> 「」
> word
> word
> 3> my $a = Q[word] ;
> word
> 4> my $b = ($a ~~ s/ '<' .* //); say $/; say $a; say $b;
> 「」
> word
> 「」
> > my $c = Q[word] ;
> word
> > my $d = $c ~~ s/ '<' .* //; say $/; say $c; say $d;
> 「」
> word
> 「」
> 7> $*VM
> moar (2019.07.1)
>
> Working in groups of 2, lines 1 and 2 replicate the code Todd put up
> (parenthesis surrounding everything to the left of the smartmatch
> operator). I get the same result as Todd. What interests me are lines
> 3 through 6. Lines 3 and 4 are the virtually the same code but with
> parentheses surrounding everything to the right hand side (RHS) of the
> assignment operator (" = "). As people will note, lines 2 and lines 4
> give different results. Removing parentheses entirely in line 6 gives
> the same result as in line 4. Because the results in line 4 and line 6
> are the same, this says that as far as parentheses are concerned, the
> smartmatch operator "~~" takes precedence over the assignment operator
> "=".
>
> What's not clear to me in the code above (lines 4 and 6) is why
> variables $b and $d get assigned to $/. I would have expected in line
> 4 that $a would have been matched against the smartmatch, and the
> result ("word") would have been simply copied into variable $b. Have I
> misunderstood?
>
> Anyway, I'm just hoping to start a conversation on the topic of
> precedence in general, and hopefully getting some feedback as to where
> to look in the docs for further instruction.
>
> Best Regards, Bill.
>
>
> On Fri, Dec 6, 2019 at 12:15 AM ToddAndMargo via perl6-users
>  wrote:
> >
> > On 2019-12-05 23:19, ToddAndMargo via perl6-users wrote:
> > > On 2019-12-05 03:09, William Michels via perl6-users wrote:
> > >> What happens when you type "perl6" or "raku" at the bash command
> prompt?
> > >
> > > Hi William,
> > >
> > > On my shop machine, it jumps to the next line with an
> > > empty flashing cursor
> > >
> > > On my office machine, it told me to install
> > >  zef install Readline
> > >
> > > After that, I get:
> > >
> > > $ perl6
> > > To exit type 'exit' or '^D'
> > >  >
> > >
> > > and
> > >
> > >  > say "hello World"
> > > hello World
> > >  > say "B" ~ Q[:\] ~ " drive dismounted"
> > > B:\ drive dismounted
> > >  >
> > >
> > > and sticking an obvious booboo into it
> > >
> > >  > if 3 % 2 = 1 {say "odd"};
> > > Cannot modify an immutable Int (1)
> > >in block  at  line 1
> > >
> > > Plus I can use the arrow keys to recall previous lines too.
> > >
> > > Time up update my Perl6 on my shop computer!
> > >
> > > No more hassling with `perl6 -e` !!!
> > >
> > > Dude!  THANK YOU !!
> > >
> > > -T
> >
> > You've created a monster!!
> >
> > perl6
> > To exit type 'exit' or '^D'
> >  > my $x = Q[]
> > 
> >  > say $x
> > 
> >  > (my $y = $x ) ~~ s/ Q[<] .* //;
> > ===SORRY!=== Error while compiling:
> > Unrecognized regex metacharacter < (must be quoted to match literally)
> > --> (my $y = $x ) ~~ s/ Q[<] .* //;
> >  > my $x = Q[abc]
> > abc
> >  > (my $y = $x ) ~~ s/ '<' .* //;
> > 

Re: How do I do literal quotes in a regex?

2019-12-07 Thread Brad Gilbert
The shortcut spelling of Q[…] is to use 「 and 」 (U+FF62  and U+FF63)

my $x = 「\:\\::」; ( my $y = $x ) ~~ s/ 「\\」 /x/; say $y
\:\\::

The case could be made that \Q[\\] should work as well. (It would need to
be added).
(Along with \q[…] and \qq[…])

Note that \Q[…] doesn't work in string literals currently either. While
\q[…] and \qq[…] do.

> "\q[\n]\n"
\n␤

> '\n\qq[\n]'
\n␤

Note that single and double quotes also work in regexs.

The three of them ('…' "…" 「…」) have a few jobs.

1. They escape spaces and other non-alphanumerics.

> 'a b c' ~~ / 'a b c' /
Nil
> 'a b c  A B C' ~~ / :i  'a b c' /
A B C

> 'a b c' ~~ / 'a . c' /
Nil
> 'a . c' ~~ / 'a . c' /
a . c

Note that the rules for the string literal still apply.

   > "abc\n" ~~ / 'abc\n' /
   Nil
   > "abc\n" ~~ / "abc\n" /
   abc␤

2. They group characters as a single atom.
(Meaning they behave a bit like [] in a regex)

> 'abccd' ~~ / 'abc'+ d /
Nil
> 'abccd' ~~ / [abc]+ d /
Nil

> 'abccd' ~~ / abc+ d /
abccd

> 'abccd   abcABCabcd' ~~ / :i 'abc'+ d /
abcABCabcd
> 'abccd   abcABCabcd' ~~ / :i [abc]+ d /
abcABCabcd

Note that '…' in a regex behaves like '…' outside of one, as well as "…"
behaving like "…" and 「…」 behaving like 「…」


On Sat, Dec 7, 2019 at 12:51 AM ToddAndMargo via perl6-users <
perl6-us...@perl.org> wrote:

> Hi All,
>
> Is there a `Q[]` that can be used in a regex?
>
> I am looking for how to get around
>
> my $x = Q[\:\\::]; ( my $y = $x ) ~~ s/ '' /x/; say $y
> \:x::
>
> This does not work:
> my $x = Q[\:\\::]; ( my $y = $x ) ~~ s/ Q[\\] /x/; say $y
> \:\\::
>
> Nor does this:
> my $x = Q[\:\\::]; ( my $y = $x ) ~~ s/ [\\] /x/; say $y
> x:\\::
>
> Many thanks,
> -T
>


Re: comment on the new name change

2019-12-06 Thread Brad Gilbert
History lesson:

Rakudo is short for Rakuda Do

Rakuda Do is supposed to have meant "the way of the camel"

The first book about Perl was Learning Perl. It had a Camel on the front
cover.
(Note also that the name of the butterfly logo is named Camelia, and that
the first 5 characters spell Camel.)

Rakudo means Paradise.

So there are two reasons Rakudo was chosen for the name of the compiler.

Raku is of course the first 4 letters of Rakudo.

Raku means comfort, ease, or relief.

Raku is also a form of pottery.
(This seems like it might be a coincidence, but knowing Larry it may be
intentional.)

The design of the Raku language is so cohesive that even the new name has
more than one reason it was chosen.

On Fri, Dec 6, 2019 at 2:12 AM ToddAndMargo via perl6-users <
perl6-us...@perl.org> wrote:

> Hi All,
>
> I personally do not care if we call Perl 6 "The Flying
> Zucchini".
>
> But what I really like is that I can now to a web search
> on "raku" and not get 3,264,682,533 hits on Perl 5
> that I have to frustratingly sort through to find what
> I want.
>
> So I am a happy camper with the new name.
>
> Just out of curiosity, was this the intention
> of the new name?
>
> https://www.thoughtco.com/raku-meaning-and-characters-2028515
>
>  The Japanese word raku, pronounced "rah-koo", is a
>  commonly-used word that means comfort, ease, or
>  relief.
>
> Having used several other programming languages in
> my lifetime, if this was the intention, I do have to
> say the name fits
>
> :-)
>
> -T
>


Re: which windows am I in?

2019-11-23 Thread Brad Gilbert
Windows before Windows 10 had different internal and external numbers.

https://www.gaijin.at/en/infos/windows-version-numbers

On Sat, Nov 23, 2019, 2:03 AM ToddAndMargo via perl6-users <
perl6-us...@perl.org> wrote:

> On 2019-11-22 23:41, ToddAndMargo via perl6-users wrote:
> > Hi All,
> >
> > In Perl6 for Windows, how do I tell if I am
> > in Windows 7 or 10?
> >
> > Many thanks,
> > -T
>
> What I have so far:
>
> Windows 6.  I am not even going to ask...
>
>
> Windows version:
>
> Windows 10:
>
> C:\>ver
> Microsoft Windows [Version 10.0.18363.476]
>
> perl6 -e "my $Rtn = qx ( ver ); my $Ver = $Rtn.lines[1].words[3]; $Ver
> ~~ s/ \] //; $Ver ~~ s/ \. .* //; say $Ver;"
> 10
>
>
>
> Windows 7:
>
> C:\>ver
> Microsoft Windows [Version 6.1.7601]
>
> perl6 -e "my $Rtn = qx ( ver ); my $Ver = $Rtn.lines[1].words[3]; $Ver
> ~~ s/ \] //; $Ver ~~ s/ \. .* //; say $Ver;"
> 6
>


Re: Question about "colon syntax" for calling other methods on 'self' inside a method

2019-11-19 Thread Brad Gilbert
$ by itself is a an anonymous state variable.

So these two lines would be exactly the same.

$.foo
(state $).foo

A feature was added where $.foo would instead be used for public attributes.
Since a public attribute just adds a method, it was allowed to use it to
call any method.
Which probably made it simpler to add.
(Note that calling a method on an anonymous variable doesn't make much
sense anyway, so there is no big loss.)

Basically it was made so that these two lines would be the same:

$.foo
$( self.foo() )

Using : on the method was probably just overlooked, because that is not
what that feature is meant for.

On Tue, Nov 19, 2019 at 12:04 AM Raymond Dresens 
wrote:

> Hello Vadim, Yary,
>
> Thanks for your feedback,
>
> I've filed an issue: https://github.com/rakudo/rakudo/issues/3306
>
> Yary, about the dollar sign,
>
> The snippet of code in the issue shows that expression "$.attribute"
> inside a method 'just works' for accessing individual attributes (or
> rather: implicitly invoking their accessors?), suggesting [to me] that the
> variable '$' can be used in the context of method lookup on "self". I would
> expect that it would work too when I try to invoke an attribute as a
> method...
>
> ...though solely printing '$' in a method yields "(Any)", not the same as
> printing "self"! Indeed: there's more going on that meets the eye, which
> makes me curious ;) Perhaps the docs mention why, I'll look for that when I
> have the opportunity to do so,
>
> Regards,
>
> Raymond.
>
> On Mon, 18 Nov 2019 at 18:13, Vadim Belman  wrote:
>
>>
>> I would say filing an issue might make sense in this case. Here is a
>> related comment from Jonathan:
>> https://github.com/rakudo/rakudo/issues/3222#issuecomment-539915286 –
>> and it explicitly states that $. is a shortcut for method calling.
>> Therefore, use of colon instead of braces should be a valid construct.
>>
>> Best regards,
>> Vadim Belman
>>
>> On Nov 18, 2019, at 11:40 AM, yary  wrote:
>>
>> I take that back! What is the dollar sign doing there in the '$.print:
>> ..." example?
>>
>> Try it without the dollar sign. Right now you're calling .print on the
>> anonymous variable '$'
>>
>> -y
>>
>>
>> On Mon, Nov 18, 2019 at 8:38 AM yary  wrote:
>>
>>> looks like a bug to me-file an issue on the rakudo GitHub
>>>
>>> On Sat, Nov 16, 2019 at 5:29 AM Raymond Dresens <
>>> raymond.dres...@gmail.com> wrote:
>>>
 Hello,

 I have a question related to the 'colon syntax' of Raku, which allows
 you to call methods without parenthesis like this:

 class Foo
 {
 method print($x, $y)
 {
 say "bar: {$x}, {$y}"
 }
 }

 my $a = Foo.new;

 $a.print: 3, 5; # ...this is what i mean with "colon syntax" ;)

 It is possible to use this syntax to call methods on 'self' as well:

 class Bar is Foo
 {
 method printDefault
 {
 self.print: 8, 12
 }
 }

 my $b = Bar.new;

 $b.printDefault;

 I use $. rather than 'self' in order to work with attributes inside
 methods in my classes, well, ... mostly, because it does not seem
 possible to do this (in rakudo, at least version 2019.07.1):

 class Baz is Foo
 {
 method printDefault
 {
 $.print: 8, 12
 }
 }

 This yields a "Confused" error, stating that it expects a so-called
 'colon pair'.

 Is this intentional? Because I'm kind of confused as well about this,

 I can live with this 'syntactical quirk', but I just keep wondering
 about it because I'd personally expect that this "$.methodname: $args"
 variant should "just work" as well...

 ...so "what gives"? ;)

 Thanks for your insights!

 Regards,

 Raymond.

>>> --
>>> -y
>>>
>>
>>


Re: processing a file in chunks

2019-10-22 Thread Brad Gilbert
CatHandle is the mechanism behind $*ARGFILES.

If you want to read several files as it they were one, you can use
IO::CatHandle.

my $combined-file = IO::CatHandle.new( 'example_000.txt', *.succ ...
'example_010.txt' );

Basically it works similar to the `cat` command-line utility. (Hence its
name)

The reason it is read-only, is because it is difficult to figure out which
file you actually want to write to.

Imagine you read the first file, and then wrote something.
Should it write to the end of the first file, or the beginning of the
second file?

On Tue, Oct 22, 2019 at 2:08 PM Marcel Timmerman  wrote:

> On 10/22/19 3:03 PM, Parrot Raiser wrote:
> > CatHandle? Is that an alias for "tail"?  :-)*
> hehe, that's a nice word change... Well, I've seen it here at
> https://docs.perl6.org/routine/readchars
>
> But there's also IO::Handle  What I've understood is that the
> CatHandle does the same as a readonly IO::Handle can. Writing will throw
> exceptions. So in the end it looks like the Unix tail program.
>
> Marcel
> >
> > On 10/22/19, Marcel Timmerman  wrote:
> >> On 10/22/19 1:05 PM, Marcel Timmerman wrote:
> >>> On 10/20/19 11:38 PM, Joseph Brenner wrote:
>  I was just thinking about the case of processing a large file in
>  chunks of an arbitrary size (where "lines" or "words" don't really
>  work).   I can think of a few approaches that would seem kind-of
>  rakuish, but don't seem to be built-in anywhere... something like a
>  variant of "slurp" with an argument to specify how much you want to
>  slurp at a time, that'll move on to the next chunk the next time it's
>  invoked...
> 
>  Is there anything like that kicking around that I've missed?
> >>> as a side note, there is also a .IO.CHandle.readchars($size), with
> >>> $size a default of 64 kb.
> >>>
> >>> Regards,
> >>> Marcel
> >> I meant  .IO.CatHandle.readchars($size)
> >> sorry
> >> M
> >>
>


Re: What is a LoweredAwayLexical?

2019-10-22 Thread Brad Gilbert
The optimizer can lower lexical variables into local variables.

When it does so, it keeps track of this so that it can give you this error
message.

The `given` block and the `when` blocks are optimized away.

If you move the first `$a` declaration to inside the `given` block the
error goes away.

I think what is happening is that somehow both `$a` variables are
coalescing into the same local variable.

This is definitely an optimizer bug.

This is not really a LTA error message bug, because the runtime doesn't
have any more information to give you.


On Tue, Oct 22, 2019 at 5:37 PM Kevin Pye  wrote:

> Yesterday I created a new when clause in an existing working program,
> which worked fine, but today when I came to exercise another previously
> working when clause it was broken.
>
> The golfed version...
>
> my $a = 41;
>
> given 6 {
> when 5 {
> my $a;
> }
> when 6 {
> say $a + 1;
> }
> }
>
> When run with various version of rakudo (at least on 2019.07.1 and current
> HEAD) this produces
>
> Use of uninitialized value of type Rakudo::Internals::LoweredAwayLexical
> in numeric context
>
> Is this expected? If nothing else, the error message is decidedly LTA.
>
> I fixed it in my case by removing the unnecessary redeclaration of $a in
> the when clause, but there might be times when that is incorrect.
>
> (And on a side note, are there plans to move this mailing list to
> raku-users@somewhere? There's nothing about it in the path to raku
> document.)
>
> Kevin.
>


Re: order of execution

2019-10-21 Thread Brad Gilbert
Programs are compiled in memory, it just isn't written out to disk.

On Mon, Oct 21, 2019 at 3:33 AM Marcel Timmerman  wrote:

> @yary
>
> Thanks for your answer. I've done it too and saw the same kind of result.
> But then I thought I've read it somewhere that programs are not compiled,
> only modules. So I must write a module to check it.
>
> But if anyone knows, it would be faster ;-)
>
> Regards,
>
> marcel
> On 20-10-2019 22:59, yary wrote:
>
> Seems like we can answer "Is it also true when compiling?" by putting the
> REPL code into a file!
>
> $ cat order-execution.raku
> class Y { method  y (Int $y) {note $y}}
> my Y $y .= new;
>
> sub b (Int $i --> Int) { note "about to increment i above $i"; $i + 10 }
>
> say b(10);
>
> say $y.?y(b(11));
>
> say $y.?undef(b(12));
>
> $ perl6 order-execution.raku
> about to increment i above 10
> 20
> about to increment i above 11
> 21
> True
> about to increment i above 12
> Nil
>
> $ perl6 --version
> *This is Rakudo Star version 2019.03.1 built on MoarVM version 2019.03 
> **implementing
> Perl 6.d.*
>
> Yes Rakudo is executing the args for something that it doesn't end up
> calling. Seems overly-eager for a language that is properly lazy by design.
> I'd be interested in seeing documentation for this order-of-operations if
> it exists.
>
> By the way I had to look up .? -
> https://docs.perl6.org/language/operators#index-entry-methodop_.%3F
>
> methodop .? 
>
> Safe call operator. $invocant.?method calls method method on $invocant if
> it has a method of such name. Otherwise it returns Nil
> .
>
> Technically, not a real operator; it's syntax special-cased in the
> compiler.
>
> -y
>
>
> On Sun, Oct 20, 2019 at 10:12 AM Marcel Timmerman 
> wrote:
>
>> Hello all,
>>
>> I've a small question where I want to know what is processed first in
>> the following line
>>
>>
>> $my-object.?"my-method"(some-complex-argument-calculation())
>>
>>
>> Will the sub 'some-complex-argument-calculation()' always be run even
>> when 'my-method' is not available because the sub must be executed
>> before the method is called.
>>
>>
>> In the REPL the sub is called despite a method is not defined. Is it
>> also true when compiling?
>>
>>
>>  > class Y { method  y (Int $y) {note $y}}
>> (Y)
>>
>>  > my Y $y .= new
>> Y.new
>>
>>  >sub b (Int $i --> Int) { note "$i"; $i + 10 }
>> 
>>
>>  > b(10)
>> 10
>> 20
>>
>>  > $y.?y(b(10))
>> 10
>> 20
>> True
>>
>>  > $y.?undef(b(10))
>> 10
>> Nil
>>
>>
>> Regards
>> Marcel
>>
>


  1   2   3   >