Re: Array remove duplicates question

2024-05-06 Thread yary
I thought you wanted them sorted also?

[1] > (8,7,6,7,5,4,2,1).unique
(8 7 6 5 4 2 1)
[2] > (8,7,6,7,5,4,2,1).unique.sort
(1 2 4 5 6 7 8)


-y


On Mon, May 6, 2024 at 6:15 AM ToddAndMargo via perl6-users <
perl6-users@perl.org> wrote:

> On 5/6/24 03:07, ToddAndMargo via perl6-users wrote:
> >
> >>> On 6 May 2024, at 04:35, ToddAndMargo via perl6-users
> >>>  wrote:
> >>>
> >>> Hi All,
> >>>
> >>> I have thought of how to do it and pretty sure
> >>> it would work, but just in case Raku have one
> >>> of those sweet utilities, does Raku have a
> >>> utility that will take an array and remove all
> >>> the duplicates and rearrange the cells back
> >>> in order?
> >>>
> >>> Many thanks,
> >>> -T
> >
> > On 5/6/24 01:59, Elizabeth Mattijsen wrote:
> >  > $ raku -e 'my @a = 1,2,3,6,7,1,2,8; @a .= unique; say @a'
> >  > [1 2 3 6 7 8]
> >  >
> >  > https://docs.raku.org/type/Any#method_unique
> >  >
> >
> > I knew there had to be something!   Thank you!
>
> My keeper:  perl6.array.duplicates.unique.txt
>
>
> Raku (perl6): how to remove duplicates from an array:
>
> Use `unique` and `.=`
>
> For example:
>
> $ raku -e 'my @a = 1,2,3,6,7,1,2,8; @a .= unique; say @a'
> [1 2 3 6 7 8]
>
> $ raku -e 'my @a = "abc","DEF","abc","jkl",1,2,8; @a .= unique; say @a'
> [abc DEF jkl 1 2 8]
>
> $ raku -e 'my @a = "abc","DEF","abc","jkl",1; @a .= unique; say @a'
> [abc DEF jkl 1]
>
> $ raku -e 'my @a = "abc","DEF","abc","jkl",1,8,1,2,8; @a .= unique; say @a'
> [abc DEF jkl 1 8 2]
>
>
>


Re: need native call help

2024-04-18 Thread yary
I did a lot of very deep windows programming in my previous job and
reminding me that I would always use the 8.3 short name for file
operations! dir /x will get it for you. Must be API called for it also.
Probably only works on local volumes not network rounded ones. Just a guess.

I've run into problems on some unix shells with maximum command-line
lengths.

-y


On Wed, 17 Apr 2024 at 11:58 PM, ToddAndMargo via perl6-users <
perl6-users@perl.org> wrote:

> On 4/17/24 19:10, William Michels via perl6-users wrote:
> > Hi Todd,
> >
> > Here are a few U&L StackExchange answers that I wrote using Raku's
> `unlink`:
> >
> >
> https://unix.stackexchange.com/questions/459521/how-to-truncate-file-to-maximum-number-of-characters-not-bytes/751267#751267
> >
> >
> https://unix.stackexchange.com/questions/749558/remove-exact-line-from-file-if-present-leave-the-rest-of-lines-error-handling/749581#749581
> >
> > (Suggestions welcome).
>
>
> Hi William,
>
> unlink($_) if $bak.IO:e & $bak.IO:f;
>
> Interesting!  Thank you.
>
> The problem is that you can not implicitly trust
> the file operations when programming on the kluge.
> Linux, no problem.
>
> I wish I had more Linux customers, but I do not.
>
> -T
>
> I do not know if you are, but I just append .tmp or .bak on to the name
> of my program.   I have never used Kernel32::GetTempTileNameA.
>
>
> https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-gettempfilenamea
>


Re: need native call help

2024-04-17 Thread yary
>From unlink's documentation:

 If the file to be deleted does not exist, the routine treats it as success.

So trying to delete a file that isn't there, doesn't have an error, which
is kind of neat, but that is a difference from native delete.

-y


On Wed, Apr 17, 2024 at 8:50 AM yary  wrote:

> What does the windows native delete do which you need, that raku's unlink 
> doesn't
> have?
>
> without unlink $FileName { say "Could not delete $FileName:", 
> .exception.message
> };
>
> -y
>
>
> On Wed, Apr 17, 2024 at 2:29 AM ToddAndMargo via perl6-users <
> perl6-users@perl.org> wrote:
>
>> On 4/16/24 23:25, ToddAndMargo via perl6-users wrote:
>> `\\>\` should have been
>> `\\?\`
>>
>>


Re: need native call help

2024-04-17 Thread yary
What does the windows native delete do which you need, that raku's
unlink doesn't
have?

without unlink $FileName { say "Could not delete $FileName:",
.exception.message
};

-y


On Wed, Apr 17, 2024 at 2:29 AM ToddAndMargo via perl6-users <
perl6-users@perl.org> wrote:

> On 4/16/24 23:25, ToddAndMargo via perl6-users wrote:
> `\\>\` should have been
> `\\?\`
>
>


Re: I need sorting help

2024-03-09 Thread yary
Using my quick-intuition, are these methods sorting on the earliest number
withing the string, ignoring the non-digits?

$ raku -e '.say for .sort: {m/ \d+ /.Int}'
$ raku -e '.say for .sort: +*.match: / \d+ /'

let's see

$ raku -e '.say for .sort: {m/ \d+ /.Int}'
it1
does2
not3
matter10
what20
the30letters40
say31

What's been interesting about this thread is not only the variety of
solutions, also that the solutions are for two different questions-

how to sort by alpha & numeric segments (b3b, a1a, c20c) =>  (a1a, b3b, c2c)
how to sort by a numeric segment only (b3b, a1a, c20c) =>  (a1a, b3b, c20c)

-y


On Thu, Mar 7, 2024 at 4:40 PM Ralph Mellor  wrote:

> On Tue, Mar 5, 2024 at 7:01 AM ToddAndMargo via perl6-users
>  wrote:
>
> > >> $ raku -e '.say for .sort(*.split(/\d+/,
> :kv).map({ (try .Numeric) // $_}).List)'
> > >>
> > >> Yippee!
>
> > > raku -e '.say for .sort: { .comb(/ \d+ | \D+
> /).map({ .Int // .self }).cache };'
> >
> > Awesome!  Now I have two different methods!
>
> And now 4:
>
> $ raku -e '.say for .sort: {m/ \d+ /.Int}'
> bk1
> bk2
> bk10
> bk34
>
> or, same logic, but spelled differently:
>
> $ raku -e '.say for .sort: +*.match: / \d+ /'
> bk1
> bk2
> bk10
> bk34
>
> --
> love, raiph
>


Re: A question on AND

2023-06-30 Thread yary
@a = @b || @c;  # this is wrong
@a = scalar(@b) || @c;  # really meant this

"or" doesn't help with this either

@a = @b or @c;  # this is wrong
(@a = scalar(@b)) or @c;  # really meant this - @c never is
assigned to @Helen Block 

the low precedence and/or is was introduced in Perl 5 for this construction

open my $fh '<', $input_filename or die "Could not open $input_filename:
$!";

At $work I see bugs where people are using "or" "and" in expressions, and
the part after the expression never gets into the variable they meant it to.

my $answer = $choice_1 or $choice_2; # this is  wrong it turns into
(my $answer = $choice_1) # or $choice_2

there $choice_2 is only evaluated if the $answer got assigned a false
value, and then it gets evaluated in void context, discarding its value.

Try this in Raku - what does it say? Do you still prefer "or" over "||" ?

my $answer = 0 or 5;

say $answer;


-y


On Fri, Jun 30, 2023 at 10:53 AM Andy Bach 
wrote:

> I  always took [1]
>  As alternatives to "&&" and "||" when used for control flow, Perl
> provides
> the "and" and "or" operators (see below). The short-circuit behavior is
> identical. The precedence of "and" and "or" is much lower, however, so
> that you can safely use them after a list operator without the need for
> parentheses
>
> to suggest that and and or are the better ones to use and && or || should
> be used only if they're specifically needed.  Which has always been "never"
> for me.
>
> a
>
> [1]
> perldoc perlop
>The "||", "//" and "&&" operators return the last value evaluated
> (unlike
> C's "||" and "&&", which return 0 or 1). Thus, a reasonably portable
> way
> to find out the home directory might be:
>
> $home =  $ENV{HOME}
>   // $ENV{LOGDIR}
>   // (getpwuid($<))[7]
>   // die "You're homeless!\n";
>
> In particular, this means that you shouldn't use this for selecting
> between two aggregates for assignment:
>
> @a = @b || @c;  # this is wrong
> @a = scalar(@b) || @c;  # really meant this
> @a = @b ? @b : @c;  # this works fine, though
>
> As alternatives to "&&" and "||" when used for control flow, Perl
> provides
> the "and" and "or" operators (see below). The short-circuit behavior is
> identical. The precedence of "and" and "or" is much lower, however, so
> that you can safely use them after a list operator without the need for
> parentheses:
>
> unlink "alpha", "beta", "gamma"
>     or gripe(), next LINE;
>
> With the C-style operators that would have been written like this:
>
> unlink("alpha", "beta", "gamma")
> || (gripe(), next LINE);
>
> It would be even more readable to write that this way:
>
> unless(unlink("alpha", "beta", "gamma")) {
> gripe();
> next LINE;
> }
>
> Using "or" for assignment is unlikely to do what you want; see below.
>
> --
> *From:* yary 
> *Sent:* Friday, June 30, 2023 8:45 AM
> *To:* Richard Hainsworth 
> *Cc:* perl6-users@perl.org 
> *Subject:* Re: A question on AND
>
>
> *CAUTION - EXTERNAL: *
> Most of Richard's parting suggestions I understand & agree with, but not
> this: " why are you using '&&' and not 'and' "
>
> My habit (from Perl 5 days) is to use && || for expressions, and reserve
> "and" "or" for "do this if assignment/function call without parens
> succeeds/fails" – is there a refinement on that distinction in Raku which I
> should pay attention to?
>
> -y
>
>
> On Fri, Jun 30, 2023 at 5:40 AM Richard Hainsworth 
> wrote:
>
> I tried this and it worked without any problem.
>
> Here's the whole program:
>
> use v6.d;say @*ARGS.raku;if @*ARGS.elems > 0  &&  "@*ARGS[0]".lc eq "debug"  {
> say 'got'}
> and at the terminal:
>
> $ raku todd-test.raku debug --debug=50
> ["debug", "--debug=50"]
> got
>
>
> FWIW
> why are you quoting ARGS? The .lc coerces to string anyway.
> why are you using && and not 'and'
> why are you not using a sub MAIN with an optional --debug
> eg. sub MAIN( @args, Bool :$debug=False) {
> #stuff
> if $debug { ... }
>
>
>
> On 30/06/2023 06:06, ToddAndMargo via perl6-users wrote:
>
> if @*ARGS.elems > 0  &&  "@*ARGS[0]".lc eq "debug"  {...}
>
> *CAUTION - EXTERNAL EMAIL:* This email originated outside the Judiciary.
> Exercise caution when opening attachments or clicking on links.
>


Re: A question on AND

2023-06-30 Thread yary
Most of Richard's parting suggestions I understand & agree with, but not
this: " why are you using '&&' and not 'and' "

My habit (from Perl 5 days) is to use && || for expressions, and reserve
"and" "or" for "do this if assignment/function call without parens
succeeds/fails" – is there a refinement on that distinction in Raku which I
should pay attention to?

-y


On Fri, Jun 30, 2023 at 5:40 AM Richard Hainsworth 
wrote:

> I tried this and it worked without any problem.
>
> Here's the whole program:
>
> use v6.d;say @*ARGS.raku;if @*ARGS.elems > 0  &&  "@*ARGS[0]".lc eq "debug"  {
> say 'got'}
> and at the terminal:
>
> $ raku todd-test.raku debug --debug=50
> ["debug", "--debug=50"]
> got
>
>
> FWIW
> why are you quoting ARGS? The .lc coerces to string anyway.
> why are you using && and not 'and'
> why are you not using a sub MAIN with an optional --debug
> eg. sub MAIN( @args, Bool :$debug=False) {
> #stuff
> if $debug { ... }
>
>
>
> On 30/06/2023 06:06, ToddAndMargo via perl6-users wrote:
>
> if @*ARGS.elems > 0  &&  "@*ARGS[0]".lc eq "debug"  {...}
>
>


Re: Help with %?RESOURCES variable

2023-04-19 Thread yary
https://docs.raku.org/language/variables says

> %?RESOURCES is a compile-time variable available to the code of a
> Distribution .
>
> It contains a hash that provides compile and runtime access to files
> associated with the Distribution of the current compilation unit.
>

 The intent of that reads as - the value is set during compilation, and is
available during runtime. Seems like either the doc is wrong, or the
implementation is incomplete. I'm hoping that the doc is right, because
it's useful to be able to read %?RESOURCES during runtime, and in general
useful to set a variable once during compile, then read it forever at
runtime.

-y


On Wed, Apr 19, 2023 at 3:00 PM Brad Gilbert  wrote:

> 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: New doc site

2023-02-27 Thread yary
Really liking the look of the site and responsiveness of the search bar-
first impression 👍
-y


On Mon, Feb 27, 2023 at 10:54 AM Will Coleda  wrote:

> Embarrassing!
>
> Thanks for catching that, thankful she got it right in the weekly!
>
>
> On Mon, Feb 27, 2023 at 8:51 AM Marcel Timmerman  wrote:
> >
> > On 27-02-2023 01:08, Will Coleda wrote:
> > > Since I know not everyone is on IRC:
> > >
> > > The updated raku.docs.org site is now live! Big thanks to everyone who
> > > helped make this happen!
> > >
> > > If you find any issues please let me know at
> > >
> > > https://github.com/raku/doc/issues - content
> > >
> > > https://github.com/raku/doc-website/issues - site, search, styling,
> etc.
> > Hi Will,
> >
> > Thanks for all the effort you and all writers/debuggers have put into it.
> > A small typo above though; 'raku.docs.org' should be
> > 'https://docs.raku.org/'.  However, I could find it via the weekly post
> > of Elizabeth.
> >
> > Thanks again,
> > Marcel
>


Re: $/ not always set after a regex match?

2023-01-02 Thread yary
I like statement modifiers, though not so much using side-effect variables
set by a postfix modifier, I'd like to see the side effect before seeing
the variable it sets. Something like

/ .+  / && put "The root of $_ is $/.";

though the discussion is about not setting $/ in the caller's context and
I'm not sure how to rewrite it with the matching operation first and
passing the match result to a named variable and also skipping if no match,
all in a single statement.

-y


On Sat, Dec 31, 2022 at 8:10 PM William Michels via perl6-users <
perl6-users@perl.org> wrote:

> RESENDING: The code examples below should read `` in all
> cases, not ``, although either works (erroneously?).
>
> ---
>
> Interested in answering the question:
>
> WHICH CODE EXAMPLE IS THE PRETTIEST?
>
> Vote for your favorite (or post your own):
>
> [#] > #REPL (line numbers altered to differentiate)
> Nil
> [0] > $_ = 'gracefully'
> gracefully
> [1a] > put "The root of $_ is $/." if / .+  /;
> The root of gracefully is graceful.
> [1b] > put "The root of $_ is $<>." if / .+  /;
> The root of gracefully is graceful.
> [1c] > print "The root of $_ is " andthen put $/ ~ '.' if / .+  ly> /;
> The root of gracefully is graceful.
> [1d] > print "The root of $_ is " andthen put $<> ~ '.' if / .+  ly> /;
> The root of gracefully is graceful.
> [1] >
> [2a] > put "Or is the root of $_ $/?" if / .+  /;
> Or is the root of gracefully grace?
> [2b] > put "Or is the root of $_ $<>?" if / .+  /;
> Or is the root of gracefully grace?
> [2c] > print "Or is the root of $_ " andthen put $/ ~ '?' if / .+  full> /;
> Or is the root of gracefully grace?
> [2d] > print "Or is the root of $_ " andthen put $<> ~ '?' if / .+
>  /;
> Or is the root of gracefully grace?
> [#] >
>
>


Re: What is this handle?

2022-11-21 Thread yary
Handle is a pointer and you can treat it as such.

A handle is a pointer to another pointer! it has different uses but
basically it is a pointer. Most pointers are a memory address of a value
like a number or string, a handle is a memory address of a pointer (another
address) to one of those.

On Sat, Nov 19, 2022 at 10:13 PM, ToddAndMargo via perl6-users <
perl6-users@perl.org> wrote:

> Hi All,
>
> Any of you familiar with native call?
>
> In the following
>
>C++
>HANDLE WTSOpenServerA(
>   [in] LPSTR pServerName
>);
>
> Is HANDLE a DWORD (32 bit integer)?
>
> I just noticed I have HANDLE defined in Raku as
>
>   constant HANDLE   = Pointer[void];
>
> I do believe most C++ pointers are 32 bit
> cardinals (unsigned integers)
>
> Many thanks,
> -T
>
> --
-y


Re: Aw: Rakudo for W7?

2022-10-23 Thread yary
I interpreted the previous email as, here is the last date that we know
Windows 7 was supported. And here is an archive that goes way back in time.
find the listing in the archive that is close to that date where Windows 7
support ended. That seems like a fair method.

On Sat, Oct 22, 2022 at 8:18 PM, ToddAndMargo via perl6-users <
perl6-users@perl.org> wrote:

> > Gesendet: Freitag, 21. Oktober 2022 um 05:37 Uhr
> > Von: "ToddAndMargo via perl6-users" 
> > An: "perl6-users" 
> > Betreff: Rakudo for W7?
> > Hi All,
> >
> > Where can I download the latest Rakudo Star
> > that supports 64 bit Windows 7?
> >
> > Many thanks,
> > -T
>
>
> On 10/21/22 08:48, no...@ist-einmalig.de wrote:
>  > Hi.
>  >
>  > https://www.microsoft.com/en-us/windows/end-of-support ==> Windows7
> support ended January, 14 2020
>
> No fear of a stupid M$ update destroying your system.
> And no need to try to find replacements for perfectly
> working mission critical software that has been
> abandoned and will not run on current versions
> of Windows.
>
> I do not force my customer onto the latest just because
> it is the latest.  There are conditions were they need
> to be able to operate on older systems.  (I will
> work on any system.  I occasionally still see DOS
> computers.)
>
> As far for security goes, M$'s security updates are
> typically very late to the show and very poorly done.
> A decent anti-virus fills i for you.  And there are
> those instances were these older system are not even
> on the Internet.  ESET still works wonderfully on
> Windows 7.
>
>
>  > https://rakudo.org/downloads/star offers Star Bundles back to 2010.07
>
>
> Which goes back to my question.  What is the last
> one they published that supports Windows 7?
>
>  >
>  >
>  > What am I missing?
>
> See above
>
>  >
>  > Regards
>  >   Anton
>
-- 
-y


Re: author specification

2022-05-06 Thread yary
But I'm understanding from this conversation is that people have different
ideas of what the auth field means.

1. It shows who is responsible for this code. It is independent of which
home the author chooses, where home is GitHub, gitlab, cpan, zef,p6c etc.
2. It shows who is responsible for this code, and its main home. Auth does
not change when stored on other homes.
3. It shows who's responsible for this code in this home. It changes
depending on which home it is being uploaded to.

So it helps to consider some cases and how we handle it.
1. Long time Perl contributor has a CPAN authority, and decides to migrate
all existing projects to github as a main home.
2. Long time perl contributor has a CPAN authority, no Git account (local
development). She decides to distribute new Raku projects in zef primarily,
mirrored in CPAN because she loves metacpan's API and interface.
3. New contributor has modules in GitHub account, is agnostic as to
ecosystems. Wants every ecosystem to reflect latest pushes to main branch
in their git account.

How should the auth field work for these cases?

More cases welcome... (Welcome to the bikeshead? 🚲🏘️🔵💚💜😢)


On Wed, May 4, 2022, 6:43 AM Marcel Timmerman  wrote:

> Hi Vadim,
>
> I'd put it this way: this API has not been stabilized yet. Though at the
> moment it's coming to some consensus.
>
> Hopefully it would not be necessary to change the auth field which is the
> main issue of mine. Because fez is registering the user on its first run,
> the auth field is not needed to find the username later on.
>
> Come to think of it, starting the auth field with 'fez' when it is stored
> on the fez ecosystem, cpan on the cpan system, etc. is information which is
> redundant. fez is checking the ecosystems one by one to find distributions
> just to find an auth starting with the same name as the ecosystem it is
> accessing.
>
> Currently the only ecosystem with authentication is zef. In order to
> publish there fez would ask your password once in a while. This is also why
> all other ecosystems are considered deprecated.
>
> I still have some trouble with fez just because of this auth field I
> think. There are others with the same issue.
>
> Best regards,
> Vadim Belman
>
>
> Thanks for your information, I'll wait for its outcome,
> Regards,
> Marcel
>
>
> On May 3, 2022, at 11: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

Re: checking MAIN arguments

2022-04-27 Thread yary
I just read through https://github.com/rakudo/rakudo/issues/4878 and I had
a thought.

It's like the "where" clause has its own signature-like list of types
it will accept. When the where clause uses the default topic "$_" then that
topic has no constraint, and MAIN can probe if "--dir=something" should be
interpreted as a flag *Bool::True* or if it should be the string
*"something"*. When the "where" clause has only $dir in the body, the
optimizer can specialize it to only take Str, and then MAIN doesn't need to
probe the *Bool::True *case.

Haven't looked at the source, I'm guessing.

-y


On Sat, Apr 16, 2022 at 11:49 AM Luca Ferrari  wrote:

> On Fri, Apr 15, 2022 at 4:15 PM yary  wrote:
> >
> > Here's how I ended up handling input arg validation, with meaningful
> error messages, as part of a Perl Weekly Challenge a couple years ago. It
> looks almost the same as Luca's original, except mine uses "die" instead of
> "warn", which means it won't attempt to continue once it encounters a bad
> arg.
>
> Interesting, but I used `warn` because I want to display all things
> that are not correct at once. In the test case I submitted there is no
> great difference in using warn instead of die, since the program
> should stop in any case, but if you have a bunch of named arguments I
> would like to see all `warn` messages at once, so I have a chance to
> fix all my invocation line at once.
>
> > I'm starting to think Luca's found a regression, since using the
> explicit variable name instead of the topic fixes the issue. That seems
> wrong.
>
> I don't know, in the beginning I thought there was a problem with the
> language specifcation, I mean, something has changed in the `wherre`
> and topic usage. However, hoping to improve our knowledge or the
> implementation, I've submitted an issue here
> <https://github.com/rakudo/rakudo/issues/4878>.
>
> Thanks,
> Luca
>


Re: checking MAIN arguments

2022-04-15 Thread yary
Here's how I ended up handling input arg validation, with meaningful error
messages, as part of a Perl Weekly Challenge a couple years ago. It looks
almost the same as Luca's original, except mine uses "die" instead of
"warn", which means it won't attempt to continue once it encounters a bad
arg.

sub MAIN(Int $line_to_start is copy,#= First line to print
 Int $end_line  #= Last line to print
where { $_ >= $line_to_start
or die "end_line cannot be less than line_to_start" },

 *@input_file   #= File(s) to read from. Also reads STDIN.
where { .all.IO.f
or die "Not a file path:\n  { .grep({! .IO.f}).join: "\n  "
} "}
) {
.say if --$line_to_start < 1
for IO::CatHandle.new(@input_file, $*IN).lines($end_line)
# Alternative would be to use .lines.kv to get line num with line
...

I'm starting to think Luca's found a regression, since using the explicit
variable name instead of the topic fixes the issue. That seems wrong.

-y


On Thu, Apr 14, 2022 at 8:26 PM William Michels via perl6-users <
perl6-users@perl.org> wrote:

> Works (𝐑𝐚𝐤𝐮𝐝𝐨™ v2021.06):
>
> admin@mbook:~$ raku Luca_Ferrari2.p6
> Usage:
>   Luca_Ferrari2.p6 [--dir=]
> admin@mbook:~$ raku Luca_Ferrari2.p6 --dir=foo
> foo
>
> But...warning "Specify the directory [$dir]" isn't printing when
> `--dir=foo` is omitted.
>
> HTH, Bill.
>
> On Tue, Apr 12, 2022 at 1:23 AM Luca Ferrari  wrote:
>
>> On Tue, Apr 12, 2022 at 10:15 AM Luca Ferrari 
>> wrote:
>> >
>> > Hello all,
>> > given this simple program:
>> >
>> > sub MAIN( Str :$dir where { .so && .IO.d // warn "Specify the
>> > directory [$dir]" } ) {
>> > say $dir;
>> > }
>> >
>>
>> Shame on me: it works if I omit the topic and substitute it with the
>> explicit variable, thus:
>>
>> sub MAIN( Str :$dir where { $dir.so && $dir.IO.d // warn "Specify the
>> directory [$dir]" } ) {
>> say $dir;
>> }
>>
>> The only thing that I find in the documentation at
>>  is:
>> "The code in where clauses has some limitations: anything that
>> produces side-effects (e.g., printing output, pulling from an
>> iterator, or increasing a state variable) is not supported and may
>> produce surprising results if used. Also, the code of the where clause
>> may run more than once for a single typecheck in some
>> implementations."
>>
>> Is there a better approach to spurting warning messages when a
>> parameter is not correct (without dealing with USAGE() and friends)?
>>
>> Thanks,
>> Luca
>>
>


Re: Help with promises, supplies and channels.

2022-04-06 Thread yary
For what it's worth, I'm on a mac, promise_test.raku hangs for me once in a
while also.

Welcome to Rakudo(tm) v2021.04.
Implementing the Raku(tm) programming language v6.d.
Built on MoarVM version 2021.04.

Trying to reduce it, I would like to find a program that reliably tickles
this bug and hangs every time... this variation does not crash for me (I
ran it 100x)

### close_much.raku ###
my Channel $ch .= new;

my @proms = (1..2000).map: {
start react {
   whenever $ch.closed { done }
}
};

$ch.close;

await Promise.allof(@proms);

say $*VM;
###


this does not crash for me
### supply_to_many.raku ###
my Channel $ch .= new;

my $p1 = Supply.interval(3);

my @proms = (1..2000).map: {
start react {
whenever $p1 { $ch.close }
   whenever $ch.closed { done }
}
};


await Promise.allof(@proms);

say $*VM;
###


This gives a sensible error "Cannot send a message on a closed channel"
### close_then_send.raku ###
my Channel $ch .= new;

# Close first, send next
$ch.close;
$ch.send("Hi!");
###


This does not crash for me, for different combinations of $senders &
$receivers (1000,1) (1,1000) (1000,1000)
### config_send_recv.raku ###
my Channel $ch .= new;

my Supply $p1 .= interval(1);

my ($senders, $receivers) = (2000,2);


my Int $count = 0;
my @sends = (1..$senders).map: {
  start react {
  whenever $p1 -> $interval {
 $ch.send($_);
 $ch.close if ++$count == $senders;
  }

   whenever $ch.closed { done }

  }
};


my @proms = (1..$receivers).map: {
  start react {
 whenever $ch.closed {
 done;
 }

 whenever $ch -> $data {
 print "$_=$data|";
 }
  }
};


await Promise.allof(@proms,@sends);

say $*VM;
###

I didn't succeed - fun to try!

-y


On Tue, Apr 5, 2022 at 3:55 PM William Michels via perl6-users <
perl6-users@perl.org> wrote:

> Thanks for the bash loop. I'm seeing a few hangs, also some errors
> returned saying:
>
> "Unhandled exception in code scheduled on thread 4"
>
> (MacOS 11.11)
>
> On Tue, Apr 5, 2022 at 12:47 PM David Emanuel da Costa Santiago <
> deman...@gmail.com> wrote:
>
>>
>> Hi William,
>>
>> when it fails or hangs it doesn't print the last line.
>>
>> Please check attached file for output of the stack.
>>
>> Since the failures are random, it's easier to invoke it in a loop:
>>
>> bash$ for i in $(seq 100); do raku test.raku; done
>>
>> If nothing is wrong with the code, i'll open a bug in the github.
>>
>> Regards,
>> David Santiago
>>
>>
>> Às 21:37 de 05/04/22, William Michels escreveu:
>> > No problems so far.
>> >
>> > say $*VM; #add as last line, returns:
>> > moar (2021.06)
>> >
>> > On Tue, Apr 5, 2022 at 11:06 AM David Emanuel da Costa Santiago
>> > mailto:deman...@gmail.com>> wrote:
>> >
>> > Hi,
>> >
>> >
>> >
>> > I'm trying to learn about promises, supplies and channels. So i made
>> > this code:
>> >
>> > """
>> >
>> > my $p1 = Supply.interval(5);
>> > my $p2 = Supply.interval(2);
>> > my Channel $ch = Channel.new;
>> >
>> > my $prom = start react {
>> >   whenever $p1 -> $interval {
>> >   say "5";
>> >   }
>> >
>> >   whenever $p2 -> $interval {
>> >   say 2;
>> >   }
>> >
>> >   whenever $ch.closed {
>> >   done;
>> >   }
>> >
>> >   whenever $ch -> $data {
>> >   say "Data: $data";
>> >   }
>> > }
>> >
>> > my $prom2 = start react {
>> >   whenever $p1 -> $interval {
>> >   $ch.send("5.2");
>> >   $ch.close;
>> >   }
>> >   whenever $ch.closed {
>> >   done;
>> >   }
>> > }
>> >
>> > my @proms = ($prom, $prom2);
>> > await Promise.allof(@proms);
>> >
>> > """
>> >
>> >
>> >
>> > I don't see anything wrong with this but most of the times runs
>> fine,
>> > sometimes hangs, sometimes throw exception. Am i doing something
>> that i
>> > shouldn't be doing?
>> >
>> > $ raku --version
>> > Welcome to Rakudo™ v2022.03-130-g8f7cc0847.
>> > Implementing the Raku® Programming Language v6.d.
>> > Built on MoarVM version 2022.03-13-ga3476e286.
>> >
>> >
>> >
>> > Regards,
>> > David Santiago
>> >
>
>


Re: junctions with given/when

2021-11-04 Thread yary
and I realize that what I just typed doesn't help a whole lot, what if you
have a junction of things and you want to tell if any/one/all/none
smartmatch the same thing... OK..

-y


On Thu, Nov 4, 2021 at 6:38 PM yary  wrote:

> Something that helps me reason about this is thinking of how regular
> expressions match against strings, to remember that which goes on which
> side is important...
>
> > "this has a Q in it" ~~ / 'Q' /  # of course this works
>
> 「Q」
>
> > / 'Q' / ~~ "this has a Q in it" # of course this breaks
>
> Regex object coerced to string ...
>
>
> > say do given "this has a Q in it" { when / 'Q' / {"has a Q"}; default
> {"no match"}}
>
> has a Q
>
> > say do given / 'Q' / { when "this has a Q in it" {"has a Q"}; default
> {"no match"}}
>
> Regex object coerced to string ...
>
> I did have a place in the earlier discussion. I eventually realized that
> if I thought of junctions as analogous to regular expressions, then it was
> easier to remember which side of the smartmatch or given/when to put it.
>
> -y
>
>
> On Thu, Nov 4, 2021 at 3:31 PM Joseph Brenner  wrote:
>
>> > ... we'd need to go
>> > through detailed, calm, measured discussion if we're to minimize
>> > the pain it seems we'll inevitably endure pain to dig ourselves out
>> > of the hole we'd be in.
>>
>> Yes, this could be a bad one.
>>
>


Re: junctions with given/when

2021-11-04 Thread yary
Something that helps me reason about this is thinking of how regular
expressions match against strings, to remember that which goes on which
side is important...

> "this has a Q in it" ~~ / 'Q' /  # of course this works

「Q」

> / 'Q' / ~~ "this has a Q in it" # of course this breaks

Regex object coerced to string ...


> say do given "this has a Q in it" { when / 'Q' / {"has a Q"}; default
{"no match"}}

has a Q

> say do given / 'Q' / { when "this has a Q in it" {"has a Q"}; default
{"no match"}}

Regex object coerced to string ...

I did have a place in the earlier discussion. I eventually realized that if
I thought of junctions as analogous to regular expressions, then it was
easier to remember which side of the smartmatch or given/when to put it.

-y


On Thu, Nov 4, 2021 at 3:31 PM Joseph Brenner  wrote:

> > ... we'd need to go
> > through detailed, calm, measured discussion if we're to minimize
> > the pain it seems we'll inevitably endure pain to dig ourselves out
> > of the hole we'd be in.
>
> Yes, this could be a bad one.
>


Re: Primitive benchmark comparison (parsing LDIF)

2021-10-28 Thread yary
A small thing to begin with in the regex  m/ ^ (@attributes) ':' \s (.+) $
/;

All the string examples use the literal ': ' colon+space, so how about
making the regex more consistent? And also allowing the empty string as a
value, which the string examples allow.

m/ ^ (@attributes) ': ' (.*) $ /;

Next, how about adding a 2nd regex test similar to the "split" that also
relies on User ignoring unknown fields? This accepts an empty-string key,
which the "split" string handler does too.

m/ ^ (<-[:]>*) ': ' (.*) /;


-y


On Thu, Oct 28, 2021 at 2:14 AM Norman Gaywood  wrote:

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

Re: [better solution] pairs of separators from a string

2021-09-20 Thread yary
See Challenge #2 in
https://theweeklychallenge.org/blog/perl-weekly-challenge-131/ ... !

-y


On Wed, Aug 25, 2021 at 2:08 PM William Michels 
wrote:

> Hi Andy!
>
> Maybe this helps (separate coding elements with parens and/or brackets,
> still get the same result):
>
> > say 1, 1, * + * ...^ *>= 100;
> (1 1 2 3 5 8 13 21 34 55 89)
>
> > say 1, 1, * + * ...^ (*>= 100);
> (1 1 2 3 5 8 13 21 34 55 89)
>
> > say 1, 1, * + * ...^ ( * >= 100);
> (1 1 2 3 5 8 13 21 34 55 89)
>
> > say (1, 1, * + *) ...^ ( * >= 100);
> (1 1 2 3 5 8 13 21 34 55 89)
>
> > say 1, 1, * + * [...^] ( * >= 100);
> (1 1 2 3 5 8 13 21 34 55 89)
>
> > say (1, 1, * + *) [...^] ( * >= 100);
> (1 1 2 3 5 8 13 21 34 55 89)
>
> From Yary:
> >> Ranges also support arbitrary functions, the doc page shows a Fibonacci
> number generator
> >> https://docs.raku.org/language/operators#index-entry-sequence_operator
>
> The Fibonacci code above (and in the docs) uses the sequence operator
> (infix ...), not the range operator (infix ..). To recap for Andy: Yary,
> Vadim, Brian, Fernando and Marc have posted code using the sequence
> operator; I've previously posted code using the range operator coupled with
> a grep() call  [I recall reading somewhere that ranges are cheaper to
> construct than sequences, but can't locate the reference at the moment].
>
> FWIW_1, I was unable to get the Fibonacci code to work with the range
> operator:
>
> > say 1, 1, * + * ..^ *>= 100;
> 11WhateverCode.new
>
> FWIW_2, I've had good luck grepping out composite sequences with the
> 'range_operator / grep' strategy:
>
> > #Using "(^*)" as a synonym for the range "(0..*-1)", see:
> https://docs.raku.org/type/Range
> Nil
>
> > ( 0..11 ).[ (^*).grep: * %% 2 ]
> (0 2 4 6 8 10)
>
> > ( 0..11 ).[ (^*).grep: * %% 3 ]
> (0 3 6 9)
>
> > ( 0..11 ).[ (^*).grep: * %% (2|3) ]
> (0 2 3 4 6 8 9 10)
>
> > ( 0..11 ).[ (^*).grep: * %% any(2,3) ]
> (0 2 3 4 6 8 9 10)
>
> HTH, Bill.
>
> PS Now to try to understand the differences (shown earlier in this thread)
> when the := binding operator is used!
>
>
> On Wed, Aug 25, 2021 at 7:15 AM Andy Bach 
> wrote:
>
>> I "misread"
>> say 1, 1, * + * ...^ *>= 100;
>>
>> thinking "shouldn't it be '<=' as you want the total to be less than
>> 100?" but
>> $ raku -e 'say 1, 1, * + * ...^ *<= 100;'
>> ===SORRY!=== Error while compiling -e
>> Whitespace required before <= operator
>> at -e:1
>> --> say 1, 1, * + * ...^ *<= 100;⏏
>> expecting any of:
>> postfix
>>
>> and
>> $ raku -e 'say 1, 1, * + * ...^ * <= 100;'
>> ()
>> $ raku -e 'say 1, 1, * + * ...^ * >= 100;'
>> (1 1 2 3 5 8 13 21 34 55 89)
>>
>> So, then it dawned on me that the '>=' is "binding" (right word?) to the
>> "*" marking the end of the sequence as "until I am ge 100".  Though that
>> doesn't quite work,
>> $ raku -e 'say 1, 1, * + * ...^ * <= 100;'
>> ()
>>
>> Ah, I see, it does work. The end of the sequence is the first number less
>> than 100, so 1 succeeds.  I guess the sequence never gets started.
>> --
>> *From:* yary 
>> *Sent:* Tuesday, August 24, 2021 8:39 PM
>> *To:* William Michels 
>> *Cc:* Marc Chantreux ; raku-users 
>> *Subject:* Re: [better solution] pairs of separators from a string
>>
>>
>> *CAUTION - EXTERNAL: *
>> Hi Bill,
>>
>> When building a range that's an arithmetic or geometric progression, the
>> sequence operator is a little quicker to type. And thus also more likely to
>> be understood more quickly too.
>>
>> > ('a' .. 'h')[(0..*-1).grep: * %% 2 ]
>> (a c e g)
>> > ('a' .. 'h')[ 0, 2 ... * ]
>> (a c e g)
>>
>> > ('a' .. 'h')[(0..*-1).grep: * % 2 ]
>> (b d f h)
>> > ('a' .. 'h')[1, 3...*]
>> (b d f h)
>>
>> # Geometric example- powers of 2
>> > ('a' .. 'z')[1, 2, 4...*]
>> (b c e i q)
>>
>> There isn't a simple translation for the is-prime example that I can
>> think of, that is a good use for "grep"
>>
>> Ranges also support arbitrary functions, the doc page shows a Fibonacci
>> number generator
>> https://docs.raku.org/language/operators#index-entry-seq

Re: [better solution] pairs of separators from a string

2021-08-24 Thread yary
Hi Bill,

When building a range that's an arithmetic or geometric progression, the
sequence operator is a little quicker to type. And thus also more likely to
be understood more quickly too.

> ('a' .. 'h')[(0..*-1).grep: * %% 2 ]
(a c e g)
> ('a' .. 'h')[ 0, 2 ... * ]
(a c e g)

> ('a' .. 'h')[(0..*-1).grep: * % 2 ]
(b d f h)
> ('a' .. 'h')[1, 3...*]
(b d f h)

# Geometric example- powers of 2
> ('a' .. 'z')[1, 2, 4...*]
(b c e i q)

There isn't a simple translation for the is-prime example that I can think
of, that is a good use for "grep"

Ranges also support arbitrary functions, the doc page shows a Fibonacci
number generator
https://docs.raku.org/language/operators#index-entry-sequence_operator
"This allows you to write

say 1, 1, * + * ...^ *>= 100;
# OUTPUT: «(1 1 2 3 5 8 13 21 34 55 89)␤»

to generate all Fibonacci numbers up to but excluding 100."



-y


On Tue, Aug 24, 2021 at 6:36 PM William Michels via perl6-users <
perl6-users@perl.org> wrote:

> Hi Marc,
>
> My understanding is that ranges are pretty cheap to construct, and in any
> case, the range @x[0..*-1] is just the index of all elements in @x. The
> .grep() approach may be most useful if you have a function (e.g. %, %%, and
> .is-prime shown below):
>
> > (0...9)
> (0 1 2 3 4 5 6 7 8 9)
> > (0...9)[0..*-1]
> (0 1 2 3 4 5 6 7 8 9)
> > (0...9)[(0..*-1).grep: * ]
> (0 1 2 3 4 5 6 7 8 9)
> > (0...9)[(0..*-1).grep: * %% 2 ]
> (0 2 4 6 8)
> > (0...9)[(0..*-1).grep: * % 2 ]
> (1 3 5 7 9)
> > (0...9)[(0..*-1).grep: *.is-prime ]
> (2 3 5 7)
> >
>
> You can find a related example in the docs (
> https://docs.raku.org/routine/grep#class_HyperSeq). Anyway, I'm sure each
> approach has its fans,
>
> Best, Bill.
>
> On Tue, Aug 24, 2021 at 3:59 AM Marc Chantreux  wrote:
>
>> hello everyone,
>>
>> I made a mistake while replying to all of us so anwsers never reached
>> your boxes. I'll summerize in one answer:
>>
>> Bill:
>>
>> > Is it just even/odd elements that you want to separate out? If so, maybe
>> > .grep() is your friend here
>>
>> I don't think it is: 0, 2 ... * seems to be
>>
>> * closer to what i have in mind when i think about the problem
>>   (so i invoke readability there)
>> * probably more efficient than (0..*).grep(* % 2) that
>>   * generate twice the number of required elements
>>   * need to filter the result
>>
>> Also, trying to play with this version:
>>
>> my ($a,$b) =
>> .[0,2...*],
>> .[1,3...*]
>> with .comb;
>>
>> just don't work because the lists are squashed into scalar context
>> in the process.
>>
>> So Brian and Fernando made my day with := and the unexpected power of
>> the [] operator.
>>
>> my (@a,@b) := .comb[ [0,2...*], [1,3...*] ];
>>
>> I really like how declarative it is. Also the use of := now seems
>> obvious to me.
>>
>> Sigils still remains something strange to me desprite all your examples
>> but i'll take some time. thanks everyone.
>>
>> marc
>>
>>


Re: (sigils are awesome, they say ...) Re: pairs of separators from a string

2021-08-23 Thread yary
A little more of Vadim's example

> my $a = ; say $a.raku;
("a", "b", "c")
> my @a = ; say @a.raku;
["a", "b", "c"]
> @a[1]='X'; say @a.raku;
["a", "X", "c"]
> $a[1]='X'
Cannot modify an immutable List ((a b c))
  in block  at  line 1

$a is a scalar container, holds one thing. In this example a List - raku
shows as parens.
@a is an array of scalar containers, each of which can be reassigned. Raku
shows as square brackets.

See https://docs.raku.org/language/containers for this plus discussion on
binding
> my @b := (7,6,5); say @b.raku
(7, 6, 5)
> @b[1]='X'
Cannot modify an immutable List ((7 6 5))
  in block  at  line 1

-y


On Sun, Aug 22, 2021 at 3:38 PM Vadim Belman  wrote:

>
> Sigils mean a lot. For example, they create a context:
>
> my $a = 1,2,3;
> my @a = 1,2,3;
> $a = ; say $a.raku;
> @a = ; say @a.raku;
>
> If you have some (actually, a lot of) spare time you can watch my class
> from TRC2021 where I cover a lot about symbols/sigils/object interaction in
> Raku:
>
> https://conf.raku.org/talk/154
> https://conf.raku.org/talk/163
>
>
> Best regards,
> Vadim Belman
>
> On Aug 22, 2021, at 8:57 AM, Marc Chantreux  wrote:
>
> thanks everyone for sharing,
>
> Vadim,
>
> my ($a, $b) = { @^a[0,2...Inf], @a[1,3...Inf] }.(q<(){}[]>.comb); say
> $a[0]; say $b[0]
>
> oh. i never see this direct call of a lambda before but it really makes
> sense! this is the answer i like the most.
>
> i rewrote it my way and this works
>
> my ($a, $b) = { .[0,2…∞], .[1,3…∞] }.(q.comb);
>
> it would be nice if this one will:
>
> my ($a, $b) = { .[0,2…∞], .[1,3…∞] }.: q.comb;
>
> But here is one of the reasons i'm still unconfortable with raku is the
> fact that sigils don't make sense anymore to me (in the contrary of perl
> were sigils means "i want a [$%@] from this").
>
> so as i can't get grid of sigils in this case
>
>my (\a, \b) = { .[0,2…∞], .[1,3…∞] }.(q.comb);
>
> i need to choose a sigil. The way i understand sigils is
> "an optional type specifier". to me
>
>my $truc  => my container 'truc' for anything you want
>my @truc  => my container 'truc' for something that should mostly
> be understood as indexed
>my %truc  => my container 'truc' for something that should mostly
> be understood as associative
>
> so of course i tried
>
> my (@a, @b) = { .[0,2…∞], .[1,3…∞] }.(q.comb);
>
> because i have two lists and two containers. this doesn't work.
> which means @ and $ combines with = to define how things are stored
> but i don't understand how for the moment.
>
> regards,
> marc
>
>
>


Re: intermixed types and resulting types

2021-08-22 Thread yary
"How would you know what types are compatible for a particular operation?"

Operations are functions so the question is the same as "How would you know
what types are compatible for a particular function"

which gets to inspecting a routine's arguments. This SO page helped me
figure that out
https://stackoverflow.com/questions/52515445/how-to-get-all-the-signatures-of-multi-sub-or-build-ins
.

Let's start with a user-defined routine that has coercion in it, taken from
https://docs.raku.org/type/Signature#Coercion_type

> sub foo(Date(Str) $d) { say $d.^name; say $d };
&foo
> say .signature for &foo.candidates;
(Date(Str) $d)

>From that I'd say that routine expects a Date, and can also take a Str
which the Date class would coerce into a Date.
Well from that, and also from knowing the example I got it from

Let's look at addition, the infix + routine- it is a multi with many
candidates

> say 'multi', .signature for &infix:<+>;
multi($?, $?, *%)
> say 'multi', .signature for &infix:<+>.candidates;
multi($x = 0)
multi(\a, \b)
multi(Real \a, Real \b)
multi(Int:D \a, Int:D \b --> Int:D)
multi(int $a, int $b --> int)
multi(Num:D \a, Num:D \b)
multi(num $a, num $b --> num)
multi(Range:D \r, Real:D \v)
multi(Real:D \v, Range:D \r)
multi(Rational:D \a, Rational:D \b)
multi(Rational:D \a, Int:D \b)
multi(Int:D \a, Rational:D \b)
multi(Complex:D \a, Complex:D \b --> Complex:D)
multi(Complex:D \a, Num(Real) \b --> Complex:D)
multi(Num(Real) \a, Complex:D \b --> Complex:D)
multi(Instant:D $a, Instant:D $b)
multi(Instant:D $a, Real:D $b --> Instant:D)
multi(Real:D $a, Instant:D $b --> Instant:D)
multi(Instant:D $a, Duration:D $b --> Instant:D)
multi(Duration:D $a, Instant:D $b --> Instant:D)
multi(Duration:D $a, Real $b --> Duration:D)
multi(Real $a, Duration:D $b --> Duration:D)
multi(Duration:D $a, Duration:D $b --> Duration:D)
multi(DateTime:D \a, Duration:D \b --> DateTime:D)
multi(Duration:D \a, DateTime:D \b --> DateTime:D)
multi(Date:D $d, Int:D $x --> Date:D)
multi(Int:D $x, Date:D $d --> Date:D)

This gives some answers, there isn't much coercion going on, only
"Num(Real)" when adding to a Complex.
The first couple candidates raise questions for me

   1. multi($x = 0) - how is there a single-arg candidate for an infix
   operator?
   2. multi(\a, \b) - does this accept everything, is it a "cleanup"
   candidate 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.

The set difference operator that Joe also used in the example is similar,
this time with no coercion at all, and a few single-arg candidates that I
don't understand being compatible with an infix operator.

> say 'multi', .signature for &infix:<(-)>.candidates;
multi()
multi(QuantHash:D \a)
multi(SetHash:D \a)
multi(BagHash:D \a)
multi(MixHash:D \a)
multi(\a)
multi(Setty:D \a, Setty:D \b)
multi(Setty:D \a, Map:D \b)
multi(Setty:D \a, Iterable:D \b)
multi(Mixy:D \a, Mixy:D \b)
multi(Mixy:D \a, QuantHash:D \b)
multi(QuantHash:D \a, Mixy:D \b)
multi(Mixy:D \a, Map:D \b)
multi(Mixy:D \a, Any:D \b)
multi(Any:D \a, Mixy:D \b)
multi(Baggy:D \a, Mixy:D \b)
multi(Baggy:D \a, Baggy:D \b)
multi(Baggy:D \a, QuantHash:D \b)
multi(QuantHash:D \a, Baggy:D \b)
multi(Baggy:D \a, Map:D \b)
multi(Baggy:D \a, Any:D \b)
multi(\a, Baggy:D \b)
multi(\a, Map:D \b)
multi(\a, Iterable:D \b)
multi($, Failure:D \b)
multi(Failure:D \a, $)
multi(\a, \b)
multi(**@p)

-y


On Sat, Aug 21, 2021 at 3:59 PM Patrick R. Michaud 
wrote:

> On Sat, Aug 21, 2021 at 12:50:21PM -0700, Joseph Brenner wrote:
> > But then, in a case like this one, how would you know in advance
> > that it would work, without Just Trying It:
> >
> >   my @monsters  = < godzilla grendel wormface blob >;
> >   my $cool_monsters = < godzilla ghidra mothera >.Set;
> >
> >   say @monsters.WHAT;  # (Array)
> >   say $cool_monsters.WHAT; # (Set)
> >
> >   my $just_monsters = @monsters (-) $cool_monsters;
> >   say $just_monsters; # Set(blob grendel wormface)
> >
> > A set difference operation seems to know what to do with arrays,
> > without any explicit conversion steps.  I don't think you can get
> > that just from studying the type graphs
>
> More likely, the set difference operation tries to coerce both of its
> operands into Sets, and arrays know how to make themselves into a Set
> (via the .Set() method inherited from List).
>
> It's much like the way the subtraction operator (&infix:<->) tries
> to coerce its operands into Numeric types, by asking the operands to
> return their "Numeric" value, or the way the concatenation operator
> (&infix:<~>) coerces its arguments into Stringy types.
>
> Pm
>


Re: pairs of separators from a string

2021-08-21 Thread yary
This reminds me of "the comma rule" which I haven't quite internalized yet.
This gets a little closer

map { .[0,2…∞], .[1,3…∞] }, ("012345".comb,)
(((0 2 4) (1 3 5)))

and my instinct is that "map" is adding a layer you don't need or want for
this issue, should just be sending the results of comb to a block. But I
can't quite get the syntax right (and docs.raku.org seems down at the
moment)

I sent a variation of this as a potential question to Perl Weekly
Challenge, maybe it will get a bunch of answers in a few weeks!

-y


On Sat, Aug 21, 2021 at 3:05 AM Marc Chantreux  wrote:

> hello,
>
> i would like to get the list of opening (α) and closing
> (ω) separators from this string:
>
> &""''(){}[]
>
> too many years of perl made me think about this solution
> or something alike but it didn't work.
>
> my (\α,\ω) =| map
> { .[0,2…∞], .[1,3…∞] },
> q&""''(){}[]&.comb;
>
> fixing this is important to me because it illustrate how bad i am to
> comprehend how raku flatten things.
>
> regards,
> marc
>
>
>


Re: Windows tutorial needed (Todd?)

2021-07-11 Thread yary
The link for that issue is https://github.com/Raku/doc/issues/3913
("doc" not "docs")

-y


On Sun, Jul 11, 2021 at 5:31 AM Tom Browder  wrote:

> See https://github.com/Raku/docs issue #3913.
>
> -Tom (tbrowder)
>


Re: Buf to Str

2021-06-09 Thread yary
That C null is an int pointer, longer than a single byte.

On Wed, Jun 9, 2021 at 11:04 AM Paul Procacci  wrote:

> Not sure about the 80's, my programming endeavors started in the 90's.
> NUL doesn't exist in the C standard so I have no comment on it.
> The C standard defines that 0 cast to the type void * is both a null
> pointer and a null pointer constant.
> I always have and most likely will continue using 0 over NULL rightly or
> otherwise; though tend to use either/or when describing something ... as
> Elizabeth pointed out.
>
> Potato vs Potatoe I guess.
> ~Paul
>
> On Wed, Jun 9, 2021 at 10:20 AM yary  wrote:
>
>> From my early 1980s days learning programming, ASCII CHR 0 is not null,
>> it is NUL (can type it as ctrl-@) it's a control character much like the
>> others.
>>
>> Ctrl-G BEL, it was fun putting you in file names...
>>
>> On Wed, Jun 9, 2021, 9:56 AM Paul Procacci  wrote:
>>
>>> >> But yeah, the Str class in Raku is much more than a C-string.
>>>
>>> Got it.  Thanks Elizabeth.
>>>
>>> On Wed, Jun 9, 2021 at 6:45 AM Elizabeth Mattijsen 
>>> wrote:
>>>
>>>> > On 9 Jun 2021, at 06:34, Paul Procacci  wrote:
>>>> >
>>>> > Hopefully a pretty quick question
>>>> >
>>>> > GIven the following:
>>>> >
>>>> > my Buf $b .= new([72, 105, 0, 32, 97, 103, 97, 105, 110, 0]);
>>>> > say $b.decode;
>>>> >
>>>> > I would expect this to print 'Hi'.
>>>> > Instead it prints 'Hi again'.
>>>> >
>>>> > https://docs.raku.org/type/Buf#(Blob)_method_decode
>>>> >
>>>> > The decode documentation for Buf only states that 'Applies an
>>>> encoding to turn the blob into a Str; the encoding will be UTF-8 by
>>>> default.'
>>>>
>>>> >
>>>> > The zero (0) in that Buf should imply an end of string yet decode
>>>> seems to want to decode the number of elements instead.
>>>>
>>>> That is an incorrect assumption carried over from C.  In the Raku
>>>> Programming Language, a null byte is a valid grapheme, as it is in
>>>> unicode.  A small change to your program:
>>>>
>>>> my Buf $b .= new(72, 105, 0, 32, 97, 103, 97, 105, 110, 0);
>>>> .say for $b.decode.uninames;
>>>> #
>>>> LATIN CAPITAL LETTER H
>>>> LATIN SMALL LETTER I
>>>> 
>>>> SPACE
>>>> LATIN SMALL LETTER A
>>>> LATIN SMALL LETTER G
>>>> LATIN SMALL LETTER A
>>>> LATIN SMALL LETTER I
>>>> LATIN SMALL LETTER N
>>>> 
>>>>
>>>>
>>>> > Furthermore, If I 'say $b.decode.chars;' it counts the initial null
>>>> as part of Str.
>>>> > In my mind, that means Str doesn't really mean string.
>>>>
>>>> I don't see an initial null in your example.
>>>>
>>>> But yeah, the Str class in Raku is much more than a C-string.
>>>>
>>>>
>>>> > So the question, how does one ACTUALLY decode what's in a buffer to a
>>>> string where it adheres to the semantics of NULL termination for strings
>>>> cleanly.
>>>>
>>>> If you want to include the null byte in your final strings:
>>>>
>>>> my @strings = $b.decode.comb(/ .*? "\0" /)
>>>>
>>>> would be a way.
>>>>
>>>>
>>>>
>>>> > Another question might be, should decode() follow null terminating
>>>> semantics instead of number of elements in a given Buf.
>>>>
>>>> No.  The C-string semantics are what they are.  They are not the
>>>> semantics used in the Raku Programming Language.
>>>>
>>>>
>>>>
>>>> Liz
>>>
>>>
>>>
>>> --
>>> __
>>>
>>> :(){ :|:& };:
>>>
>>
>
> --
> __
>
> :(){ :|:& };:
>
-- 
-y


Re: Buf to Str

2021-06-09 Thread yary
>From my early 1980s days learning programming, ASCII CHR 0 is not null, it
is NUL (can type it as ctrl-@) it's a control character much like the
others.

Ctrl-G BEL, it was fun putting you in file names...

On Wed, Jun 9, 2021, 9:56 AM Paul Procacci  wrote:

> >> But yeah, the Str class in Raku is much more than a C-string.
>
> Got it.  Thanks Elizabeth.
>
> On Wed, Jun 9, 2021 at 6:45 AM Elizabeth Mattijsen  wrote:
>
>> > On 9 Jun 2021, at 06:34, Paul Procacci  wrote:
>> >
>> > Hopefully a pretty quick question
>> >
>> > GIven the following:
>> >
>> > my Buf $b .= new([72, 105, 0, 32, 97, 103, 97, 105, 110, 0]);
>> > say $b.decode;
>> >
>> > I would expect this to print 'Hi'.
>> > Instead it prints 'Hi again'.
>> >
>> > https://docs.raku.org/type/Buf#(Blob)_method_decode
>> >
>> > The decode documentation for Buf only states that 'Applies an encoding
>> to turn the blob into a Str; the encoding will be UTF-8 by default.'
>>
>> >
>> > The zero (0) in that Buf should imply an end of string yet decode seems
>> to want to decode the number of elements instead.
>>
>> That is an incorrect assumption carried over from C.  In the Raku
>> Programming Language, a null byte is a valid grapheme, as it is in
>> unicode.  A small change to your program:
>>
>> my Buf $b .= new(72, 105, 0, 32, 97, 103, 97, 105, 110, 0);
>> .say for $b.decode.uninames;
>> #
>> LATIN CAPITAL LETTER H
>> LATIN SMALL LETTER I
>> 
>> SPACE
>> LATIN SMALL LETTER A
>> LATIN SMALL LETTER G
>> LATIN SMALL LETTER A
>> LATIN SMALL LETTER I
>> LATIN SMALL LETTER N
>> 
>>
>>
>> > Furthermore, If I 'say $b.decode.chars;' it counts the initial null as
>> part of Str.
>> > In my mind, that means Str doesn't really mean string.
>>
>> I don't see an initial null in your example.
>>
>> But yeah, the Str class in Raku is much more than a C-string.
>>
>>
>> > So the question, how does one ACTUALLY decode what's in a buffer to a
>> string where it adheres to the semantics of NULL termination for strings
>> cleanly.
>>
>> If you want to include the null byte in your final strings:
>>
>> my @strings = $b.decode.comb(/ .*? "\0" /)
>>
>> would be a way.
>>
>>
>>
>> > Another question might be, should decode() follow null terminating
>> semantics instead of number of elements in a given Buf.
>>
>> No.  The C-string semantics are what they are.  They are not the
>> semantics used in the Raku Programming Language.
>>
>>
>>
>> Liz
>
>
>
> --
> __
>
> :(){ :|:& };:
>


Re: What's going on with "given (junction) {when (value)...}"

2021-05-31 Thread yary
Thanks for the explanation, I think the docs (and Roast) also can be more
explicit on the difference between
$left ~~ $right
and
$right.ACCEPTS($left)
and
given ($left) { when $right { ... } }
and
... when $right;

ralph-if you are reading this, last week you went into detail about the
tradeoffs of special-casing Junction handling, how do you view these cases
where the topic "$left" is a Junction?

Larry the second thing I did on reading your answer (first being re-reading
and thinking about it) was to try the underlying ACCEPTS- do you think
ACCEPTS should return False here, or is it `~~` and `when` that should
coerce Junctions into something that fails against the right side?

> 3.ACCEPTS(any(3,4))
any(True, False)

> ? (3.ACCEPTS(any(3,4)))
True

-y


On Mon, May 31, 2021 at 6:38 PM Larry Wall  wrote:

> On Sun, May 30, 2021 at 10:18:13PM -0400, yary wrote:
> : This came up in today's Raku study group (my own golfing-)
> :
> : > ? (any(4,3) ~~ 3)
> : True
> : > ? (3 ~~ any(4,3))
> : True
> : > given any(4,3) { when 3 {say '3'}; say 'nope'}
> : nope
> : > given 3 { when any(4,3) {say '3'}; say 'nope'}
> : 3
> : > given any(4,3) { say .raku }
> : any(4, 3)
> :
> : why does Raku say 'nope' for the example *"**given any(4,3) { when 3 {say
> : '3'}; say 'nope'}*"
> :
> : Since this expression is true *? (any(4,3) ~~ 3)*
> : I expected the "*given 4|3*" to also match "*when 3*"
>
> I think both of these should be returning False.  In general, the left
> side of ~~ should
> not be auto-threading, or we revert to the suboptimal Perl semantics of
> smartmatching.
> The reason we broke the symmetry of smartmatch is so that we can optimize
> based on
> the type of the right-hand argument, and allowing auto-threading of the
> other argument
> prevents that.  Note that in the switch structure above, "when 3" is
> supposed to be
> optimizable to a jump table, but how do you calculate a jump from a
> junction?  So we
> biased smartmatching in the direction of coercion-first semantics rather
> early on
> (though, alas, not early enough to prevent Perl adoption of the earlier
> design).
>
> In any case, the documentation says ~~ is defined underlyingly by
> .ACCEPTS, and
> for a Numeric pattern, that says:
>
> multi method ACCEPTS(Numeric:D: $other)
>
> Returns True if $other can be coerced to Numeric and is numerically
> equal to the invocant
> (or both evaluate to NaN).
>
> And I'd be awfully surprised if any(4,3) can be coerced to Numeric in any
> meaningful way...
>
> Perhaps this should be documented as a trap for people coming from Perl,
> if it isn't already.
>
> Larry
>


Re: What's going on with "given (junction) {when (value)...}"

2021-05-31 Thread yary
Nice checking! I opened https://github.com/rakudo/rakudo/issues/4386
-y


On Mon, May 31, 2021 at 3:45 AM Bruce Gray 
wrote:

>
>
> > On May 30, 2021, at 9:18 PM, yary  wrote:
> >
> > This came up in today's Raku study group (my own golfing-)
> >
> > > ? (any(4,3) ~~ 3)
> > True
> > > ? (3 ~~ any(4,3))
> > True
> > > given any(4,3) { when 3 {say '3'}; say 'nope'}
> > nope
> > > given 3 { when any(4,3) {say '3'}; say 'nope'}
> > 3
> > > given any(4,3) { say .raku }
> > any(4, 3)
> >
> > why does Raku say 'nope' for the example "given any(4,3) { when 3 {say
> '3'}; say 'nope'}"
> >
> > Since this expression is true ? (any(4,3) ~~ 3)
> > I expected the "given 4|3" to also match "when 3"
> >
> > -y
>
> This looks very version dependent, and I would not have expected it to be
> version dependent at all.
>
> Summary of behavior across versions. True means `given any(4,3) { when
> 3...` does match just like its converse, and False means it does not match.
> I have noted possible false negatives; 3 of the docker build have MoarVM
> versions newer than the Rakudo versions. Possible build error?
> False 2020.[1..2] (But suspect, since the VM reported version
> 2020.12)
> True  2020.[5..9]
> False 2020.10 (But suspect, since the VM reported version
> 2020.12)
> True  2020.11
> False 2020.12 through nightly (which was 4 hours ago)
>
> Full detail:
> (All run on JJ's alpine docker images (Thanks JJ!), but on a Windows box
> (hence the double-quotes), because Docker is hosed on my Macbook.)
> C:\Users\bruce>copy con yary_03.bat
> @echo off
> docker run --rm -it jjmerelo/alpine-raku:2020.01 -e "print
> $*VM.version; given any(4,3) { when 3 {say True}; say False; };"
> docker run --rm -it jjmerelo/alpine-raku:2020.02 -e "print
> $*VM.version; given any(4,3) { when 3 {say True}; say False; };"
> docker run --rm -it jjmerelo/alpine-raku:2020.05 -e "print
> $*VM.version; given any(4,3) { when 3 {say True}; say False; };"
> docker run --rm -it jjmerelo/alpine-raku:2020.05.1   -e "print
> $*VM.version; given any(4,3) { when 3 {say True}; say False; };"
> docker run --rm -it jjmerelo/alpine-raku:2020.06 -e "print
> $*VM.version; given any(4,3) { when 3 {say True}; say False; };"
> docker run --rm -it jjmerelo/alpine-raku:2020.07 -e "print
> $*VM.version; given any(4,3) { when 3 {say True}; say False; };"
> docker run --rm -it jjmerelo/alpine-raku:2020.08 -e "print
> $*VM.version; given any(4,3) { when 3 {say True}; say False; };"
> docker run --rm -it jjmerelo/alpine-raku:2020.08.1   -e "print
> $*VM.version; given any(4,3) { when 3 {say True}; say False; };"
> docker run --rm -it jjmerelo/alpine-raku:2020.08.2   -e "print
> $*VM.version; given any(4,3) { when 3 {say True}; say False; };"
> docker run --rm -it jjmerelo/alpine-raku:2020.09 -e "print
> $*VM.version; given any(4,3) { when 3 {say True}; say False; };"
> docker run --rm -it jjmerelo/alpine-raku:2020.10 -e "print
> $*VM.version; given any(4,3) { when 3 {say True}; say False; };"
> docker run --rm -it jjmerelo/alpine-raku:2020.11 -e "print
> $*VM.version; given any(4,3) { when 3 {say True}; say False; };"
> docker run --rm -it jjmerelo/alpine-raku:2020.12 -e "print
> $*VM.version; given any(4,3) { when 3 {say True}; say False; };"
> docker run --rm -it jjmerelo/alpine-raku:2021.02 -e "print
> $*VM.version; given any(4,3) { when 3 {say True}; say False; };"
> docker run --rm -it jjmerelo/alpine-raku:2021.02.1   -e "print
> $*VM.version; given any(4,3) { when 3 {say True}; say False; };"
> docker run --rm -it jjmerelo/alpine-raku:2021.03 -e "print
> $*VM.version; given any(4,3) { when 3 {say True}; say False; };"
> docker run --rm -it jjmerelo/alpine-raku:2021.04 -e "print
> $*VM.version; given any(4,3) { when 3 {say True}; say False; };"
> docker run --rm -it jjmerelo/alpine-raku:2021.05 -e "print
> $*VM.version; given any(4,3) { when 3 {say True}; say False; };"
> docker run --rm -it jjmerelo/alpine-raku:latest  -e "print
> $*VM.version; given any(4,3) { when 3 {say True}; say False; };"
> docker run --rm -it jjmerelo/alpine-raku:nightly -e "print
> $*VM.version; given any(4,3) { when 3 {say True}; say False; };"
> ^Z
> 1 file(s) copied.
>
> C:\Users\bruce>yary_03.bat
> 2020.12False
> 2020.12False

What's going on with "given (junction) {when (value)...}"

2021-05-30 Thread yary
This came up in today's Raku study group (my own golfing-)

> ? (any(4,3) ~~ 3)
True
> ? (3 ~~ any(4,3))
True
> given any(4,3) { when 3 {say '3'}; say 'nope'}
nope
> given 3 { when any(4,3) {say '3'}; say 'nope'}
3
> given any(4,3) { say .raku }
any(4, 3)

why does Raku say 'nope' for the example *"**given any(4,3) { when 3 {say
'3'}; say 'nope'}*"

Since this expression is true *? (any(4,3) ~~ 3)*
I expected the "*given 4|3*" to also match "*when 3*"

-y


Re: gather take eager syntax

2021-04-21 Thread yary
a meta-comment, showing values with "dd" or ".raku" often helps alleviate
confusion with understanding non-trivial cases. Try "dd" instead of "say"


Re: slurpy hash signatures

2021-04-18 Thread yary
On Sun, Apr 18, 2021 at 3:00 PM Joseph Brenner  wrote:

> Before I get started here, a small point about defining hashes.
> There are various ways that work:
>
> my %h1 = ( 'ha' => 1, 'ho' => 2, 'hum' => 3 );
> my %h2 = (  ha  => 1,  ho  => 2,  hum  => 3 );
> my %h3 =  ha  => 1,  ho  => 2,  hum  => 3;
> my %h4 = 'ha' => 1, 'ho' => 2, 'hum' => 3;
>
>
Those are all lists of pairs, here's another way to write it
my %h5 = :ha<1>, :ho<2>, :hum<3>;

And even a list-of-things works as a hash initializer

my %h6 = 'ha', 1, 'ho', 2, 'hum', 3; # no pairs
say %h6; #2

as for the main point, interesting! I have the same question about
slurpy-named parameters now...


Re: [sf-perl] The SF Perl Raku Study Group, 03/28 at 1pm PDT

2021-03-29 Thread yary
Took me a bit of looking, but the issue is in the details- the decision
character for "stuff" is '-' since that is always the beginning of "ruler",
the first regex under "control_2" which is the first regex following
"stuff". Changing to "-" and re-ordering the stuff regex fixes the
proof-of-concept, and speeds it up roughly 40% on my system.

regex stuff
{
[# stuff is a group of either
<-[-]>+: # a ratcheting string of non-decision points. Removing
ratcheting makes it hang on Yary's system.
  || # or
'-'  # a "dash" decision point
]*   # 0-many of those. Greedy or non-greedy both work,
about the same speed.
}  # end regex

Will commit this soon.

(and thanks for making this runnable & pointing out that I can use your
test files all in the repo)

-y


On Mon, Mar 29, 2021 at 8:07 PM Joseph Brenner  wrote:

> That's interesting thinking... I've been playing around with the idea
> over here, but haven't got it to work (it fails to parse):
>
>
> https://github.com/doomvox/raku-study/blob/main/bin/2021mar28/doomfiles_browse_sequence-iii.raku
>
> This version does work-- just using greedy matching on "stuff" makes
> it use orders-of-magnitude less resources:
>
>
> https://github.com/doomvox/raku-study/blob/main/bin/2021mar28/doomfiles_browse_sequence-ii.raku
>
>
> And yes, I would guess that the non-greedy matching probably works
> here because the following material is effectively pinned at the end
> of the document.
>
> Note that you should be able to run these scripts as written, provided
> you also pull copies of these source files:
>
> https://github.com/doomvox/raku-study/tree/main/dat/doomfiles
>
>
>
> On 3/29/21, yary  wrote:
> > Hi Joe & other Raku study group attendees,
> >
> > At the time I left, we were looking at a grammar with a speed-memory
> issue
> > on large-ish files. I had a germ of an idea which I couldn't express, and
> > from the meeting notes I see you have a simple fix *"by changing stuff
> > regex (.\*?) to non-greedy (.\*)*" I suspect the greedy-optimization
> works
> > because the thing after the "stuff" regex is near the end of the file.
> Thus
> > if instead it was close to the beginning, it would have a similar issue
> > with greedy and non-greedy would fix.
> >
> > With a night to sleep on it, the thing I was thinking & trying to say is
> > that, in the specialized HTML-grammar you had, the decision points are
> all
> > at left-brackets. By re-writing "stuff" so that it will only backtrack
> when
> > it hits a bracket, I expect more speed-memory gains.
> >
> > How well does this perform vs the simple .* greedy fix?
> >
> > regex stuff
> > { (  # capture stuff (positional capture might not be needed)
> > [   # Stuff is a group of either
> > \<  # a left-bracket decision point
> >   ||# or
> > <-[ \< ]>+: # a ratcheting string of non-decision points
> > ]*  # 0-many of those. Greedy or non-greedy both
> work?
> > ) }  # end capture, end regex
> >
> > This was harder to express verbally & in code than I expected!
> >
> > -y
> >
> >
> > On Sun, Mar 28, 2021 at 4:23 PM Joseph Brenner 
> wrote:
> >
> >> I did send this one out, but it doesn't seem that it went out exactly,
> >> so let's try this one more time.   The Study Group is happening,
> >> already in progress, though we'll be taking a break next week and
> >> broadcasting a burning yule log with the soundtrack to Jesus Christ
> >> Superstar.  (Just kidding)
> >>
> >>
> >> Flaming Carrot, "Night Patrol" (1986) by Bob Burden:
> >>
> >> I feel it rising now...
> >> ... like little bubbles...
> >> THE MOON IS FULL...
> >> ... in a full moon, your brain floats to top of your head...
> >> I feel it...
> >> beginning to boil...
> >> a lot will happen tonight.
> >>
> >> The Raku Study Group
> >>
> >> March 28, 2021  1pm in California, 8pm in the UK
> >>
> >> Zoom meeting link:
> >>
> >>
> https://us02web.zoom.us/j/81127128506?pwd=N0I5bkxUZTRLaWwxN2RJTGlsT254QT09
> >>
> >> Passcode: 4RakuRoll
> >>
> >> RSVPs are useful, though not needed:
> >>   https://www.meetup.com/San-Francisco-Perl/events/277163968/
> >> ___
> >> SanFrancisco-pm mailing list
> >> sanfrancisco...@pm.org
> >> https://mail.pm.org/mailman/listinfo/sanfrancisco-pm
> >>
> >
>


Re: [sf-perl] The SF Perl Raku Study Group, 03/28 at 1pm PDT

2021-03-29 Thread yary
Hi Joe & other Raku study group attendees,

At the time I left, we were looking at a grammar with a speed-memory issue
on large-ish files. I had a germ of an idea which I couldn't express, and
from the meeting notes I see you have a simple fix *"by changing stuff
regex (.\*?) to non-greedy (.\*)*" I suspect the greedy-optimization works
because the thing after the "stuff" regex is near the end of the file. Thus
if instead it was close to the beginning, it would have a similar issue
with greedy and non-greedy would fix.

With a night to sleep on it, the thing I was thinking & trying to say is
that, in the specialized HTML-grammar you had, the decision points are all
at left-brackets. By re-writing "stuff" so that it will only backtrack when
it hits a bracket, I expect more speed-memory gains.

How well does this perform vs the simple .* greedy fix?

regex stuff
{ (  # capture stuff (positional capture might not be needed)
[   # Stuff is a group of either
\<  # a left-bracket decision point
  ||# or
<-[ \< ]>+: # a ratcheting string of non-decision points
]*  # 0-many of those. Greedy or non-greedy both work?
) }  # end capture, end regex

This was harder to express verbally & in code than I expected!

-y


On Sun, Mar 28, 2021 at 4:23 PM Joseph Brenner  wrote:

> I did send this one out, but it doesn't seem that it went out exactly,
> so let's try this one more time.   The Study Group is happening,
> already in progress, though we'll be taking a break next week and
> broadcasting a burning yule log with the soundtrack to Jesus Christ
> Superstar.  (Just kidding)
>
>
> Flaming Carrot, "Night Patrol" (1986) by Bob Burden:
>
> I feel it rising now...
> ... like little bubbles...
> THE MOON IS FULL...
> ... in a full moon, your brain floats to top of your head...
> I feel it...
> beginning to boil...
> a lot will happen tonight.
>
> The Raku Study Group
>
> March 28, 2021  1pm in California, 8pm in the UK
>
> Zoom meeting link:
>
> https://us02web.zoom.us/j/81127128506?pwd=N0I5bkxUZTRLaWwxN2RJTGlsT254QT09
>
> Passcode: 4RakuRoll
>
> RSVPs are useful, though not needed:
>   https://www.meetup.com/San-Francisco-Perl/events/277163968/
> ___
> SanFrancisco-pm mailing list
> sanfrancisco...@pm.org
> https://mail.pm.org/mailman/listinfo/sanfrancisco-pm
>


Re: Objects, TWEAK and return

2021-03-22 Thread yary
Agreed!
-y


On Mon, Mar 22, 2021 at 6:45 PM Ralph Mellor 
wrote:

> On Mon, Mar 22, 2021 at 2:12 PM yary  wrote:
> >
> > It's not good practice to use "map" for side effects only, discarding
> > the returned value–which happens here
>
> I agree.
>
> > Would [using `for`] also work-around the lack of sink context in TWEAK?
>
> Yes.
>
> > I think it is a cause of the unexpected behavior.
>
> Perhaps.
>
> That said, in response to the issue I filed in which I wrote:
>
> > BUILD and TWEAK are not called in sink context by the existing standard
> > object construction machinery shipping with standard Raku 6.d. Perhaps it
> > would be best if they were?
>
> jnthn has commented:
>
> > Yes, with a potential optimization of seeing if the BUILD or TWEAK
> already
> > declared its return type as Nil (which is a common practice) so we don't
> > increase code size of the generated BUILDALL without a need.
>
> --
> love raiph
>


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

2021-03-22 Thread yary
Hi all,

Thanks Bill for posting your results from my samples. Seems like we both
get lots of warnings/errors from our REPL's, me even with 2021.02.01. I
suspect there must be something going on with what the REPL is trying to
print, after all it does want to display the results of every line. I
haven't looked at that since the first post, was more interested in the
capturing-or-not rules displayed by the code run from a file than tracking
down the REPL output. Maybe I'll look into it again next weekend, need to
get back to $work today!

Thanks Raiph for the continued examples, this one in particular showing how
to get all nested captures worked for me. While I'm not sure I agree with
the design, it is consistent, and perhaps I will internalize this over time.

On Fri, Mar 19, 2021 at 7:14 PM Ralph Mellor 
wrote: ...

>
> A Raku equivalent:
> my $word = '(\w+)';
> my $AwithB = "$word ' with ' $word";
> my $regex = "$AwithB .* 'is ' $word";
> $_ = 'Interpolating regexes with arbitrary captures is fun!';
> .say for m//..pairs;
> displays:
>  0 => 「regexes」
>  1 => 「arbitrary」
>  2 => 「fun」
> 
> > Raku example:
> >
> > my $word = /(\w+)/;
> > my $AwithB = /$word' with '$word/;
> If you interpolate by using `$abc...` or `<$abc...>` instead of ``,
> Raku will by default not capture. And the non-capturing is nested, so
> throwing away those captures also throws away the corresponding
> capture within `$word`.


-y


Re: Objects, TWEAK and return

2021-03-22 Thread yary
Good to see this investigated down to the details, yet I just realized
something that was bothering me about it. Going back to the original post:

 submethod TWEAK {
$!filelist.lines».split(',').map( -> ($a, $b) { @!show.push: ( $a, $b
)  });
  }

It's not good practice to use "map" for side effects only, discarding the
returned value–which happens here, and I think it is a cause of the
unexpected behavior.

Would this also work-around the lack of sink context in TWEAK?

 submethod TWEAK {
for $!filelist.lines».split(',')  -> ($a, $b) { @!show.push: ( $a, $b
)  };
  }

-y


On Sun, Mar 21, 2021 at 7:11 PM Ralph Mellor 
wrote:

> On Sun, Mar 21, 2021 at 9:47 PM  wrote:
> >
> > Waw! :) Following your examples and suggestions, these work:
> >
> > > class { submethod TWEAK(-->Nil) { Any.map: {say 99}  } }.new;
> > > class { submethod TWEAK { sink Any.map: {say 99}  } }.new;
> > > class { submethod TWEAK { eager Any.map: {say 99}  } }.new;
> >
> > I really appreciate your discussion. Let me know if you think it
> > is worth to include this issue in the TWEAK Raku documentation.
>
> I think the first step is to see if it's considered a Raku(do) bug.
>
> I've filed an issue: https://github.com/rakudo/rakudo/issues/4260
>
> --
> love, raiph
>


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

2021-03-19 Thread yary
My current expectations are a little different than any others previously
expressed and I don't know how to get the result. I am no longer
considering named captures from Regex's interpolated inside  and am now looking at directly interpolating them.

Perl example:

DB<1> *$word = qr/(\w+)/;*


DB<2> *$AwithB = qr/$word with $word/*


DB<3> *$_ = 'Interpolating regexes with arbitrary captures is fun!'*


DB<4> *x /$AwithB.*is $word/*


0  'regexes'

1  'arbitrary'

2  'fun'

That was simple and I like the results of the capture groups being
first-level.

Raku example:

my $word = /(\w+)/;
my $AwithB = /$word' with '$word/;
$_= 'Interpolating regexes with arbitrary captures is fun!';
say "Nested rx";
dd m/$AwithB.*'is '$word/;

say "shallow rx";
dd m/$word' with '$word.*'is '$word/;

say "no interpolation";
dd m/(\w+)' with '(\w+).*'is '(\w+)/;
# code end results below

Nested rx

Match $/ = Match.new(:orig("Interpolating regexes with arbitrary captures
is fun!"), :from(14), :pos(52))

shallow rx

Match $/ = Match.new(:orig("Interpolating regexes with arbitrary captures
is fun!"), :from(14), :pos(52))

no interpolation

Match $/ = Match.new(:orig("Interpolating regexes with arbitrary captures
is fun!"), :from(14), :pos(52), :list((Match.new(:orig("Interpolating
regexes with arbitrary captures is fun!"), :from(14), :pos(21)),
Match.new(:orig("Interpolating regexes with arbitrary captures is fun!"),
:from(27), :pos(36)), Match.new(:orig("Interpolating regexes with arbitrary
captures is fun!"), :from(49), :pos(52)

Run against

Welcome to 𝐑𝐚𝐤𝐮𝐝𝐨™ v2021.02.1.

Implementing the 𝐑𝐚𝐤𝐮™ programming language v6.d.

Built on MoarVM version 2021.02.

What I see from that example code is Raku matching all the regex's as I
expect regardless of nesting them, all without the named capture grouping
angle-brackets. Which is what the documentation suggests from its example-

my $string   = 'Is this a regex or a string: 123\w+False$pattern1 ?';
my $regex= /\w+/;
say $string.match: / $regex /;#  [4] OUTPUT: «「Is」␤»

Where my expectation differs from the behavior in my example is Raku's
discarding the capture groups of the interpolated regexes. The overall
match works, in all cases :from(14) to :pos(52), but Raku treats the
groupings inside the interpolations as non-capturing.

-y


On Thu, Mar 18, 2021 at 6:08 PM Ralph Mellor 
wrote:

> On Thu, Mar 18, 2021 at 12:59 AM yary  wrote:
> >
> > As it is I get same kinds of errors in the REPL, perhaps it is MacOS
> > with Linenoise that's mucking that up.
>
> I can confirm your new test code also works fine in both program
> and repl forms in 2020.12.
>
> Though obviously the case you mark as "interesting" still doesn't do
> any sub-capturing. Which is to be expected if you know that aspect
> of Raku's regex language.
>
> > I had hoped that by directly interpolating $rd and $rw they would
> > fill in the top-level match object and fill in $0, $1 – but it has the
> > same issue as Joe's original example.
>
> Are you just saying that your original expectations were the same
> as Joe's, but you now understand that's not how Raku regexes
> work, but it's trivial to get the same result? Or are you saying you
> don't know how to get the same result?
>
> --
> love, raiph
>


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

2021-03-17 Thread yary
Thanks raiph for everything!

Including getting me to upgrade my Raku, "Welcome to Rakudo(tm) v2021.02.1.

Implementing the Raku(tm) programming language v6.d.

Built on MoarVM version 2021.02."


As it is I get same kinds of errors in the REPL, perhaps it is MacOS with
Linenoise that's mucking that up. The code in a file does better, matching
the docs. Still I had hoped to work around these issues by interpolating
with the bare variables not inside of angle-brackets. Here's the test code-


my $str = ' grr huh yeah 388 boo! ';

say $str ~~ / (\d+) \s (\w+) /; # 388 boo

say "Match 0=$0, 1=$1"; # Match 0=388, 1=boo

say  "=== below is the interesting case";

my $rd = /(\d+)/;

my $rw = /(\w+)/;

say $str.match: / $rd \s $rw /; # 388 boo

say "Match 0=$0, 1=$1"; # Match 0=, 1=

say "=== below shows literal string matching";

my $sd = '(\d+)';

my $sw = '(\w+)';

$str ~= "$sd $sw";

say $str.match: / ($sd) \s ($sw) /; # (\d+) (\w+)

say "Match 0=$0, 1=$1"; # Match 0=(\d+), 1=(\w+)

I had hoped that by directly interpolating $rd and $rw they would fill in
the top-level match object and fill in $0, $1 – but it has the same issue
as Joe's original example. It matches the right text but doesn't fill in
the top-level match.

-y


On Wed, Mar 17, 2021 at 6:55 PM Ralph Mellor 
wrote:

> > 1. The list you posted is fantastic ("If the first character inside is
> anything other
> > than an alpha it doesn't capture"). It should be added to the Raku Docs
> ASAP.
>
> Not the list, right? Just the rule. (There are dozens of kinds of
> assertions. No one
> is going to remember the list.) If you were to add just the line you
> suggest then
> you'd be able to do it ASAP.
>
> > 2. There are some shortcuts that don't seem to follow a set pattern. For
> example
> > a named capture can be accessed using $ instead of $/ ;
> > the "/' can be elided. Do you have a method you can share for remembering
> > these sorts of shortcuts? Or are they disfavored?
>
> I know you're asking Brad, but fwiw my overall method for mnemonics is to
> stay
> creative and bring in visual and audio elements (like images and rhyming)
> and
> weave them into a little made up story that fits in with an overall
> adventure story
> about Raku. The elements would be ones that work for a given individual
> for a
> given aspect of a given feature of Raku, with the story being made up by
> the
> person doing the learning.
>
> Thus, for example, I might note that the @ symbol looks something like a
> `0`
> and is sounded out as "at" and have a kid tell me a little story they
> imagine
> getting added to the twitter profile of someone they know about programming
> that involves the fact that array indexing is `0` based, thus giving
> them a strong
> reminder of the latter aspect.
>
> Fwiw I'm not seeing much value in developing one for eliding the `/`.
> If a dev doesn't
> know they can elide the `/` when writing code, then no harm done; just
> leave it in.
> If a dev is *reading* code and sees syntax of the form `$` and
> wonders what
> it is, they can type `$<` into the search box in the doc and get a
> match. I personally
> found it really easy to remember because it's so simple and used so
> frequently. I
> think mnemonics
>
> > 3. Finally, I've never seen in the Perl6/Raku literature the motto you
> cite:
> > "One of the mottos of Raku, is that it is ok to confuse a new programmer,
> > it is not ok to confuse an expert."
>
> I think that's a reasonable distillation of Larry's perspective. It's
> another way
> of expressing that Python is good as a first language, Raku as a last one.
>
> Consider the options:
>
> * Ok to confuse a new programmer or an expert. (Not a good option.)
>
> * Ok to confuse an expert, not Ok to confuse a new programmer. ScratchJr?
>
> * Not Ok to confuse a new programmer or an expert. ScratchJr?
>
> > [ The motto I prefer is from Larry Wall: "...easy things should stay
> easy,
> > hard things should get easier, and impossible things should get hard...
> ."
>
> I like that one too. I daresay I prefer it too. But for it to work, it
> really needs
> to be Ok to confuse a new programmer but not Ok to confuse an expert.
>
> Note that easy things being easy does not mean that new programmers
> won't get confused. For example, a new Raku programmer who is used
> to Perl might  be confused that `<$foo>` does not capture in Raku, even
> though it does in Perl. But it's still easy to capture; you write
> ``.
>
> But when *experts* are *systematically* confused, i.e. *all* experts just
> keep falling for the same trap, then impossible things won't just be hard,
> they'll stop happening.
>
> Note that I say that as a non-expert in many, many areas of Raku. What
> I *do* know is that whenever I encounter something that surprises me,
> and keep an open mind about what's going on, no matter how annoyed
> I am or convinced Raku is being stupid, I almost always eventually arrive
> at an interim conclusion it's appropriate as is.
>
> *Almost* always. A

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

2021-03-17 Thread yary
The "Interpolation" section of the raku docs use strings as the elements of
building up a larger regex from smaller pieces, but the example that looks
fruitful isn't working in my raku. This is taken from
https://docs.raku.org/language/regexes#Regex_interpolation

> my $string   = 'Is this a regex or a string: 123\w+False$pattern1 ?';

Is this a regex or a string: 123\w+False$pattern1 ?

> my $regex= /\w+/;

/\w+/

> say $string.match: / $regex /;

Regex object coerced to string (please use .gist or .raku to do that)
 ... and more error lines, and no result when the docs show matching '123':

「」


$ raku -v

Welcome to 𝐑𝐚𝐤𝐮𝐝𝐨™ v2020.10.

Implementing the 𝐑𝐚𝐤𝐮™ programming language v6.d.

Built on MoarVM version 2020.10.


-y


On Wed, Mar 17, 2021 at 3:17 PM William Michels via perl6-users <
perl6-users@perl.org> wrote:

> Dear Brad,
>
> 1. The list you posted is fantastic ("If the first character inside is
> anything other than an alpha it doesn't capture"). It should be added to
> the Raku Docs ASAP.
>
> 2. There are some shortcuts that don't seem to follow a set pattern. For
> example a named capture can be accessed using $ instead of
> $/ ; the "/' can be elided. Do you have a method you can share for
> remembering these sorts of shortcuts? Or are they disfavored?
>
> > say ~$ if 'abc' ~~ / $ = [ \w+ ] /;
> abc
> >
> [ Above from the example at https://docs.raku.org/syntax/Named%20captures
> ].
>
> 3. Finally, I've never seen in the Perl6/Raku literature the motto you
> cite: "One of the mottos of Raku, is that it is ok to confuse a new
> programmer, it is not ok to confuse an expert." Do you have a citation?
>
> [ The motto I prefer is from Larry Wall: "...easy things should stay easy,
> hard things should get easier, and impossible things should get hard... ."
> Citation: https://www.perl.com/pub/2000/10/23/soto2000.html/ ].
>
> Best Regards,
>
> Bill.
>
>
>
> On Sat, Mar 13, 2021 at 4:47 PM Brad Gilbert  wrote:
>
>> 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 「.」
>> <&ws> 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 

Re: Please create a Raku community channel

2021-03-14 Thread yary
The Rakudo Weekly blog gives me a sense of what's going on in the Raku
world, when I remember to check it!
https://rakudoweekly.blog/about-rakudo-weekly/

That site isn't quite what's called for in therms of community discussion
and announcements, but is a decent "organic" overview of what's happening
in Raku lists & blog spaces.

-y


On Sun, Mar 14, 2021 at 3:32 AM Darren Duncan 
wrote:

> On 2021-03-13 2:27 p.m., Vadim Belman wrote:
> > Concerning the accidental duplication of projects, aside of the fact
> that it is dissipation of scarce community resources, the good side is that
> there will be two options to choose from. I will be happy to see both
> project launched. One could eventually become part of the official site,
> the other may be ran independently. One way or another I hope there will be
> more gains from it than loses.
>
> These projects could be merged if both authors are conducive to it, now
> that
> this is known.
>
> If there is reason for them to stay separate, I don't see why they can't
> BOTH be
> official sites, like Version 1 plus Version A, no reason to have to pick
> one.
>
> -- Darren Duncan
>


Re: [sf-perl] The SF Perl Raku Study Group, 03/14 at 1pm PDT

2021-03-12 Thread yary
Or is that a Zen critique ... I think therefore i am not...?

On Fri, Mar 12, 2021, 11:21 AM Joseph Brenner  wrote:

> You'll need to expand on that a bit, I don't get the complaint.
>
> Do pretentious quotations bug you?
>
>
> On 3/12/21, Tiejun Li  wrote:
> >  Joseph,
> > You think you are something. You are not. You are nothing.
> > TJ
> >
> > On Friday, March 12, 2021, 3:17:03 AM GMT+8, Joseph Brenner
> >  wrote:
> >
> >  Donald Knuth, "Computer programming as an art", CACM, December 1974:
> >
> > "In this connection it is most important for us all
> > to remember that there is no one 'best' style; everybody
> > has his own preferences, and it is a mistake to try to force
> > people into an unnatural mold.  ...  The important thing is
> > that you really *like* the style you are using; it should be
> > the best way you prefer to express yourself."
> >
> > The Raku Study Group
> >
> > March 14th, 2021  1pm in California, 9pm in the UK
> >
> > Zoom meeting link:
> >
> >
> https://us02web.zoom.us/j/88493580999?pwd=Zmt3bUE0SFZLYU9MRnFDSXY5eDJLQT09
> >
> > Passcode: 4RakuRoll
> >
> > RSVPs are useful, though not needed:
> >   https://www.meetup.com/San-Francisco-Perl/events/276873465/
> > ___
> > SanFrancisco-pm mailing list
> > sanfrancisco...@pm.org
> > https://mail.pm.org/mailman/listinfo/sanfrancisco-pm
> >
>


Re: dimensions in a multidimensional array

2021-02-05 Thread yary
This got me interested in
https://docs.raku.org/language/list#index-entry-Shaped_arrays

and I find myself wanting to implement a role "Shaped" and applying it to
List, for an immutable shaped list, whose implementation packs its elements
for o(1) lookup... on my ever-lengthening to-do list

-y


On Fri, Feb 5, 2021 at 10:06 AM Elizabeth Mattijsen  wrote:

> > On 5 Feb 2021, at 15:49, Theo van den Heuvel 
> wrote:
> > 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?
>
> If it's a shaped multidimensional array, you can call the .shape method
>
> my @a[3;3;3];
> dd @a.shape;   # (3,3,3)
>
> If it is not, then your workaround appears the way to do it.


Re: list assignment

2021-01-19 Thread yary
Let's dig in a little

 my @one = 1,2,3;
 my @two = 4,5,6;
 my @both = @one,@two;

at this point @both is an array containing two arrays

> dd @both
Array @both = [[1, 2, 3], [4, 5, 6]]

Showing that assigning into an array variable gives an array, each element
of which can itself be an array.

What is @both[0] - ah it is an array

> dd @both[0]
Array @both = $[1, 2, 3]

So I expect assigning it intoan array to result in an array containing a
single array

> my @first = @both[0];
[[1 2 3]]
> dd @first
Array @first = [[1, 2, 3],]


And if I want it to match the original @one array, then I should retrieve
from index 0

> dd @first[0]
Array @first = $[1, 2, 3]
> dd @first[0] === @one
Bool::True

When you use binding := Raku no longer puts items into a new container, it
makes the thing on the left an alias for the thing on the right. No new
container means no outer array holding things assigned to it.

That all matches my intuition... does it help you?

-y


On Tue, Jan 19, 2021 at 1:18 PM Brian Duggan  wrote:
>
> Hi Folks,
>
> I ran into this situation today, which seems counterintuitive:
>
>  my @one = 1,2,3;
>  my @two = 4,5,6;
>  my @both = @one,@two;
>  my @first = @both[0];
>  say @one.raku;
>  say @first.raku;
>
> output:
>
> [1, 2, 3]
> [[1, 2, 3],]
>
> I was expecting @first and @one to be the same.
> I discovered that I could instead write either of these --
>
>   my (@first) = @both[0];
>   my @first := @both[0];
>
> or I could change the @both assignment to be
>
> my @both := @one, @two;
>
> ..but I wonder if there's an idiomatic approach -- or
> way of thinking about this -- that makes this flow more
> intuitive.
>
> thanks
> Brian


Re: LTA documentation page

2021-01-06 Thread yary
In the Perl world, I use perldoc all the time to view the exact
documentation for the installed module I’m working with. And on a regular
basis, it’s useful for me to inspect the source code of the installed
modules.

I have been going through quite a few contortions to look at the source
code for installed modules in raku, and would very much like rakudoc to
have an option similarly to perldoc -l showing the cached path and hashed
local file names of installed modules.

On Wed, Jan 6, 2021 at 11:25 AM Richard Hainsworth 
wrote:

> We have a Google Summer of Code project to work on rakudoc, and the latest
> version of rakudoc points to "noisgul" 's repo.
>
> But ... rakudo aka p6doc was intended to work in the same way as perldoc.
>
> At the time the p6doc project was started, there was actually very little
> documentation, so most of the energy of people interested in documentation
> was on getting Perl 6 / Raku  documented. As projects evolved, the best way
> to access the documentation turned out to be via the website.
>
> Work on rakudoc languished because for most people, looking on line was
> easier and quicker than looking for installed modules.
>
> There REMAINS a need for a tool to look at the documentation associated
> with installed modules. That documentation exists if it is contained in the
> distribution that zef installs. As Vadim said Raku can robustly keep
> multiple versions of the same Module differing by version number and author
> fork. So in principle, if the Module is there, so is the documentation. But
> rakudoc does not access that information.
>
> So rakudoc does not do what you might think it should.
> On 05/01/2021 17:41, JJ Merelo wrote:
>
> Yep, there are a couple of (known) issues here:
> https://github.com/Raku/problem-solving/issues/252 which request to
> remove it from the ecosystem (and I'll probably do it when I finish this
> email), and this one https://github.com/Raku/doc/issues/2896 Build.pm
> does not really work now, to it should probably be removed. And if it is,
> there's actually nothing to "install" so it should be removed.
> Maybe we should work first on releasing rakudoc. Let me see if we can do
> that soon-ish or it requires a lot of work. And in any case we will
> probably encourage people to use the online version of the documentation
> (or to build it themselves via Documentable)
>
> Thanks anyways for the checks, cheers
>
> El mar, 5 ene 2021 a las 18:02, Gianni Ceccarelli ()
> escribió:
>
>> On 2021-01-05 William Michels via perl6-users 
>> wrote:
>> > Raiph's suggestion works for me (on rakudo-2020.10). I mean, p6doc
>> > installs
>>
>> Oh, that points to new, different, problems.
>>
>> https://modules.raku.org/search/?q=p6doc links to
>> https://github.com/Raku/doc which does not contain a ``p6doc`` script,
>> which means that what I get with ``zef install p6doc`` is not the same
>> thing (this is a general problem with pointing at repositories instead
>> of distribution artifacts, it's not specific to p6doc)
>>
>> Then, ``zef install p6doc`` fails here, because::
>>
>>   Failed to create directory '/usr/share/perl6/site/doc' with mode
>>   '0o777': Failed to mkdir: Permission denied
>>
>> AIUI, distributions should install to the CompUnit::Repository in my
>> home directory, not into the system-wide one.
>>
>> --
>> Dakkar - 
>> GPG public key fingerprint = A071 E618 DD2C 5901 9574
>>  6FE2 40EA 9883 7519 3F88
>> key id = 0x75193F88
>>
>>
>
> --
> JJ
>
> --
-y


Re: for and ^ question

2020-12-30 Thread yary
Look up ..^ which is the long form of ^ when used in ^8 sort of thing

https://docs.raku.org/routine/..$CIRCUMFLEX_ACCENT

"Constructs a Range  from the arguments,
excluding the end point."

try out these
3 .. 7
3 ..^ 7
3 ^.. 7
3 ^..^ 7

and also see
https://docs.raku.org/routine/...html
https://docs.raku.org/routine/$CIRCUMFLEX_ACCENT...html
https://docs.raku.org/routine/$CIRCUMFLEX_ACCENT..$CIRCUMFLEX_ACCENT





-y


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

> On 12/30/20 6:04 PM, Curt Tilmes wrote:
> > On Wed, Dec 30, 2020 at 8:40 PM ToddAndMargo via perl6-users
> >  wrote:
> >> In the following for loop:
> >>
> >>   for ^$nCount -> $i {
> >>
> >> What is the ^ doing?
> >
> > https://docs.raku.org/type/Range   About the third paragraph from the
> top:
> >
> > The caret is also a prefix operator for constructing numeric ranges
> > starting from zero:
> >  my $x = 10;
> >  say ^$x; # same as 0 ..^ $x.Numeric
> >
>
> Thank you!
>
> In a for look, it looks like 0 through 9.  Is that
> the for loops doing?
>
>


Re: Missing NullPointerException

2020-12-19 Thread yary
Going back to Dec 3rd explanation:

"... I had a chain of methods which should do some side effect.
It all went fine only the side effect was not there. I then figured
out after some time that one of methods returned Nil and
somehow silently it did not do what I expected."

This looks like an incomplete set of rules – an API contract that needs
filling in – more than a language issue. From the illustrative example now
in play

$drone.engine.start;

the original code as described in the Dec 3rd extract above, implies these
rules:

Each method
- has a side effect on success, no side effect on failure.
- returns a defined object on success. return behavior on failure not
explicitly defined.
Expectation- failure should show more than lack of side effects plus Nil
return value at final step.

Now if all of the "$drone" object/class, the "engine" method, and the
"start" method are app code, then we can fill out the contract so that
$drone.engine.start does the right thing. If on the other hand it was a
Rakudo call which returned Nil instead of failing, then there is a language
issue. Which is what E.M. posted on Dec 3rd:

Nil is really a Failure that doesn't throw.  It indicates the absence of a
> value where there is one expected.
> That is why Nil doesn't throw.  If you want to indicate a soft failure,
> you should use fail().
> If the chain of methods you mention are core methods, and one of them is
> returning Nil, then perhaps we have a bug.  Could you elaborate on the
> situation where you encountered this?


For the sake of discussion, let's fill out the contract each method adheres
to. Side effect has no change
- has a side effect on success, no side effect on failure.

To fulfill the expectation that a failure anywhere "shows up" early, there
are a few tweaks available.
1. On failure, method throws an exception/"die"s -
https://docs.raku.org/language/exceptions
2. On failure, method returns an failure object -
https://docs.raku.org/type/Failure
3. Methods never return Nil. - requires a little work to check at the
returns.

Any of those will make a failure show up closer to where it happened.

I can only recommend #3 in the case where there must be an engine.

A slight modification to the example can show why a method may want to
return Nil on success, and also show that the behavior of Nil with method
calls is actually rather useful:

$drone.wheels.lock;

If a drone has no wheels, the "wheels" method returns Nil and the code
still works. For a drone with wheels, it can throw an exception or return a
failure if there's a problem with the "wheels" method– or if the brakes
don't work, then "lock" can die or return a failure.

-y


On Fri, Dec 18, 2020 at 12:58 PM Konrad Bucheli via perl6-users <
perl6-users@perl.org> wrote:

>
>
> On 16.12.20 12:39, Brad Gilbert wrote:
> >  with $drone.engine {
> >  .start;
> >  say "engine started";
> >  }
>
> Now we get the inverse pyramid of doom. Above code does not the same as
> mine, it only improves the debugging output, but does not fail:
>
>   with $drone.engine {
>   .start;
>   say "engine started";
>   }
>   orelse {
>   die "looks like we lost the engine";
>   }
>
> My point is that I never expected the engine to be lost, because it is
> an integral part of the drone. And that is correct because it was only a
> bug in `engine` which was revealed during testing and when fixed I do
> not need all this any more.
>
> So to understand all the implications of
>
>  $drone.engine.start;
>
> I need in depth Raku understanding. Is that already tribal knowledge?.
> Or you have already been hurt by it as I was. It is definitively not
> beginner friendly and not even intermediate friendly.
>
> I feel uncomfortable with that. Whenever I see something like this I
> have to be aware that the normally obvious assumptions are incorrect.
> These bugs are more difficult to find because the program continues and
> only later on you will see that some data or state is incorrect. And the
> problem with incorrect data is that you might not even spot it.
>
>
> >
> > On Tue, Dec 15, 2020, 11:10 PM Konrad Bucheli via perl6-users
> > mailto:perl6-users@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
> > 

Re: Junctions wrapped in singleton lists

2020-11-16 Thread yary
Open a bug report at https://github.com/rakudo/rakudo/issues/ showing the
change in behavior

-y


On Mon, Nov 16, 2020 at 4:39 PM Ralph Mellor 
wrote:

> say $*PERL.version; # v6.d
> say $*PERL.compiler.version; # v2018.12
> say ({ 1 | -1 } ... *)[^3]; # (any(1, -1) any(1, -1) any(1, -1))
>
> say $*PERL.version; # v6.d
> say $*PERL.compiler.version; # v2020.07
> say ({ 1 | -1 } ... *)[^3]; # ((any(1, -1)) (any(1, -1)) (any(1, -1)))
>


Re: Junctions wrapped in singleton lists

2020-11-15 Thread yary
A few more experiments, for what it's worth. I have no answers.
> { any(1,2) }.^name
Block
> any(1,2).^name
Junction
> (1|-1).^name
Junction
> ((1|-1) ... *)[^3]
((any(1, -1)) (any(2, 0)) (any(3, 1)))
> (1|-1 ... *)[^3]
((any(1, -1)) (any(2, 0)) (any(3, 1)))
> 1|-1 ... 3
((any(1, -1)) (any(2, 0)) 3)

-y


On Sat, Nov 14, 2020 at 4:06 AM Gianni Ceccarelli 
wrote:

> On 2020-11-13 Sean McAfee  wrote:
> > I just tried making a sequence of junctions and found that each one
> > ended up wrapped in a singleton list somehow:
> >
> > > ({ 1 | -1 } ... *)[^3]
> > ((any(1, -1)) (any(1, -1)) (any(1, -1)))
>
> oh, that's weird::
>
> > ({ 'a' } ... *)[0].^name
> Str
> > ({ any(1,2) } ... *)[0].^name
> List
> > { any(1,2) }().^name
> Junction
>
> --
> Dakkar - 
> GPG public key fingerprint = A071 E618 DD2C 5901 9574
>  6FE2 40EA 9883 7519 3F88
> key id = 0x75193F88
>


Re: Constructing a number from digits in an arbitrary base

2020-10-30 Thread yary
> 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.

If that were to exist, would that be an inverse of "polymod"- maybe
"polymul"? - with this property

@decomposed-num = $some_number.polymod(@a-sequence)
if and only if
$some_number = @decomposed-num.polymul(@a-sequence)

-y

On Fri, Oct 30, 2020 at 2:19 PM Elizabeth Mattijsen  wrote:

> > On 30 Oct 2020, at 22:11, Sean McAfee  wrote:
> >
> > Sorry, it seems I wasn't explicit enough.
> >
> > 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.  One way would be the one I originally
> suggested:
> >
> > > sum <46 20 26 87 11> Z* (1, * * 101 ... *)
> > 123456789
> >
> > ...but I'm hoping there's something more concise, shorter, and/or
> readable.
>
> Ah, so it's not about parsing per se.  Sorry I misunderstood.
>
> 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  :-)
>
>
>
> Liz


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

2020-10-12 Thread yary
Here's another way of phrasing these answers-

Some routines like "join" operate on strings, and thus coerce their
argument to a string.

Some routines like "sin" operate on numbers, and thus coerce their argument
to a number.

Each class defines how it coerces to Str or Num, regardless of what is
doing the coercing. Array defines its Str coersion as *.join(' ') and its
Num coercion as *.items

Sometimes those coercions are very helpful, like letting "put" write string
representations of all sorts of things with no extra work for the developer.

Other times, they are not so helpful, instead be explicit what you want the
routine to work on- don't rely on coercion to the string or num the routine
expects. With arrays, follow Larry's advice and use the >> hyperoperator,
if that's what you want.

There's no "context" in the Perl sense, that history refers to a
"wantarray" built-in where a subroutine would ask if the return value was
assigned to an array or not, and then behave differently. Raku doesn't have
that.
https://docs.raku.org/language/5to6-perlfunc#index-entry-wantarray_-_perlfunc

-y


On Mon, Oct 12, 2020 at 6:44 PM William Michels via perl6-users <
perl6-users@perl.org> wrote:

>
>
> On Sat, Oct 10, 2020 at 4:49 PM Tobias Boege  wrote:
>
>> On Sun, 11 Oct 2020, Tobias Boege wrote:
>> > On Sat, 10 Oct 2020, William Michels via perl6-users wrote:
>> > > 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'.
>> > >
>> >
>> > If you want to view it as a matter of paradigm, I guess it would be the
>> > "operator-centric paradigm", except that it is a method and not an
>> operator.
>> >
>> > The Array class inherits methods from Cool and when you call a method
>> from
>> > Cool on the Array, the Cool part of the array will answer the call. The
>> > Array is Cool to advertise that it can be evaluated in numeric and
>> string
>> > "context". In string context, the array becomes joined using spaces as
>> > delimiters. Put more bluntly: when you treat an array like a string
>> > (by calling a string-related method of Cool on it), then Raku treats it
>> > as a string, even if it must convert it to one before. [ This may sound
>> > magical, but in reality Array just obtains the method .split from Cool
>> > and its implementation explicitly converts the invocant, whatever it
>> > may be, to a Stringy on which a sensible split is defined. ]
>> >
>>
>> Oh, it seems like I was far too slow. From all the other answers, I think
>> Brad put best what I tried to express using many redundant words. And he
>> avoided the historically charged and probably inaccurate term "context".
>>
>> Best,
>> Tobias
>>
>
>
> Thank you, Tobias!
>
> user@mbook~$ raku  #test numeric function calls on array
> user@mbook~$ raku  #enter REPL
> To exit type 'exit' or '^D'
> > my @nums = 0, π/2, 3 * π/2;
> [0 1.5707963267948966 4.71238898038469]
> > say @nums.elems
> 3
> > say @nums.sin.elems
> 1
> > say @nums.sin
> 0.1411200080598672
> > say @nums.elems.sin
> 0.1411200080598672
> > say sin(3)
> 0.1411200080598672
> > $*VM
> moar (2020.06)
> >
>
> At first perusal one might conclude that calling .sin on an array
> "auto-joins" the arrays elements, but in fact, calling .sin on an array
> returns the sin() of the number of array elements. The two calls
> "@nums.sin" and "@nums.elems.sin" give exactly the same result.
>
> I'm ignorant of the 'historically charged' use of the term 'context',
> although I interpret your comment to suggest that the term 'context' now
> may be a disfavored concept. If so, then all the more reason to obviate the
> need to explain this concept to new Raku programmers.
>
> --Best, Bill.
>


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

2020-10-12 Thread yary
These behave like overwriting

> List.^find_method('split').wrap: { $^a.map: *.split($^b) }
> List.^find_method('sin').wrap: *.map: *.sin;
>

but they don't have to, since Aureliano started with "wrap" they can be
actual wrappers:

sub map-over-arg(\A) {my &nextone=nextcallee; A.map:{nextone $_}}
List.^find_method('sin').wrap: &map-over-arg;
List.^find_method('cos').wrap: &map-over-arg;
my @nums = 0, π/2, 3 * π/2;
say @nums.sin;  *# (0 1 -1)*
say @nums.cos; *# (1 6.123233995736766e-17 -1.8369701987210297e-16)*

I'm not sure if that can be simplified to use "nextwith" instead of
"nextcallee"–the "map" introduces a new scope which seems to require
"nextcallee"

The example with "split" is complicated by having 2 positionals only the
first of which needs a map, not going to play with that at the moment, left
as exercise to interested readers!

-y


On Mon, Oct 12, 2020 at 9:15 AM Aureliano Guedes 
wrote:

>
>
> On Mon, Oct 12, 2020 at 10:03 AM Brian Duggan  wrote:
>
>> On Saturday, October 10, William Michels via perl6-users wrote:
>> > 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.
>>
>> This seems pretty convenient and intuitive.  At least, it is possible
>> to mimic that behavior in Raku:
>>
>> List.^find_method('split').wrap: { $^a.map: *.split($^b) }
>> List.^find_method('sin').wrap: *.map: *.sin;
>>
> This is like overwrite the function?
> Might be better just implement a new function, I mean, a new verb as is
> called in R.
>
>
>> my @words = ;
>> my @nums = 0, π/2, 3 * π/2;
>>
>> say @words.split(',');
>> say @nums.sin;
>>
>> gives us
>>
>>   ((a b) (c d))
>>   (0 1 -1)
>>
>> Brian
>>
>
>
> --
> Aureliano Guedes
> skype: aureliano.guedes
> contato:  (11) 94292-6110
> whatsapp +5511942926110
>


Re: cross reduce operator magic

2020-10-11 Thread yary
here's a way to not re-test a,b == b,a

squish(sort flat map {$_..31 X[&({$^a**$^b+$b**$a})] $_},2..31)

I'm not completely happy with it, but it does work and is about 30% faster

squish(sort [X[&({$^a**$^b+$b**$a})]] 2..31,2..31) eqv squish(sort flat map
{$_..31 X[&({$^a**$^b+$b**$a})] $_},2..31)
True

say (grep {$_ < 1e11}, squish(sort flat map {$_..31 X[&({$^a**$^b+$b**$a})]
$_},2..31)) ~ ' took ' ~ (now - BEGIN now)
...took 0.0161237 vs
say (grep {$_ < 1e11}, squish(sort [X[&({$^a**$^b+$b**$a})]] 2..31,2..31))
~ ' took ' ~ (now - BEGIN now)
...took 0.0240974



-y


On Sun, Oct 11, 2020 at 8:32 PM yary  wrote:

> Since this is a golf exercize, reducing number of characters, why use the
> reduction form when infix is shorter?
>
> squish(sort [X[&({$^a**$^b+$b**$a})]] 2..31,2..31) # from original
> squish(sort 2..31 X[&({$^a**$^b+$b**$a})] 2..31) # infix is 2-chars
> shorter
>
> Also I am trying to do a little un-golf speed-optimizing, the Wiki page
> for the sequence notes that requiring a<=b removes trivial duplicates.
> Let's see what I can figure out in the near future...
>
> -y
>
>
> On Sun, Oct 11, 2020 at 5:55 PM Cezmi Pastirma 
> wrote:
>
>> Wow, that's a very comprehensive explanation. I've just found out that I
>> couldn't even comprehend the first reduction operator. I was thinking it
>> was doing some magic operations. All it did was enable the cross op to act
>> on the 2 lists without having to be  between   them. As simple as that. And
>> surely I mis-took the second bracket as a second reduction. Now it's clear
>> that it's for Nesting of metaoperators
>> <https://docs.raku.org/language/operators#___top>  Actually I was
>> guessing this fine detail must have been documented in the Raku docs but I
>> hadn't the faintest idea how to search for it in the huge docs of Raku :)
>>
>> The custom operator definition to separate the Cross from the Op is very
>> welcome too. I haven't written any custom op in Raku so far and it's good
>> to see it in action.
>>
>> Thank you for your time. Very much appreciated.
>>
>>
>> 11.10.2020, 21:31, "Bruce Gray" :
>>
>> NOTE: 30 minutes from now is the start of the Raku Study Group of the San
>> Francisco Perl Mongers.
>> We can offer a "deep dive" into how the Leyland code works, if that would
>> be helpful.
>> Zoom details here:
>> https://mail.pm.org/pipermail/sanfrancisco-pm/2020-October/004726.html
>>
>>
>>  On Oct 11, 2020, at 10:39 AM, Cezmi Pastirma 
>> wrote:
>>
>>  I've got a question about a Leyland-numbers-listing Raku code which I
>> saw at codegolf.stackexchange.com at
>> https://codegolf.stackexchange.com/a/83013/98132
>>
>>  I've slightly rearranged the code to make it print Leyland numbers up to
>> 1 Billion:
>>  .say for grep {$_ < 1E11}, squish(sort [X[&({$^a**$^b+$b**$a})]]
>> 2..32,2..32)
>>
>>  The question in short is:
>>
>>  How does the cross reduce work there?
>>
>>
>> The reduction is a red herring to our understanding here.
>> Note that, when you are only [reducing] on two lists, `[any_op_here] @a,
>> @b` is the same as `@a any_op_here @b`.
>> These are equivalent:
>> say [X+] 2..4, 1..5;
>> say 2..4 X+ 1..5;
>> The operator need not be a meta-operator:
>> say [*] 3, 5;
>> say 3 * 5;
>>
>>  Extra info:
>>
>>  That cross reduce section surely does what this half-pseudo code tries
>> to do:
>>  map { $^a ** $^b + $b ** $a }, 2..32,32…2
>>
>>
>> If @c has 20 elements, and @d has 30 elements, then `@c X+ @d` has 600
>> elements.
>> You cannot produce the equivalent with a simple `map`.
>> (You could with a flattened map-within-a-map)
>>
>>
>> Simplifying your "slightly rearranged” code:
>> .say for grep {$_ < 1E11}, squish(sort [X[&({$^a**$^b+$b**$a})]]
>> 2..32,2..32)
>>
>> ...to just the part you are curious about, we get:
>> say [X[&({$^a**$^b+$b**$a})]] 2..4,2..4;
>> (8 17 32 17 54 145 32 145 512)
>>
>> We are only [reducing] on two lists, so we can remove the reduction, and
>> just use the Xop:
>> say 2..4 X[&({$^a**$^b+$b**$a})] 2..4;
>> (8 17 32 17 54 145 32 145 512)
>>
>>
>>  The tricky part here is the use of reduce operators two times in a row,
>> once before the cross operator, once before the & operator, which I guess
&g

Re: cross reduce operator magic

2020-10-11 Thread yary
Since this is a golf exercize, reducing number of characters, why use the
reduction form when infix is shorter?

squish(sort [X[&({$^a**$^b+$b**$a})]] 2..31,2..31) # from original
squish(sort 2..31 X[&({$^a**$^b+$b**$a})] 2..31) # infix is 2-chars shorter

Also I am trying to do a little un-golf speed-optimizing, the Wiki page for
the sequence notes that requiring a<=b removes trivial duplicates. Let's
see what I can figure out in the near future...

-y


On Sun, Oct 11, 2020 at 5:55 PM Cezmi Pastirma 
wrote:

> Wow, that's a very comprehensive explanation. I've just found out that I
> couldn't even comprehend the first reduction operator. I was thinking it
> was doing some magic operations. All it did was enable the cross op to act
> on the 2 lists without having to be  between   them. As simple as that. And
> surely I mis-took the second bracket as a second reduction. Now it's clear
> that it's for Nesting of metaoperators
>   Actually I was
> guessing this fine detail must have been documented in the Raku docs but I
> hadn't the faintest idea how to search for it in the huge docs of Raku :)
>
> The custom operator definition to separate the Cross from the Op is very
> welcome too. I haven't written any custom op in Raku so far and it's good
> to see it in action.
>
> Thank you for your time. Very much appreciated.
>
>
> 11.10.2020, 21:31, "Bruce Gray" :
>
> NOTE: 30 minutes from now is the start of the Raku Study Group of the San
> Francisco Perl Mongers.
> We can offer a "deep dive" into how the Leyland code works, if that would
> be helpful.
> Zoom details here:
> https://mail.pm.org/pipermail/sanfrancisco-pm/2020-October/004726.html
>
>
>  On Oct 11, 2020, at 10:39 AM, Cezmi Pastirma 
> wrote:
>
>  I've got a question about a Leyland-numbers-listing Raku code which I saw
> at codegolf.stackexchange.com at
> https://codegolf.stackexchange.com/a/83013/98132
>
>  I've slightly rearranged the code to make it print Leyland numbers up to
> 1 Billion:
>  .say for grep {$_ < 1E11}, squish(sort [X[&({$^a**$^b+$b**$a})]]
> 2..32,2..32)
>
>  The question in short is:
>
>  How does the cross reduce work there?
>
>
> The reduction is a red herring to our understanding here.
> Note that, when you are only [reducing] on two lists, `[any_op_here] @a,
> @b` is the same as `@a any_op_here @b`.
> These are equivalent:
> say [X+] 2..4, 1..5;
> say 2..4 X+ 1..5;
> The operator need not be a meta-operator:
> say [*] 3, 5;
> say 3 * 5;
>
>  Extra info:
>
>  That cross reduce section surely does what this half-pseudo code tries to
> do:
>  map { $^a ** $^b + $b ** $a }, 2..32,32…2
>
>
> If @c has 20 elements, and @d has 30 elements, then `@c X+ @d` has 600
> elements.
> You cannot produce the equivalent with a simple `map`.
> (You could with a flattened map-within-a-map)
>
>
> Simplifying your "slightly rearranged” code:
> .say for grep {$_ < 1E11}, squish(sort [X[&({$^a**$^b+$b**$a})]]
> 2..32,2..32)
>
> ...to just the part you are curious about, we get:
> say [X[&({$^a**$^b+$b**$a})]] 2..4,2..4;
> (8 17 32 17 54 145 32 145 512)
>
> We are only [reducing] on two lists, so we can remove the reduction, and
> just use the Xop:
> say 2..4 X[&({$^a**$^b+$b**$a})] 2..4;
> (8 17 32 17 54 145 32 145 512)
>
>
>  The tricky part here is the use of reduce operators two times in a row,
> once before the cross operator, once before the & operator, which I guess
> donates a closure. How to interpret this usage of operators?
>
>
>
> The square brackets after the X, I think you mis-took as a second
> reduction.
>
> Those brackets are just there to disambiguate the `op` that the `X` is
> crossing on.
> See: https://docs.raku.org/language/operators#Nesting_of_metaoperators
>
> These are equivalent:
> .say for ^2 X+ ^2;
> .say for ^2 X[+] ^2;
>
>
> We can create our own operator, to further separate the Cross from the Op:
> multi infix:<⨁> ($a, $b) {
>$a ** $b
> + $b ** $a
> };
> say 2 ⨁ 3;
> say 2..4 X⨁ 2..4;
> 17
> (8 17 32 17 54 145 32 145 512)
>
> The `X` itself is the operator-form of the `cross` routine,
> well-documented here:
> https://docs.raku.org/routine/cross
>
> https://docs.raku.org/language/operators#index-entry-X_(cross_metaoperator)
>
> https://docs.raku.org/language/operators#index-entry-cross_product_operator
>
> If any part of this was lacking in clarity, please let me know where to
> focus, and I will be glad to expound.
>
> --
> Hope this helps,
> Bruce Gray (Util of Perlmonks)
>
>


Re: print particular lines question

2020-09-01 Thread yary
Every time $ shows up, it is a different scalar.

$=1; say $;

is similar to

my $anonONE=1; say $anonTWO;

thus they are very limited use

-y


On Tue, Sep 1, 2020 at 3:55 PM Andy Bach 
wrote:

> > My first clue that something is amiss is in your third line of code when
> the  return skips "AA" and starts "AB, AC, AD". That suggests to me
> that the two step assign/printf call is playing havoc with the $ anonymous
> variable
>
> Missed that about the missing AA - does the same thing  with a named var,
> though:
>  raku -e 'for  -> $alpha {  for (1..14) { (state $sv = $alpha)++;
>  printf("d: %s\n", $sv ) } }'
> d: AB
> d: AC
>
> So
>  raku -e 'for  -> $alpha {  for (1..14) { say (state $sv =
> $alpha)++;  printf("d: %s\n", $sv ) } }'
> AA
> d: AB
> AB
> d: AC
>
> Ah, the increment happens the initial assignment.
> $sv = "AA";
> $sv++;
> print $sv;  # AB
>
> but the
> say (state $sv = $alpha)++
>
> says the result of the assignment, then the increment.  My confusion was
> more about my inability to use "$" anywhere else.
>  raku -e 'for  -> $alpha {  for (1..14) { say (state $ = $alpha)++;
>  printf("d: %s\n", $ ) } }'
> AA
> Use of uninitialized value of type Any in string context.
> Methods .^name, .raku, .gist, or .say can be used to stringify it to
> something meaningful.
>   in block  at -e line 1
> Use of uninitialized value of type Any in string context.
> Methods .^name, .raku, .gist, or .say can be used to stringify it to
> something meaningful.
>   in any join at gen/moar/stage2/NQPCORE.setting line 1075
> d:
> AB
> Use of uninitialized value of type Any in string context.
> ...
>
> break it out of the parens, and it loses some "stateness":
>  raku -e 'for  -> $alpha {  for (1..14) { say state $ = $alpha;
> $++;  printf("d: %s\n", $ ) } }'
> AA
> Use of uninitialized value of type Any in string context.
> Methods .^name, .raku, .gist, or .say can be used to stringify it to
> something meaningful.
>   in block  at -e line 1
> ...
> AA
>
> but the named doesn't
>  raku -e 'for  -> $alpha {  for (1..14) { state $sv = $alpha; say
> $sv; $sv++;  printf("d: %s\n", $sv ) } }'
> AA
> d: AB
> AB
> d: AC
>
>
>
>
> --
> *From:* William Michels 
> *Sent:* Tuesday, September 1, 2020 5:30 PM
> *To:* Andy Bach 
> *Cc:* yary ; perl6-users 
> *Subject:* Re: print particular lines question
>
> My first clue that something is amiss is in your third line of code when
> the  return skips "AA" and starts "AB, AC, AD". That suggests to me
> that the two step assign/printf call is playing havoc with the $ anonymous
> variable. Try this instead:
>
> ~$ raku -e 'for  -> $alpha {  for (1..14) { printf("d: %s\n",
> (state $ = $alpha)++ ) }; };'
> d: AA
> d: AB
> d: AC
> d: AD
> d: AE
> d: AF
> d: AG
> d: AH
> d: AI
> d: AJ
> d: AK
> d: AL
> d: AM
> d: AN
> d: NN
> d: NO
> d: NP
> d: NQ
> d: NR
> d: NS
> d: NT
> d: NU
> d: NV
> d: NW
> d: NX
> d: NY
> d: NZ
> d: OA
>
> HTH, Bill.
>
> On Tue, Sep 1, 2020 at 2:57 PM Andy Bach 
> wrote:
>
> I'm barely hanging on with the "$" so ... so from:
> raku -e 'for  -> $alpha { for (1..14) {   print (state $ =
> $alpha)++ ~ " "  } }'
> AA AB AC AD AE AF
>
> I tried an actual, er, non-anon var
> # raku -e 'for  -> $alpha { for (1..14) {   print (state $sv =
> $alpha)++ ~ " "  } }'
> AA AB AC AD AE AF ...
>
> and then I tried
> raku -e 'for  -> $alpha {  for (1..14) { (state $sv = $alpha)++;
>  printf("d: %s\n", $sv ) } }'
> d: AB
> d: AC
> d: AD
> d: AE
> d: AF
> ...
>
> but back to "$"
>  raku -e 'for  -> $alpha {  for (1..14) { (state $ = $alpha)++;
>  printf("d: %s\n", $ ) } }'
> Use of uninitialized value of type Any in string context.
> Methods .^name, .raku, .gist, or .say can be used to stringify it to
> something meaningful.
>   in block  at -e line 1
> Use of uninitialized value of type Any in string context.
> Methods .^name, .raku, .gist, or .say can be used to stringify it to
> something meaningful.
>   in any join at gen/moar/stage2/NQPCORE.setting line 1075
> d:
>
> [27 more times]
>
> I used printf hoping the %s context would stringify "$" as trying any of
> the suggested "methods" complain of a missing "self"
>  raku -e 

Re: print particular lines question

2020-09-01 Thread yary
Yes, because INIT and BEGIN happen before runtime, and $alpha is set at
runtime! Hence my original BEGIN example using a constant to set the first
value.

Another reason to prefer "state" over those phasers... unless you want a
counter over the lifetime of the process, which is valid.

-y


On Tue, Sep 1, 2020 at 1:17 PM William Michels 
wrote:

> I tried combining Larry's code and Yary's code, variously using
> "state" or "INIT" or "BEGIN". This is what I saw:
>
> ~$ raku -e 'for  -> $alpha { for (1..14) { print (state $ =
> $alpha)++ ~ " " } }'
> AA AB AC AD AE AF AG AH AI AJ AK AL AM AN NN NO NP NQ NR NS NT NU NV
> NW NX NY NZ OA
>
> ~$ raku -e 'for  -> $alpha { for (1..14) { print (INIT $ =
> $alpha)++ ~ " " } }'
> 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
>
> ~$ raku -e 'for  -> $alpha { for (1..14) { print (BEGIN $ =
> $alpha)++ ~ " " } }'
> 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
>
> Expected?  --Bill.
>
> On Tue, Sep 1, 2020 at 11:44 AM yary  wrote:
> >
> >
> > Thanks, that's cool, and shows me something I was wondering about
> >
> > On Tue, Sep 1, 2020 at 11:36 AM Larry Wall  wrote:
> >>
> >> If you want to re-initialize a state variable, it's probably better to
> make
> >> it explicit with the state declarator:
> >>
> >> $ raku -e "for  { for (1..2) { say (state $ = 'AAA')++ } }"
> >> AAA
> >> AAB
> >> AAA
> >> AAB
> >
> >
> > $ raku -e 'for  -> $alpha { for (1..3) { say (state $ = $alpha)++
> } }'
> > AA
> > AB
> > AC
> > OO
> > OP
> > OQ
> >
>


Re: print particular lines question

2020-09-01 Thread yary
Thanks, that's cool, and shows me something I was wondering about

On Tue, Sep 1, 2020 at 11:36 AM Larry Wall  wrote:

> If you want to re-initialize a state variable, it's probably better to make
> it explicit with the state declarator:
>
> $ raku -e "for  { for (1..2) { say (state $ = 'AAA')++ } }"
> AAA
> AAB
> AAA
> AAB
>

$ raku -e 'for  -> $alpha { for (1..3) { say (state $ = $alpha)++ }
}'
AA
AB
AC
OO
OP
OQ


Re: print particular lines question

2020-08-31 Thread yary
Nope $_ is the "default topic" if you want to use the jargon. It has a
name, the underscore character.

$ is a nameless variable, jargon is "anonymous scalar"

$_ is different specialness from $

-y


On Mon, Aug 31, 2020 at 5:13 PM ToddAndMargo via perl6-users <
perl6-users@perl.org> wrote:

> On 2020-08-31 17:03, yary wrote:
> > anonymous variable
>
> Would be safe thinking it had the same properties as `$_`?
>


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

2020-08-31 Thread yary
First part of my previous email on this thread! Re-read this bit

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

and restating the above: "string".lines is different a different method
from "File.txt".IO.lines, which is also different from
"File.txt".IO.open.lines .  Yes that's confusing but there are reasons for
all that which make sense when one thinks about them a while.

So if you want to split a string, use split!

If you want to experiment a text file's line endings with "lines", do that
experiment with a file! Which was the 2nd part of my previous email

> dd $_ for 'line0-10.txt'.IO.lines(:nl-in["i","\n"], :!chomp)[0..3];
> "Li"
> "ne 0\n"
> "Li"
> "ne 1\n"

-y


On Mon, Aug 31, 2020 at 5:12 PM ToddAndMargo via perl6-users <
perl6-users@perl.org> wrote:

> On 2020-08-30 08:42, 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
> >
> > methodlines(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
>
> Hi Yary,
>
> Now what am I doing wrong?
>
> p6 'my $x="a\tb\tc\td\t"; dd $x; for $x.lines(:nl-in["\t", 0x09],
> :!chomp) {dd $_};'
>
> Str $x = "a\tb\tc\td\t"
>
> "a\tb\tc\td\t"
>
> :'(
> -T
>


Re: print particular lines question

2020-08-31 Thread yary
I like this better for alpha counter

raku -e "for (1..4) { say (BEGIN $ = 'AAA')++ }"

with BEGIN, the assignment of AAA happens once. With the earlier ||= it
checks each time through the loop.
-y


On Mon, Aug 31, 2020 at 5:03 PM yary  wrote:

> Not even a reset- every time there's a $ by itself it is a new/different
> anonymous variable. So it is only useful where it is never referred to
> anywhere else.
>
> $ raku -e "for (1..4) { say $++, ' ,  ', ++$; say 'again- ',$;}"
>
> 0 ,  1
>
> again- (Any)
>
> 1 ,  2
>
> again- (Any)
>
> 2 ,  3
>
> again- (Any)
>
> 3 ,  4
>
> again- (Any)
>
> Hmm, how to make an alpha counter?
>
> $ raku -e "for (1..4) { say ($ ||= 'AAA')++ }"
>
> AAA
>
> AAB
>
> AAC
>
> AAD
>
> There is also anonymous @ and % but I don't have an example off the top of
> my head.
> -y
>
>
> On Mon, Aug 31, 2020 at 4:57 PM ToddAndMargo via perl6-users <
> perl6-users@perl.org> wrote:
>
>> On 2020-08-31 16:53, ToddAndMargo via perl6-users wrote:
>> >>> On Mon, Aug 31, 2020, 4:20 PM ToddAndMargo via perl6-users
>> >>> mailto:perl6-users@perl.org>> wrote:
>> >>>
>> >>> On 2020-08-31 05:53, Brian Duggan wrote:
>> >>>  > On Monday, August 24, Curt Tilmes wrote:
>> >>>  >> $ cat Lines.txt | raku -e '.say for lines()[3,2,5]'
>> >>>  >
>> >>>  > The -n flag is an option here too:
>> >>>  >
>> >>>  >     raku -ne '.say if $++ == 3|2|5' Lines.txt
>> >>>  >
>> >>>  > Brian
>> >>>  >
>> >>>
>> >
>> >>>> Hi Bill,
>> >>>>
>> >>>> Works beatifically! And no bash pipe!
>> >>>>
>> >>>> $ raku -ne '.say if $++ == 3|2|5' Lines.txt
>> >>>> Line 2
>> >>>> Line 3
>> >>>> Line 5
>> >>>>
>> >>>> What is `$++`?
>> >>>>
>> >>>> -T
>> >>>>
>> >
>> > On 2020-08-31 16:36, yary wrote:
>> >> $ by itself is an anonymous variable, putting ++ after starts it at 0
>> >> (hmm or nil?) and increments up.
>> >>
>> >> By putting the plus plus first, ++$, it will start at 1, thanks to
>> >> pre-increment versus post increment
>> >>
>> >
>> > Hi Yary,
>> >
>> > Excellent instructions!  It is a counter.   I found
>> > it over on
>> >
>> >  https://docs.raku.org/perl6.html
>> >
>> > with a search on `$++`.  But I had to pick it up
>> > from "context"
>> >
>> >
>> >
>> > $ p6 'my @x=<"a" "b" "c">; for @x -> $i { print $++," ", ++$, " ", $i,
>> > "\n";}'
>> > 0 1 "a"
>> > 1 2 "b"
>> > 2 3 "c"
>> >
>> > Question: does the counter restart after its use, or do
>> > I need to do it myself?
>> >
>> > -T
>> >
>>
>> To answer my own question.  It resets itself:
>>
>> $ p6 'my @x=<"a" "b" "c">; for @x -> $i { print $++, " ", ++$, " ", $i,
>> "\n" }; print "\n", $++, "\n";'
>> 0 1 "a"
>> 1 2 "b"
>> 2 3 "c"
>>
>> 0
>>
>>
>>
>> --
>> ~~
>> Computers are like air conditioners.
>> They malfunction when you open windows
>> ~~
>>
>


Re: print particular lines question

2020-08-31 Thread yary
Not even a reset- every time there's a $ by itself it is a new/different
anonymous variable. So it is only useful where it is never referred to
anywhere else.

$ raku -e "for (1..4) { say $++, ' ,  ', ++$; say 'again- ',$;}"

0 ,  1

again- (Any)

1 ,  2

again- (Any)

2 ,  3

again- (Any)

3 ,  4

again- (Any)

Hmm, how to make an alpha counter?

$ raku -e "for (1..4) { say ($ ||= 'AAA')++ }"

AAA

AAB

AAC

AAD

There is also anonymous @ and % but I don't have an example off the top of
my head.
-y


On Mon, Aug 31, 2020 at 4:57 PM ToddAndMargo via perl6-users <
perl6-users@perl.org> wrote:

> On 2020-08-31 16:53, ToddAndMargo via perl6-users wrote:
> >>> On Mon, Aug 31, 2020, 4:20 PM ToddAndMargo via perl6-users
> >>> mailto:perl6-users@perl.org>> wrote:
> >>>
> >>> On 2020-08-31 05:53, Brian Duggan wrote:
> >>>  > On Monday, August 24, Curt Tilmes wrote:
> >>>  >> $ cat Lines.txt | raku -e '.say for lines()[3,2,5]'
> >>>  >
> >>>  > The -n flag is an option here too:
> >>>  >
> >>>  > raku -ne '.say if $++ == 3|2|5' Lines.txt
> >>>  >
> >>>  > Brian
> >>>  >
> >>>
> >
> >>>> Hi Bill,
> >>>>
> >>>> Works beatifically! And no bash pipe!
> >>>>
> >>>> $ raku -ne '.say if $++ == 3|2|5' Lines.txt
> >>>>     Line 2
> >>>> Line 3
> >>>> Line 5
> >>>>
> >>>> What is `$++`?
> >>>>
> >>>> -T
> >>>>
> >
> > On 2020-08-31 16:36, yary wrote:
> >> $ by itself is an anonymous variable, putting ++ after starts it at 0
> >> (hmm or nil?) and increments up.
> >>
> >> By putting the plus plus first, ++$, it will start at 1, thanks to
> >> pre-increment versus post increment
> >>
> >
> > Hi Yary,
> >
> > Excellent instructions!  It is a counter.   I found
> > it over on
> >
> >  https://docs.raku.org/perl6.html
> >
> > with a search on `$++`.  But I had to pick it up
> > from "context"
> >
> >
> >
> > $ p6 'my @x=<"a" "b" "c">; for @x -> $i { print $++," ", ++$, " ", $i,
> > "\n";}'
> > 0 1 "a"
> > 1 2 "b"
> > 2 3 "c"
> >
> > Question: does the counter restart after its use, or do
> > I need to do it myself?
> >
> > -T
> >
>
> To answer my own question.  It resets itself:
>
> $ p6 'my @x=<"a" "b" "c">; for @x -> $i { print $++, " ", ++$, " ", $i,
> "\n" }; print "\n", $++, "\n";'
> 0 1 "a"
> 1 2 "b"
> 2 3 "c"
>
> 0
>
>
>
> --
> ~~
> Computers are like air conditioners.
> They malfunction when you open windows
> ~~
>


Re: print particular lines question

2020-08-31 Thread yary
Answering my own question, the operator sets the type of $. That's what
gradual typing is all about!

$ seq 5 | raku -ne "say $++"

0

1

2

3

4

$ seq 5 | raku -ne "say $ ~= 'Hi' "

Hi

HiHi

HiHiHi

HiHiHiHi

HiHiHiHiHi

$ seq 5 | raku -ne "say $++, $ ~= ' Hi' "

0 Hi

1 Hi Hi

2 Hi Hi Hi

3 Hi Hi Hi Hi

4 Hi Hi Hi Hi Hi

-y


On Mon, Aug 31, 2020 at 4:39 PM Aureliano Guedes 
wrote:

> Basically :
>
> $ raku -e 'my $a = 1; say ++$a; say $a'
> 2
> 2
> $ raku -e 'my $a = 1; say $a++; say $a'
> 1
> 2
>
> On Mon, Aug 31, 2020 at 8:36 PM yary  wrote:
>
>> $ by itself is an anonymous variable, putting ++ after starts it at 0
>> (hmm or nil?) and increments up.
>>
>> By putting the plus plus first, ++$, it will start at 1, thanks to
>> pre-increment versus post increment
>>
>> On Mon, Aug 31, 2020, 4:20 PM ToddAndMargo via perl6-users <
>> perl6-users@perl.org> wrote:
>>
>>> On 2020-08-31 05:53, Brian Duggan wrote:
>>> > On Monday, August 24, Curt Tilmes wrote:
>>> >> $ cat Lines.txt | raku -e '.say for lines()[3,2,5]'
>>> >
>>> > The -n flag is an option here too:
>>> >
>>> > raku -ne '.say if $++ == 3|2|5' Lines.txt
>>> >
>>> > Brian
>>> >
>>>
>>> Hi Bill,
>>>
>>> Works beatifically! And no bash pipe!
>>>
>>> $ raku -ne '.say if $++ == 3|2|5' Lines.txt
>>> Line 2
>>> Line 3
>>> Line 5
>>>
>>> What is `$++`?
>>>
>>> -T
>>>
>>
>
> --
> Aureliano Guedes
> skype: aureliano.guedes
> contato:  (11) 94292-6110
> whatsapp +5511942926110
>


Re: print particular lines question

2020-08-31 Thread yary
$ by itself is an anonymous variable, putting ++ after starts it at 0 (hmm
or nil?) and increments up.

By putting the plus plus first, ++$, it will start at 1, thanks to
pre-increment versus post increment

On Mon, Aug 31, 2020, 4:20 PM ToddAndMargo via perl6-users <
perl6-users@perl.org> wrote:

> On 2020-08-31 05:53, Brian Duggan wrote:
> > On Monday, August 24, Curt Tilmes wrote:
> >> $ cat Lines.txt | raku -e '.say for lines()[3,2,5]'
> >
> > The -n flag is an option here too:
> >
> > raku -ne '.say if $++ == 3|2|5' Lines.txt
> >
> > Brian
> >
>
> Hi Bill,
>
> Works beatifically! And no bash pipe!
>
> $ raku -ne '.say if $++ == 3|2|5' Lines.txt
> Line 2
> Line 3
> Line 5
>
> What is `$++`?
>
> -T
>


Re: print particular lines question

2020-08-31 Thread yary
Aww don't you remember Raku's earliest(?) contribution to Perl? I was so
happy when this arrived, and sad over its subsequent neglect

perl -ne 'no warnings "experimental"; print if $. ~~ [3,5,11]' line0-10.txt


-y


On Mon, Aug 31, 2020 at 8:28 AM William Michels via perl6-users <
perl6-users@perl.org> wrote:

> How would P5 handle line numbers > 10 ? Not getting back line #11 with
> the P5 examples below:
>
> $ raku -ne '.say if ++$ == 3|2|5|11' test_lines.txt
> Line 2
> Line 3
> Line 5
> Line 11
>
> ~$ perl -ne 'print if $. =~ /\b[3 2 5 11]\b/' test_lines.txt
> Line 1
> Line 2
> Line 3
> Line 5
>
> ~$ perl -ne 'print if $. =~ /\b[3,2, 5, 11]\b/' test_lines.txt
> Line 1
> Line 2
> Line 3
> Line 5
>
> On Mon, Aug 31, 2020 at 8:17 AM Brian Duggan  wrote:
> >
> > On Monday, August 31, Andy Bach wrote:
> > > >  raku -ne '.say if $++ == 3|2|5' Lines.txt
> > >
> > > OT, maybe, but is
> > > perl -ne 'print if $. =~ /\b[325]\b/' Lines.txt
> > >
> > > or
> > > perl -ne 'print if $c++ =~ /\b[436]\b/' Lines.txt
> > >
> > > the best you can do in P5?
> >
> > I can't think of anything better :-)
> >
> > Brian
>


Re: lines :$nl-in question

2020-08-30 Thread yary
+1 on Matthew's comment

Do you agree with that definition, Yary? Brad? Here it is:
> "Invocant"
> "Caller, the one who calls or invokes. The invocant of a method would
> be the object on which that method is being called, or, in some cases,
> the class itself. Invocant is used instead of caller because the
> latter refers to the scope."


I have a quibble there. 1st & 2nd sentences disagree slightly by going from
active to passive voice. "Caller, the one who calls" vs "object on which
that method is being called"

Suggestion for 2nd sentence "The invocant of a method would be the object
calling the method" ... if that is correct!

On Sun, Aug 30, 2020 at 2:08 PM Stuckwisch, Matthew <
matthew-stuckwi...@utc.edu> wrote:

> So I guess I got included on this as the resident language professor :-)
> (although I probably should subscribe to p6 users at some point)  I
> didn't see the whole thread in the e-mail I got copied in on, so apologizes
> if I repeat much.
>
> I'll spare everyone all the linguistic details, but suffice it to say,
> invocant and invoker are functionally equivalent.  The former is a
> nominalized adjective, and the latter a noun proper.  They mean "the one
> that invokes (calls)".   We can use either, but I'd recommend we be very
> consistent.  Invocant seems to be the preferred, so let's use it
> exclusively.  On the other side, we have invoked and invokee, which in
> English share a similar distinction (although nominalizing the former often
> sounds odd, and adjectifying the latter would probably be read as missing a
> genitive 's).
>
> Summed up, we should avoid using invocant to refer to a method that's
> being called.  Generally, just calling it a "method" is sufficient, but if
> need be, I'd go with "the invoked method".  We probably can write
> documentation to avoid the formalisms altogether, though, by saying
> something to the effect of
>
> > Opens the file [represented by the [calling] object] and returns its
> lines.
>
> That's fairly simple and clear.  In an article about signatures, however,
> I think using the term is absolutely appropriate, and warrants defining it
> parenthetically inline as "the object that calls/invokes the associated
> method".  I get that using the word "call" muddies the water (the formal
> distinction that tchrist was getting at is that a sub has no invocant
> except perhaps a calling context, ie the "caller" — which a method also
> has), but we already did that by having methods use CALL-ME instead of
> INVOKE-ME :-) *
>
> MSS
>
>
> * Of course, the reason was to harmonize calls of all code, and the fluid
> nature of allowing transitive methods be used as subs and viceversa (method
> $invocant: @args and $invocant.&sub) means that one term had to rule them
> all.
>
> --
> *From:* William Michels 
> *Sent:* Sunday, August 30, 2020 2:44:55 PM
> *To:* yary 
> *Cc:* perl6-users ; ToddAndMargo <
> toddandma...@zoho.com>; Brad Gilbert 
> *Subject:* Re: lines :$nl-in question
>
> Do you agree with that definition, Yary? Brad? Here it is:
>
> "Invocant"
>
> "Caller, the one who calls or invokes. The invocant of a method would
> be the object on which that method is being called, or, in some cases,
> the class itself. Invocant is used instead of caller because the
> latter refers to the scope."
>
> https://docs.raku.org/language/glossary#Invocant
>
> At first blush, the definition at
> https://docs.raku.org/language/glossary#Invocant contradicts the
> definition given to us by Brad. English speaker will typically use the
> following word pairs to denote 1. an actor and 2. a recipient of some
> action. So we have the following:
>
> Payer vs. Payee
> Lessor vs. Lessee
> Employer vs. Employee
>
> So going with the typical English usage above, the pattern would
> continue with "Caller" vs "Callee" and "Invoker" vs
> "Invokee/Invocant".  Therefore my humble reading of the definition
> given by Brad, as well as a post authored by a certain TChrist on
> StackExchange [1], suggests to me that "Invocant" is a synonym for
> "Callee" (or the possibly-imaginary word "Invokee"). One can look at
> the definition of "Invoker" online provided by Oracle with regards to
> the Java programming language [2], to further distinguish "Invoker" vs
> "Invocant".
>
> HTH, Bill.
>
> W. Michels, Ph.D.
>
> [1] https://english.stackexchange.com/a/59070
> [2]
> https://docs.oracle.com/javas

Re: lines :$nl-in question

2020-08-30 Thread yary
The Raku glossary has a definition
https://docs.raku.org/language/glossary#Invocant

suggestion, link to that where the term appears.

-y


On Sun, Aug 30, 2020 at 9:16 AM William Michels via perl6-users <
perl6-users@perl.org> wrote:

> Inline:
>
> On Sun, Aug 30, 2020 at 12:49 AM Brad Gilbert  wrote:
> >
> > 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.
>
> Maybe we can meet Todd halfway?
>
> >
> > On Sat, Aug 29, 2020 at 6:39 PM ToddAndMargo via perl6-users <
> perl6-users@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.
>
>
> "Opens the invocant (i.e. the object being called) and returns its lines."
>
> [Add text in parentheses above only once per method, when the word
> 'invocant' is first used].
>
> Comments?
>
> Best Regards, Bill.
>


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

2020-08-30 Thread yary
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-users@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: liens and :chomp question

2020-08-30 Thread yary
Expanding on how to read the docs & signature a bit, from Tobias

> You confuse two methods that have the same name "lines". One of them,
> which exists in the IO::Path class, has a :chomp argument. The other,
> on IO::Handle does not.
>   "path".IO.lines()   <-- calls lines on an IO::Path (supports :chomp)
>   "path".IO.open.lines()  <-- calls lines on an IO::Handle (does not
> support :chomp)


Looking up https://docs.raku.org/routine/lines shows a Table of Contents
with

class Cool
(Cool) routine lines
class Supply
(Supply) method lines
class Str
(Str) routine lines
class IO::CatHandle
(IO::CatHandle) method lines
class IO::Path
(IO::Path) method lines
class IO::Handle
(IO::Handle) routine lines
class IO::Socket::INET
(IO::Socket::INET) method lines


Lots of different "lines" methods. If I click on IO::Handle it jumps to
sub  lines( $what = $*ARGFILES, |c)
multi method lines( IO::Handle:D: $limit, :$close )
multi method lines( IO::Handle:D: :$close )

which indeed has no named argument for "chomp"

As an aside-Reading between the lines (no pun intended), I deduce that the
IO::Handle "lines" method is its own implementation so that it can read
"lazily" as needed, and to support the "close" option.

And as another aside, it has a "sub" which shows that when "lines" is
called with no arguments, it defaults to reading from $*ARGFILES.

So, back to the table of contents. How does one know which "lines" routine
to look at?

Either by thinking & remembering --
"oh 'file'.IO.open returns an IO::Handle that's the one to read"
"Huh 'file'.IO returns a path object, and there's *'(IO::Path) method*
*lines'* listed lets look at that, hmm it has *chomp*"

or by experiment!
> 'example.txt'.IO.WHAT
(Path)
> 'example.txt'.IO.open.WHAT
(Handle)

-y


On Sun, Aug 30, 2020 at 12:56 AM ToddAndMargo via perl6-users <
perl6-users@perl.org> wrote:

> On 2020-08-30 00:35, Tobias Boege wrote:
> > On Sun, 30 Aug 2020, ToddAndMargo via perl6-users wrote:
> >>> - You are calling .lines on the value of .IO.open which is an
> >>>   IO::Handle. IO::Handle.lines does not take a named argument
> >>>   :chomp, so passing one is useless.
> >>
> >> That explains it.
> >>
> >> Bu:
> >>   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.
> >>
> >> The "signature" line (cryptogram) clearly stated that
> >> ":$chomp" is a parameter of the method.
> >>
> >> Now you are obviously correct that :chomp is ignored.
> >> If I am not mistaken, I have just tripped over another
> >> error in the documentation.  Your take?
> >>
> >
> > You confuse two methods that have the same name "lines". One of them,
> > which exists in the IO::Path class, has a :chomp argument. The other,
> > on IO::Handle does not.
> >
> >"path".IO.lines()   <-- calls lines on an IO::Path (supports
> :chomp)
> >"path".IO.open.lines()  <-- calls lines on an IO::Handle (does not
> support :chomp)
> >
> > In the second case, if you want chomping to happen you have to pass
> > the :chomp to the *open* call, as you do below:
>
> Hi Tobias,
>
> The terrible example they included was:
> '50GB-file'.IO.lines.grep(*.contains: 'Perl').elems,
>" lines that mention Perl";
>
> I left off the "grep" and the "elems".
>
> "Lines.txt".IO.open.lines
>
> This was the example they gave for
>
> method lines(IO::Path:D: :$chomp = True, :$enc = 'utf8', :$nl-in =
> ["\x0A", "\r\n"], |c --> Seq:D)
>
> Exactly what is "IO::Path:D:"?
>
> I know that :D is declared and the ":" after it
> is a delimiter.  That leaved "IO::Path":
>
> https://docs.raku.org/type/IO::Path
>
> And I can't make heads or tails out of the page.
>
> My goal is to learn how to use :$chomp = True,
> :$enc = 'utf8', :$nl-in, and, |c
>
> Thank you for the help!
> -T
>


Re: lines :$nl-in question

2020-08-30 Thread yary
The :foo syntax is called a "colon pair", and colon pair also
describes :quux since it is short for :quux(True)

Colon pair also describes :$foo because it is a shorthand using a colon to
create the Pair object foo=>$foo

Searching raku docs showed
https://docs.raku.org/language/glossary#index-entry-Colon_Pair

which also says that putting a bunch of those together creates a "colon
list"

It also has a link to Adverb https://docs.raku.org/language/glossary#Adverb

which shows how colon pairs can be used to set named arguments–when used
that way, a colon pair is also called an "adverbial pair."

-y


On Sun, Aug 30, 2020 at 2:50 AM ToddAndMargo via perl6-users <
perl6-users@perl.org> wrote:
>
> >> On Sat, Aug 29, 2020 at 9:05 PM ToddAndMargo via perl6-users
> >> mailto:perl6-users@perl.org>> wrote:
>
> >> And if you would not mind, what is the official name
> >> of variables that begin with ":"
> >>
>
> On 2020-08-30 00:43, Brad Gilbert wrote:
> > 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)
>
>
> Follow up questions:
>
> 1) what is the exact name used to describe these critters?
>
> 2) is there a manual page on them?


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

2020-08-28 Thread yary
Right after sending I saw that the semicolon wasn't the issue, sorry! The
second half of my message is correct I think. The command reads a line at a
time, then calls lines()[3,2,5] on that single line which has no lines
after the zeroth.

tee hee, zeroth is a word!

-y


On Fri, Aug 28, 2020 at 10:59 AM William Michels 
wrote:

> I remove the semicolon, and it throws an error:
>
> $ cat test_lines.txt | raku -ne 'my $x=$_; say $x for
> $x.lines()[3,2,5] -> $i {say $i;}'
> ===SORRY!=== Error while compiling -e
> Unexpected block in infix position (missing statement control word
> before the expression?)
> at -e:1
> --> my $x=$_; say $x for $x.lines()[3,2,5] ->
> expecting any of:
> infix
> infix stopper
>
> What's the correct code?
>
> Best, Bill.
>
>
> On Thu, Aug 27, 2020 at 2:12 PM yary  wrote:
> >
> > You have an extra semicolon in there -" say $x; for" -
> >
> > so what happens is for each line
> > 1. it runs "say $x" and thus prints "Line 0" the first time through,
> since it had read "Line 0" only
> > 2. Then it runs "say $i" for each of $x.lines()[3,2,5] - but $x is only
> "Line 0" so it says 3 x "Nil"
> > 3. Repeat for "Line 1", etc
> > -y
> >
> >
> > On Thu, Aug 27, 2020 at 1:40 PM ToddAndMargo via perl6-users <
> perl6-users@perl.org> wrote:
> >>
> >> On 2020-08-27 13:28, Tobias Boege wrote:
> >> > On Thu, 27 Aug 2020, ToddAndMargo via perl6-users wrote:
> >> >> To pick out particular lines:
> >> >> $ cat Lines.txt | raku -e '.say for lines()[3,2,5]'
> >> >> Line 3
> >> >> Line 2
> >> >> Line 5
> >> >>
> >> >> If it is, it is buried somewhere.
> >> >>
> >> >> And what goes inside the ()?  That may seem like a dumb
> >> >> remark (especially since I live and die in Top Down and
> >> >> know very well what the () does) but it is a common mistake
> >> >> I make with lines is forgetting the () when using the [].
> >> >>
> >> >
> >> > How does that mistake manifest? I cannot see a way in which omitting
> >> > the sub call parentheses in code like that could possibly lead to some
> >> > different behavior.
> >> >
> >>
> >> Here is does not:
> >>
> >> $ cat Lines.txt | raku -e '.say for lines[3,2,5]'
> >> Line 3
> >> Line 2
> >> Line 5
> >>
> >> And I am having trouble reproducing the issue.  Would
> >> help my point, no?  I will write back if I find it.
> >> Usually I forget my mistakes as soon as I figure out
> >> the right way to do things.
> >>
> >> Now this is getting weird!
> >>
> >> $ cat Lines.txt | raku -ne 'my $x=$_; say $x; for $x.lines()[3,2,5] ->
> >> $i {say $i;}'
> >>
> >> Line 0
> >> Nil
> >> Nil
> >> Nil
> >> Line 1
> >> Nil
> >> Nil
> >> Nil
> >> Line 2
> >> ...
>


Re: Extended identifiers in named attributes

2020-08-28 Thread yary
I wonder what was intended with these extended identifiers?
https://github.com/Raku/problem-solving/issues/224* - Extended
identifiers-why and where, exactly?*
-y


On Fri, Aug 28, 2020 at 8:26 AM Ralph Mellor 
wrote:

> I don't think you're supposed to be able to have extended identifiers
> as named parameter/argument identifiers. They are meant for a few
> specific scenarios where there's special value in having adverbs aka
> pairs embedded in identifiers:
>
> * Alternations in grammars. Typically of form `foo:sym`.
>
> * Appending :api<>, :auth<>, :ver<> to package identifiers.
>
> They *may* work in a couple of other scenarios but in general,
> don't do that.
>
> By the way, "attributes" has a specific meaning in Raku, namely the
> fields of object instances.
>
> --
> love, raiph
>
>
> On Wed, Aug 26, 2020 at 1:31 PM 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: Raku User's Survey 2020 out now....

2020-08-27 Thread yary
You have an extra semicolon in there -" say $x; for" -

so what happens is for each line
1. it runs "say $x" and thus prints "Line 0" the first time through, since
it had read "Line 0" only
2. Then it runs "say $i" for each of $x.lines()[3,2,5] - but $x is only
"Line 0" so it says 3 x "Nil"
3. Repeat for "Line 1", etc
-y


On Thu, Aug 27, 2020 at 1:40 PM ToddAndMargo via perl6-users <
perl6-users@perl.org> wrote:

> On 2020-08-27 13:28, Tobias Boege wrote:
> > On Thu, 27 Aug 2020, ToddAndMargo via perl6-users wrote:
> >> To pick out particular lines:
> >> $ cat Lines.txt | raku -e '.say for lines()[3,2,5]'
> >> Line 3
> >> Line 2
> >> Line 5
> >>
> >> If it is, it is buried somewhere.
> >>
> >> And what goes inside the ()?  That may seem like a dumb
> >> remark (especially since I live and die in Top Down and
> >> know very well what the () does) but it is a common mistake
> >> I make with lines is forgetting the () when using the [].
> >>
> >
> > How does that mistake manifest? I cannot see a way in which omitting
> > the sub call parentheses in code like that could possibly lead to some
> > different behavior.
> >
>
> Here is does not:
>
> $ cat Lines.txt | raku -e '.say for lines[3,2,5]'
> Line 3
> Line 2
> Line 5
>
> And I am having trouble reproducing the issue.  Would
> help my point, no?  I will write back if I find it.
> Usually I forget my mistakes as soon as I figure out
> the right way to do things.
>
> Now this is getting weird!
>
> $ cat Lines.txt | raku -ne 'my $x=$_; say $x; for $x.lines()[3,2,5] ->
> $i {say $i;}'
>
> Line 0
> Nil
> Nil
> Nil
> Line 1
> Nil
> Nil
> Nil
> Line 2
> ...
>


Re: Associative class for any key, any value

2020-08-26 Thread yary
Yep that's it, thanks!

> my Any %h{ Any };

> %h{ 22 } = "foo"; %h{ "22" } = IO; %h{ IO } = sub { ... };

> %h.kv.raku;

(IO, sub { ... }, 22, "foo", "22", IO).Seq
-y


On Wed, Aug 26, 2020 at 8:04 PM Brad Gilbert  wrote:

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


Associative class for any key, any value

2020-08-26 Thread yary
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?

-y


Re: print particular lines question

2020-08-25 Thread yary
> Now, does anyone have a simpler way than using the ".map" above?

There were a few in the thread!

Here's my golfing, unlike the others, this preserves the order of the lines
(which may or may not be desired)

raku -ne '.say if $++ == any 6,3,1' line0-10.txt

-y


On Tue, Aug 25, 2020 at 12:03 PM William Michels via perl6-users <
perl6-users@perl.org> wrote:

> If Todd wants to print lines containing "Line 1", "Line 3", and "Line 7",
> he's going to have to correct for zero-indexing:
>
> user@book:~$ raku -e '$*IN.lines[ 1,3,7 ].join("\n").put;' < Lines.txt
> Line 2
> Line 4
> Line 8
>
> #Below: subtracting one from (1,3,7) gives the return he wants:
>
> user@book:~$ raku -e '$*IN.lines[ (1,3,7).map: { $_ - 1 }
> ].join("\n").put;' < Lines.txt
> Line 1
> Line 3
> Line 7
>
> Now, does anyone have a simpler way than using the ".map" above?
>
> HTH, Bill.
>
>
>
> On Tue, Aug 25, 2020 at 10:46 AM Andy Bach 
> wrote:
>
>> Ah, I see, the -n reads a line and then my lines on $*IN starts with the
>> next one
>> C:\> type lines.txt | "\Program Files (x86)\rakudo\bin\raku.exe"   -e "my
>> @x = $*IN.lines(); say @x[0,1,7,3]; "
>> (Line 0 Line 1 Line 7 Line 3)
>>
>> and so $*IN is the default for lines()
>> C:\> type lines.txt | "\Program Files (x86)\rakudo\bin\raku.exe"   -e "my
>> @x = lines(); say @x[0,1,7,3]; "
>> (Line 0 Line 1 Line 7 Line 3)
>>
>> This hangs, with and without the -n
>> C:\> "\Program Files (x86)\rakudo\bin\raku.exe"   -ne "my @x =
>> $*IN.lines(); say @x[0,1,7,3]; " lines.txt
>>
>> Though:
>> C:\> "\Program Files (x86)\rakudo\bin\raku.exe"   -ne "my @x = lines();
>> say @x[0,1,7,3]; " lines.txt
>> (Line 1 Line 2 Line 8 Line 4)
>> Cannot do 'get' on a handle in binary mode
>>   in block  at -e line 1
>>
>> a
>>
>> Andy Bach, BS, MSCMECFA
>> Systems Mangler
>> Internet: andy_b...@wiwb.uscourts.gov
>> Voice: (608) 261-5738, Cell: (608) 658-1890
>>
>> "The three great problems of computer science:
>> compiler complexity and 'off-by-one' errors".
>> https://martinfowler.com/bliki/TwoHardThings.html
>>
>> --
>> *From:* Andy Bach 
>> *Sent:* Tuesday, August 25, 2020 12:18 PM
>> *To:* Parrot Raiser <1parr...@gmail.com>
>> *Cc:* perl6-users ; ToddAndMargo <
>> toddandma...@zoho.com>
>> *Subject:* Re: print particular lines question
>>
>> On Win10
>> C:\>type lines.txt | "\Program Files (x86)\rakudo\bin\raku.exe"   -ne
>> "say lines()[1,7,3]; "
>> (Line 2 Line 8 Line 4)
>> (Line 11 Nil Nil)
>>
>> C:\>type lines.txt | "\Program Files (x86)\rakudo\bin\raku.exe"   -ne
>> "say lines()[1,7,3].join(qq~\n~); "
>> Line 2
>> Line 8
>> Line 4
>> Use of Nil in string context
>>   in block  at -e line 1
>> Use of Nil in string context
>>   in block  at -e line 1
>> Line 11
>>
>> and, speaking of that off by one problem ... lines.txt does start with
>> "line 0"
>> C:\> type lines.txt | "\Program Files (x86)\rakudo\bin\raku.exe"   -ne
>> "my @x = $*IN.lines(); say @x[0,1,7,3]; "
>> (Line 1 Line 2 Line 8 Line 4)
>>
>> a
>>
>> Andy Bach, BS, MSCMECFA
>> Systems Mangler
>> Internet: andy_b...@wiwb.uscourts.gov
>> Voice: (608) 261-5738, Cell: (608) 658-1890
>>
>> "The three great problems of computer science:
>> compiler complexity and 'off-by-one' errors".
>> https://martinfowler.com/bliki/TwoHardThings.html
>>
>> --
>> *From:* Parrot Raiser <1parr...@gmail.com>
>> *Sent:* Tuesday, August 25, 2020 11:22 AM
>> *To:* Andy Bach 
>> *Cc:* perl6-users ; ToddAndMargo <
>> toddandma...@zoho.com>
>> *Subject:* Re: print particular lines question
>>
>> That will golf a little (and improve it) to:
>>
>> $ raku -e '.say for lines()[3,2,5]' lines.txt
>>
>> but you have to remember that it's zero-based. I used the first sample
>> file and got
>> Line 4
>> Line 3
>> Line 6
>>
>> "The three great problems of computer science: compiler complexity and
>> 'off-by-one' errors".
>>
>>
>> On 8/25/20, Andy Bach  wrote:
>> >> Assigning  `my @x=$_.lines` puts everything into $x[0]
>> >
>> > Trying this on windows
>> >
>> > C:\> raku.exe   -e "my @x = 'lines.txt'.IO.lines; say
>> > @x[1,7,3].join(qq~\n~); "
>> > Line 1
>> > Line 7
>> > Line 3
>> >
>> > or
>> > C:\> raku.exe -e " say 'lines.txt'.IO.lines[1,7,3].join(qq~\n~); "
>> > Line 1
>> > Line 7
>> > Line 3
>> >
>> > a
>> >
>> > Andy Bach, BS, MSCMECFA
>> > Systems Mangler
>> > Internet: andy_b...@wiwb.uscourts.gov> andy_b...@wiwb.uscourts.gov>
>> > Voice: (608) 261-5738, Cell: (608) 658-1890
>> >
>> > Every man has the right to an opinion but no man
>> > has a right to be wrong in his facts. Nor, above all,
>> > to persist in errors as to facts. Bernard Baruch
>> >
>> > 
>> > From: ToddAndMargo via perl6-users 
>> > Sent: Monday, August 24, 2020 9:35 PM
>> > To: perl6-users 
>> > Subject: print particular lines question
>> >
>> > Hi All,
>> >
>> > I seems I should know how to do this, but
>> > I am drawing a blank.
>> >
>> > $ cat Lines.txt | raku -ne 'say $_;'
>> > Line 1
>> > Line 2
>> > Line 3
>> > L

Re: Combining multiple "is..." traits into one?

2020-08-11 Thread yary
I played with the "is" trait and I is puzzled. This example code

multi trait_mod: (Routine \routine, :$equality!) {
trait_mod:(routine, :equiv(&infix:<==>));
}

sub is-eq is equality { ... }
say 'is-eq  ', &is-eq.prec;

multi trait_mod: (Routine \routine, :$chainable!) {
trait_mod:(routine, :assoc);
}

sub chained is chainable { ... }
say 'chained', &chained.prec;

multi trait_mod: (Routine \routine, :$equivalence!) {
trait_mod:(routine,:equality);
trait_mod:(routine,:chainable);
}

# Uncomment these two lines
# sub trait-er is equality is chainable { ... }
# say 'trait-er   ', &trait-er.prec;

# or uncomment these two lines
# sub jolly-trait is equivalence { ... }
# say 'jolly-trait',&jolly-trait.prec;


run it as-is, and the results make sense to me
is-eq  {iffy => 1, pasttype => chain, prec => m=}
chained{assoc => chain}

if I uncomment either of the two-line stanzas at the end, the output of
is-eq also changes.

is-eq  {*assoc => chain*, iffy => 1, pasttype => chain, prec => m=}
chained{assoc => chain}
trait-er   {assoc => chain, iffy => 1, pasttype => chain, prec => m=}

is-eq  {*assoc => chain*, iffy => 1, pasttype => chain, prec => m=}
chained{assoc => chain}
jolly-trait{assoc => chain, iffy => 1, pasttype => chain, prec => m=}

What is going on, why are the traits changing for 'is-eq' in the
uncommented examples?

-y


On Tue, Aug 11, 2020 at 5:38 PM Stuart Hungerford <
stuart.hungerf...@gmail.com> wrote:

> On Wed, Aug 12, 2020 at 8:12 AM Tobias Boege  wrote:
>
> > [...]
> > > Would a custom version of the trait_mod: routine do the trick?
> >
> > Yes:
> >
> >   multi trait_mod: (Routine $r, :$equivalence!) {
> >   trait_mod:($r, :equiv(&infix:<==>));
> >   trait_mod:($r, :assoc);
> >   }
>
> As a supplementary question: is it possible to build up trait
> modifications from simpler ones? Something like:
>
> multi trait_mod: (Routine \routine, :$equality!) {
>   trait_mod:(routine, :equiv(&infix:<==>));
> }
>
> multi trait_mod: (Routine \routine, :$chainable!) {
>   trait_mod:(routine, :assoc);
> }
>
> multi trait_mod: (Routine \routine, :$equivalence!) {
>   {magic to ensure routine is equality and routine is chainable}
> }
>
> Although I'm not yet sure that's a good idea.
>
> Thanks,
>
> Stu
>


Re: Avoiding monkey typing for custom roles on built-in types...

2020-08-09 Thread yary
I only superficially read this question–but it does make me think of
coercing input types

https://docs.raku.org/language/functions.html#Coercion_types
https://stackoverflow.com/questions/34874779/what-is-the-point-of-coercions-like-intcool

If the methods that do the adding-of-magmas were written with coercion,
would you still want to monkey-type the built-ins?

method add(AddMagma(Cool):D, AddMagma(Cool):D) of AddMagma:D {...}

-y


On Sat, Aug 8, 2020 at 8:05 PM Stuart Hungerford <
stuart.hungerf...@gmail.com> wrote:

> Hi,
>
> I'm creating some Raku roles that model algebraic structures:
>
> role AddMagma {
>   method add(AddMagma:D, AddMagma:D) of AddMagma:D {...}
> }
>
> role AddSemigroup does AddMagma {
>   multi method add-associativity(AddSemigroup:D \x, AddSemigroup:D \y)
> of Bool:D {
> self.add(x.add(y)) == (self.add(x)).add(y)
>   }
> }
>
> All the built-in numeric types are (ignoring floating point issues)
> additive magmas and additive semigroups. So my first thought was to
> monkey type the appropriate classes to do these roles:
>
> use MONKEY-TYPING;
>
> augment class Int does AddMagma {
>   method add(Int:D \x) of Int:D {
> self + x
>   }
> }
>
> augment class Int does AddSemigroup {}
>
> # and similar for other built-in types.
>
> Then I can test the structure properties with built-in numeric values:
>
> say "Int addition is associative: ", 42.add-associativity(43, 44);
>
> BUT: monkey typing like this is frowned upon (with good reason no doubt)
> and can't be done on numeric roles like Numeric, which are "sealed".
>
> Would a better approach be to create custom subtypes of the built-in
> numeric types that mixin the algebraic roles? Is there an idiomatic way
> avoid boilerplate code in creating instances of these custom subtypes?
>
> Any advice much appreciated,
>
> Stu
>


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

2020-08-03 Thread yary
I opened a Raku ticket https://github.com/rakudo/rakudo/issues/3839
-y


On Sun, Aug 2, 2020 at 5:42 PM Eirik Berg Hanssen <
eirik-berg.hans...@allverden.no> wrote:

> On Sun, Aug 2, 2020 at 11:14 PM yary  wrote:
>
>> Issue golf, ff is always evaluating its RHS
>>
>> $ raku -e 'say "With ff: ";say ( 1..5 ).grep({False ff .say}); say "With
>> fff: ";say ( 1..5 ).grep({False fff .say});'
>> With ff:
>> 1
>> 2
>> 3
>> 4
>> 5
>> ()
>> With fff:
>> ()
>>
>
>   I haven't looked much at Raku since it was Perl6, but for comparison,
> here's some Perl 5:
>
> $ perl -E 'say "With ..: ";say grep {/nope/ .. say} 1..5; say "With ...:
> ";say grep {/nope/ ... say} 1..5;'
> With ..:
>
> With ...:
>
>
> Eirik
>


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

2020-08-02 Thread yary
Issue golf, ff is always evaluating its RHS

$ raku -e 'say "With ff: ";say ( 1..5 ).grep({False ff .say}); say "With
fff: ";say ( 1..5 ).grep({False fff .say});'
With ff:
1
2
3
4
5
()
With fff:
()


-y


On Sun, Aug 2, 2020 at 2:16 PM yary  wrote:

> tl;dr: is this a Rakudo issue?
>
> ooh a puzzle 😀 why do 'ff' and 'fff' give different results in this case?
> The start & end are disjoint, the $++ should only run when the string test
> is true, so I expect 'ff' and 'fff' to behave the same also.
>
> Golfing a little
>
> $ raku -e 'my @input=qw G - 4 5 - hide>; \
> say "With ff:  ",@input.grep({($_ eq "+" && $++ < 2) ff  ($_ eq "-" && $++
> < 2)}); \
> say "With fff: ",@input.grep({($_ eq "+" && $++ < 2) fff ($_ eq "-" && $++
> < 2)});'
>
> With ff:  (+ B C D - + E F - 2 3 - never never + G - 4 5 - hide)
> With fff: (+ B C D - + E F -)
>
> With both of these, the flip-flop turns on with the first '+' and turns
> off with the first '-'
> With both of these, the 2nd '+' turns on the flip-flop.
> WIth 'ff', the flip-flop never turns off, with 'fff' the flip-flop turns
> off when it encounters the next '-'
>
> I wonder... let's have the end of the flip-flop say every time it runs
>
> raku -e 'my @input=qw G - %% && - hide>; \
> say "With ff: ";say @input.grep({($_ eq "+" && $++ < 2) ff  ("checking
> $_".say && $_ eq "-" && say "increment to " ~ ++$ )}); \
> say "With fff:";say @input.grep({($_ eq "+" && $++ < 2) fff ("checking
> $_".say && $_ eq "-" && say "increment to " ~ ++$ )});'
>
> With ff:
> checking nope
> checking +
> checking B
> checking C
> checking D
> checking -
> increment to 1
> checking ??
> checking -
> increment to 2
> checking no
> checking +
> checking E
> checking F
> checking -
> increment to 3
> checking !!
> checking ##
> checking -
> increment to 4
> checking never
> checking never
> checking +
> checking G
> checking -
> increment to 5
> checking %%
> checking &&
> checking -
> increment to 6
> checking hide
> (+ B C D - + E F -)
> With fff:
> checking B
> checking C
> checking D
> checking -
> increment to 1
> checking E
> checking F
> checking -
> increment to 2
> (+ B C D - + E F -)
>
> Hey gurus, why is the end check in 'ff' running so much more often than
> the end check of 'fff' ?
>
> ps. I had many weird errors, due to having "rake" installed, and having
> something autocorrect my "raku" command-line to "rake"!!!
>
> -y
>
>
> On Sat, Aug 1, 2020 at 10:06 PM William Michels 
> wrote:
>
>> Hi Yary, Nice code!
>>
>> The general approach of using an anonymous counter is useful to me. Below
>> are  examples when I only want to recover the first one or two blocks of
>> text starting with "Start" and ending with "Mark" (nota bene: I took your
>> example text and deleted the blank lines):
>>
>> user@book:~$ raku -ne ' say $_ if ($_ eq "Start" && $++ < 1) fff ($_ eq
>> "Mark" && $++ < 1);' yary_ff_example2.txt
>> Start
>> hi print me
>> yes!
>> Mark
>> user@mbook:~$ raku -ne ' say $_ if ($_ eq "Start" && $++ < 1) ff ($_ eq
>> "Mark" && $++ < 1);' yary_ff_example2.txt
>> Start
>> hi print me
>> yes!
>> Mark
>> user@mbook:~$ raku -ne ' say $_ if ($_ eq "Start" && $++ < 2) fff ($_ eq
>> "Mark" && $++ < 2);' yary_ff_example2.txt
>> Start
>> hi print me
>> yes!
>> Mark
>> Start
>> We're back!
>> Mark
>> user@mbook:~$ raku -ne ' say $_ if ($_ eq "Start" && $++ < 2) ff ($_ eq
>> "Mark" && $++ < 2);' yary_ff_example2.txt
>> Start
>> hi print me
>> yes!
>> Mark
>> Start
>> We're back!
>> Mark
>> Still here!
>> Start
>> haha that Start does nothing
>> going to end it now
>> Mark
>> !bye bye don't see me!
>> user@mbook:~$
>>
>> I guess I have to say--I'm still a little surprised by the last result
>> using the "ff" infix op

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

2020-08-02 Thread yary
tl;dr: is this a Rakudo issue?

ooh a puzzle 😀 why do 'ff' and 'fff' give different results in this case?
The start & end are disjoint, the $++ should only run when the string test
is true, so I expect 'ff' and 'fff' to behave the same also.

Golfing a little

$ raku -e 'my @input=qw; \
say "With ff:  ",@input.grep({($_ eq "+" && $++ < 2) ff  ($_ eq "-" && $++
< 2)}); \
say "With fff: ",@input.grep({($_ eq "+" && $++ < 2) fff ($_ eq "-" && $++
< 2)});'

With ff:  (+ B C D - + E F - 2 3 - never never + G - 4 5 - hide)
With fff: (+ B C D - + E F -)

With both of these, the flip-flop turns on with the first '+' and turns off
with the first '-'
With both of these, the 2nd '+' turns on the flip-flop.
WIth 'ff', the flip-flop never turns off, with 'fff' the flip-flop turns
off when it encounters the next '-'

I wonder... let's have the end of the flip-flop say every time it runs

raku -e 'my @input=qw; \
say "With ff: ";say @input.grep({($_ eq "+" && $++ < 2) ff  ("checking
$_".say && $_ eq "-" && say "increment to " ~ ++$ )}); \
say "With fff:";say @input.grep({($_ eq "+" && $++ < 2) fff ("checking
$_".say && $_ eq "-" && say "increment to " ~ ++$ )});'

With ff:
checking nope
checking +
checking B
checking C
checking D
checking -
increment to 1
checking ??
checking -
increment to 2
checking no
checking +
checking E
checking F
checking -
increment to 3
checking !!
checking ##
checking -
increment to 4
checking never
checking never
checking +
checking G
checking -
increment to 5
checking %%
checking &&
checking -
increment to 6
checking hide
(+ B C D - + E F -)
With fff:
checking B
checking C
checking D
checking -
increment to 1
checking E
checking F
checking -
increment to 2
(+ B C D - + E F -)

Hey gurus, why is the end check in 'ff' running so much more often than the
end check of 'fff' ?

ps. I had many weird errors, due to having "rake" installed, and having
something autocorrect my "raku" command-line to "rake"!!!

-y


On Sat, Aug 1, 2020 at 10:06 PM William Michels 
wrote:

> Hi Yary, Nice code!
>
> The general approach of using an anonymous counter is useful to me. Below
> are  examples when I only want to recover the first one or two blocks of
> text starting with "Start" and ending with "Mark" (nota bene: I took your
> example text and deleted the blank lines):
>
> user@book:~$ raku -ne ' say $_ if ($_ eq "Start" && $++ < 1) fff ($_ eq
> "Mark" && $++ < 1);' yary_ff_example2.txt
> Start
> hi print me
> yes!
> Mark
> user@mbook:~$ raku -ne ' say $_ if ($_ eq "Start" && $++ < 1) ff ($_ eq
> "Mark" && $++ < 1);' yary_ff_example2.txt
> Start
> hi print me
> yes!
> Mark
> user@mbook:~$ raku -ne ' say $_ if ($_ eq "Start" && $++ < 2) fff ($_ eq
> "Mark" && $++ < 2);' yary_ff_example2.txt
> Start
> hi print me
> yes!
> Mark
> Start
> We're back!
> Mark
> user@mbook:~$ raku -ne ' say $_ if ($_ eq "Start" && $++ < 2) ff ($_ eq
> "Mark" && $++ < 2);' yary_ff_example2.txt
> Start
> hi print me
> yes!
> Mark
> Start
> We're back!
> Mark
> Still here!
> Start
> haha that Start does nothing
> going to end it now
> Mark
> !bye bye don't see me!
> user@mbook:~$
>
> I guess I have to say--I'm still a little surprised by the last result
> using the "ff" infix operator. I'd appreciate knowing why "ff" and "fff"
> behave differently in the last two examples, since the beginning marker
> doesn't look anything like the end marker (suggesting they should act
> identically). Also, is there a simpler way to write the conditional?
>
> Thx, Bill.
>
>
>
> On Sat, Aug 1, 2020 at 4:04 PM yary  wrote:
> >
> > This made me want to try a contrived puzzle, use 'fff' to show things
> between a "start" and 2nd "mark" line. That is, print any line below not
> marked with "!" at the start
> >
> > $ cat example.txt
> >
> > !ignore me
> >
> > Start
> >
> > hi print me
> >
> > yes!
> >
> > Mark
> >
> > still print me
> >
> > Mark
> >
> > !ignore this line
> >
> > !this l

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

2020-08-01 Thread yary
This made me want to try a contrived puzzle, use 'fff' to show things
between a "start" and 2nd "mark" line. That is, print any line below not
marked with "!" at the start

$ cat example.txt

!ignore me

Start

hi print me

yes!

Mark

still print me

Mark

!ignore this line

!this line too

Start

We're back!

Mark

Still here!

Start

haha that Start does nothing

going to end it now

Mark

!bye bye don't see me!

Let's see...ooh that was easy!!

raku -ne '.say if "Start" ff ($_ eq "Mark" && ++$ %% 2)' example.txt

That increments the anonymous state variable $ and then checks if it is
divisible by 2, so that only every 2nd Mark returns True

Don't know if I'll ever need it, fun to have it.

-y


On Tue, Jul 28, 2020 at 7:09 PM Brad Gilbert  wrote:

> 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 

Re: 2020.07 just hit

2020-08-01 Thread yary
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 
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: delimiters with more than one character? ...

2020-07-17 Thread yary
FYI the original thread is viewable at
https://www.mail-archive.com/debian-user@lists.debian.org/msg758713.html
and the post has several reasonable answers there. Among the first is a
classic Perl one-liner and suggestions along the lines of "what you're
doing looks brittle, how about doing the whole thing in Perl" and "tell use
what you really want to accomplish and we'll find a better solution!"

Raku content for fun and practice

$ *echo ' 34 + 45 \| abc \| 1 2 3 \| c\|123abc '*
 34 + 45 \| abc \| 1 2 3 \| c\|123abc
$
*# Good, shell echo preserves \| combo*$ echo ' 34 + 45 \| abc \| 1 2 3 \|
c\|123abc ' | raku -pe 's:g/\\ \| / \n /'

 34 + 45

  abc

  1 2 3

  c

 123abc


-y

-y


On Thu, Jul 16, 2020 at 2:51 PM William Michels via perl6-users <
perl6-users@perl.org> wrote:

> -- Forwarded message -
> Date: Thu, Jul 16, 2020 at 11:42 AM
> Subject: Re: delimiters with more than one character?
> To: 
>
> I've slowly been learning the Raku programming language (AKA Perl6), and
> while I'm far from being an expert, this is the first solution I came up
> with (raku one-or-two-liners, at the bash command prompt):
>
> user@mbook:~$ raku -e ' my Str $s=" 34 + 45 \| abc \| 1 2 3 \| c\|123abc
> "; $s.put';
>  34 + 45 | abc | 1 2 3 | c|123abc
> user@mbook:~$ raku -e ' my Str $s=" 34 + 45 \| abc \| 1 2 3 \| c\|123abc
> "; $s.split("|").raku.put';
> (" 34 + 45 ", " abc ", " 1 2 3 ", " c", "123abc ").Seq
> user@mbook:~$ raku -e ' my Str $s=" 34 + 45 \| abc \| 1 2 3 \| c\|123abc
> "; .put for $s.split("|");'
>  34 + 45
>  abc
>  1 2 3
>  c
> 123abc
> user@mbook:~$ raku -e ' my Str $s=" 34 + 45 \| abc \| 1 2 3 \| c\|123abc
> "; .raku.put for $s.split("|");'
> " 34 + 45 "
> " abc "
> " 1 2 3 "
> " c"
> "123abc "
> user@mbook:~$
>
> Looking at the Str typed-variable $s I see that backslash escapes are
> removed automatically (the second command only has to split on the pipe
> character). So maybe this isn't a general solution, but it works for the
> example given.
>
> https://raku.org/
>
> HTH, Bill.
>
>
>
>
>
> On Thu, Jul 16, 2020 at 5:35 AM Tom Browder  wrote:
>
>> An opportunity for Raku golfers to show off Raku on the Debian users list.
>>
>> Best regards,
>>
>> -Tom
>>
>> -- Forwarded message -
>> From: Albretch Mueller 
>> Date: Tue, Jul 14, 2020 at 07:52
>> Subject: delimiters with more than one character? ...
>> To: Debian Users ML 
>>
>>
>>  I have a string delimited by two characters: "\|"
>>
>>  _S=" 34 + 45 \| abc \| 1 2 3 \| c\|123abc "
>>
>>  which then I need to turn into a array looking like:
>>
>>   _S_AR=(
>> " 34 + 45 "
>> " abc "
>> " 1 2 3 "
>> " c"
>> "123abc "
>> )
>>
>>   I can't make awk or tr work in the way I need and all examples I
>> have found use only one character.
>>
>>   Is it possible to do such things in bash?
>>
>>   lbrtchx
>>
>>


Re: proto and multi

2020-06-29 Thread yary
It looks like you have spaces in the token { * } can you try it without,
using this {*} instead?

On Mon, Jun 29, 2020, 1:29 PM Richard Hainsworth 
wrote:

> I have several multi methods.
>
> All of them have the same first statement, then differ depending on the
> signature.
>
> proto seems to be a way to factor out the common statement, and there is a
> phrase in the Documentation that * can affect the dispatch, viz:
>
> "You can give the proto a function body, and place the {*} where you want
> the dispatch to be done. This can be useful when you have a "hole" in your
> routine that gives it different behavior depending on the arguments given:"
>
> The docs give and example proto, but unfortunately, not how this works
> with other multi's.
>
> So  I tried this:
>
> class NewClass {
> has $.debug is rw = False;
> has $.value is rw = 'Initial value';
>
> proto method handle( |c ) {
> note "value is $.value" if $.debug;
> { * }}
> multi method handle(Str $s) {
> $.value = $s;
> say 'in string'}
> multi method handle(Positional @s) {
> $.value = @s[0];
> say 'in positional'}
> }
> my NewClass $x .= new;
> $x.handle('hello world');$x.handle();$x.debug = 
> True;$x.handle('hello world');$x.handle();
>
> #raku test.raku
> #value is Initial value
> #value is Initial value
>
> I am wondering how to use proto and {*}
>
>


Re: interpolating the return from embedded code in a regexp

2020-06-15 Thread yary
Brad: "Note that {} is there to update $/ so that $0 works the way you
would expect"

I ran into that before & was trying to remember that detail... found it in
https://docs.raku.org/language/regexes#Capture_numbers

But the example is a bit on the obtuse side:

These capture variables are only available outside the regex.

# !!WRONG!! The $0 refers to a capture *inside* the second capture
say "11" ~~ /(\d) ($0)/; # OUTPUT: «Nil␤»

In order to make them available inside the regex, you need to insert a code
block behind the match; this code block may be empty if there's nothing
meaningful to do:

# CORRECT: $0 is saved into a variable outside the second capture
# before it is used inside
say "11" ~~ /(\d) {} :my $c = $0; ($c)/; # OUTPUT: «「11」␤ 0 => 「1」␤ 1 => 「1」␤»
say "Matched $c"; # OUTPUT: «␤Matched 1␤»


As of Raku 2019.11 at least, the $0 construct works without the {} code
block, in simple cases.

> "11" ~~ /(\d) $0/

「11」

 0 => 「1」

> '876554' ~~ /(\d) $0/

「55」

 0 => 「5」


# Inside a new capture, $0 refers to inner capture

> "11" ~~ /(\d) ($0)/

Nil

> "11" ~~ /(\d) {} ($0)/

Nil

> "11" ~~ /(\d) {} :my $c=$0; ($c)/

「11」

 0 => 「1」

 1 => 「1」
# Let's use that inner capture

> "1122" ~~ /(\d) {} :my $c=$0; ($c (\d) $0)/

「1122」

 0 => 「1」

 1 => 「122」

  0 => 「2」

The Match docs can be clearer on when to use {} and when it isn't needed,
opened an issue https://github.com/Raku/doc/issues/3478

-y


On Mon, Jun 15, 2020 at 3:09 PM Brad Gilbert  wrote:

> 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: interpolating the return from embedded code in a regexp

2020-06-14 Thread yary
True, and I am well and truly baffled by my example where the 1st bad line
incorrectly is labelled good, the 2nd bad line is correctly labelled bad,
and the 3rd good like is correctly labelled good.

-y


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

> > Just to be be clear, my idea is the second line is wrong, and it
> should flag that one as a problem
>
> Oh, but if you go literally with the code I posted, *both* the first
> and second lines have incorrect descriptions, and only the third line
> ("corn dogs") matches.
>
> (That was a mistake when I wrote it up, but whatever.)
>
>
>
> On 6/14/20, Joseph Brenner  wrote:
> > Well, with the first one it rejects all of my lines, and with the
> > second one it passes all of them.
> >
> > Just to be be clear, my idea is the second line is wrong, and it
> > should flag that one as a problem
> >
> >
> >
> > On 6/14/20, yary  wrote:
> >> https://docs.raku.org/language/regexes#Regex_interpolation gave me some
> >> ideas
> >>
> >> Try matching against  / (^P\d+) \s+ %products{$0} /
> >>
> >> This one also works, in a roundabout way
> >>  / (^P\d+) \s+ {"%products{$0}"} /
> >> -y
> >>
> >>
> >> On Sun, Jun 14, 2020 at 4: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: interpolating the return from embedded code in a regexp

2020-06-14 Thread yary
I should have read the output!

This one gives the right answers but with lots of warnings
/ (^P\d+) \s+ $("%products{$0}") /

checking line: P123  Viridian Green Label Saying Magenta

Use of Nil in string context

  in regex  at regex-loop.p6 line 18

Use of Nil in string context

  in regex  at regex-loop.p6 line 18

Use of uninitialized value %products{''} of type Any in string context.

Methods .^name, .perl, .gist, or .say can be used to stringify it to
something meaningful.

  in regex  at regex-loop.p6 line 18

Matched, line looks good

checking line: P666  Yoda puppets

NO: bad line.
...
Why is it reading with an empty-string $0 in %products{''}

-y


On Sun, Jun 14, 2020 at 5:47 PM Joseph Brenner  wrote:

> Well, with the first one it rejects all of my lines, and with the
> second one it passes all of them.
>
> Just to be be clear, my idea is the second line is wrong, and it
> should flag that one as a problem
>
>
>
> On 6/14/20, yary  wrote:
> > https://docs.raku.org/language/regexes#Regex_interpolation gave me some
> > ideas
> >
> > Try matching against  / (^P\d+) \s+ %products{$0} /
> >
> > This one also works, in a roundabout way
> >  / (^P\d+) \s+ {"%products{$0}"} /
> > -y
> >
> >
> > On Sun, Jun 14, 2020 at 4: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: interpolating the return from embedded code in a regexp

2020-06-14 Thread yary
https://docs.raku.org/language/regexes#Regex_interpolation gave me some
ideas

Try matching against  / (^P\d+) \s+ %products{$0} /

This one also works, in a roundabout way
 / (^P\d+) \s+ {"%products{$0}"} /
-y


On Sun, Jun 14, 2020 at 4: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: I need a second pair of eyes

2020-05-26 Thread yary
>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-users@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: Raku -npe command line usage

2020-05-08 Thread yary
The comma is more boring than that, it's simply separating the arguments to
the sub "grep" - adding parend

.say for sort grep( *.starts-with(q[WARN]), lines )

grep as a sub takes a routine as the 1st arg, and the list to grep
through after.

-y


On Fri, May 8, 2020 at 7:28 PM William Michels 
wrote:

> >Boring hard-to-read solution not using any of those
> > raku -e'.say for sort grep *.starts-with(q[WARN]),lines' sample.log
>
> Interesting! I don't think I've seen a comma used like that in a
> one-liner. Also a very fast solution (thanks Brad!).
>
> Presumably the ",lines" tells raku/perl6 to run the preceding code on
> input lines?
>
> TIA, Bill.
>
> On Fri, May 8, 2020 at 11:03 AM yary  wrote:
> >
> > > perl6 -e 'lines() ==> grep /^WARN/ ==> sort() ==> join("\n") ==>
> say();'
> >
> > that's neat too.
> >
> > This is showed me that I didn't have a clear grasp of the feed operator
> ==> vs the hyper-operator >>
> >
> > Now I have learned/internalized that the feed operators pass along the
> entire sequence (list?), whereas the hyper-operator passes items one at a
> time. Hence "==> say" putting the results on one line, because "say" is
> getting the entire list. And  ">>.sort" not sorting, because sort would be
> called once per item with only that single item to sort.
> >
> > Boring hard-to-read solution not using any of those
> >
> > raku -e'.say for sort grep *.starts-with(q[WARN]),lines' sample.log
> >
> > -y
> >
> > On Fri, May 8, 2020 at 1:20 PM William Michels 
> wrote:
> >>
> >> Maybe?
> >>
> >> perl6 -e 'lines() ==> grep /^WARN/ ==> sort() ==> join("\n") ==> say();'
> >>
> >> HTH, Bill.
> >>
> >>
> >> On Fri, May 8, 2020 at 9:10 AM Fernando Santagata
> >>  wrote:
> >> >
> >> > raku -e'.say for lines() ==> grep(/^WARN/) ==> sort' sample.log
> >> >
> >> > is not very satisfying because for the "for" which breaks the flow.
> >> > OTOH this
> >> >
> >> > raku -e'lines().grep(/^WARN/).sort».say' sample.log
> >> >
> >> > doesn't use the feed operator and this
> >> >
> >> > raku -e'lines() ==> grep(/^WARN/) ==> sort() ==> say()' sample.log
> >> >
> >> > outputs a list on one line, not each line on its own. This one works,
> but it feels awkward:
> >> >
> >> > raku -e'lines() ==> grep(/^WARN/) ==> sort() ==> reduce({$^a ~ "\n" ~
> $^b}) ==> say()' sample.log
> >> >
> >> > On Fri, May 8, 2020 at 5:49 PM yary  wrote:
> >> >>
> >> >> All good ideas so far, in the "more than one way to do it" spirit,
> can use "state" instead of "my", since state only initializes 1st time it's
> hit.
> >> >>
> >> >> raku -ne 'state @i;@i.push($_) if .starts-with(q[WARN]); END
> .say for @i.sort' sample.log
> >> >>
> >> >> Or adapting Brad's answer with the feed operator for fun
> >> >>
> >> >> raku -e 'for lines() ==> grep /^WARN/ ==> sort() {.say}'
> sample.log
> >> >>
> >> >> Now, I didn't want to use 'map' in there, because of a habit of only
> using 'map' when I want the return values. When looping for side-effects
> only, like saying each value in a list, I want to use 'for'. UnFORtunately
> though I cannot find anything as clean looking as
> >> >>
> >> >> raku -e 'lines() ==> grep /^WARN/ ==> sort() ==> map *.say'
> sample.log
> >> >>
> >> >> reading entirely L-to-R which does NOT use map... ideas?
> >> >>
> >> >> -y
> >> >>
> >> >>
> >> >> On Fri, May 8, 2020 at 10:10 AM William Michels via perl6-users <
> perl6-users@perl.org> wrote:
> >> >> >
> >> >> > On Fri, May 8, 2020 at 5: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.
>

Re: Raku -npe command line usage

2020-05-08 Thread yary
> perl6 -e 'lines() ==> grep /^WARN/ ==> sort() ==> join("\n") ==> say();'

that's neat too.

This is showed me that I didn't have a clear grasp of the feed operator ==>
vs the hyper-operator >>

Now I have learned/internalized that the feed operators pass along the
entire sequence (list?), whereas the hyper-operator passes items one at a
time. Hence "==> say" putting the results on one line, because "say" is
getting the entire list. And  ">>.sort" not sorting, because sort would be
called once per item with only that single item to sort.

Boring hard-to-read solution not using any of those

raku -e'.say for sort grep *.starts-with(q[WARN]),lines' sample.log

-y

On Fri, May 8, 2020 at 1:20 PM William Michels 
wrote:

> Maybe?
>
> perl6 -e 'lines() ==> grep /^WARN/ ==> sort() ==> join("\n") ==> say();'
>
> HTH, Bill.
>
>
> On Fri, May 8, 2020 at 9:10 AM Fernando Santagata
>  wrote:
> >
> > raku -e'.say for lines() ==> grep(/^WARN/) ==> sort' sample.log
> >
> > is not very satisfying because for the "for" which breaks the flow.
> > OTOH this
> >
> > raku -e'lines().grep(/^WARN/).sort».say' sample.log
> >
> > doesn't use the feed operator and this
> >
> > raku -e'lines() ==> grep(/^WARN/) ==> sort() ==> say()' sample.log
> >
> > outputs a list on one line, not each line on its own. This one works,
> but it feels awkward:
> >
> > raku -e'lines() ==> grep(/^WARN/) ==> sort() ==> reduce({$^a ~ "\n" ~
> $^b}) ==> say()' sample.log
> >
> > On Fri, May 8, 2020 at 5:49 PM yary  wrote:
> >>
> >> All good ideas so far, in the "more than one way to do it" spirit, can
> use "state" instead of "my", since state only initializes 1st time it's hit.
> >>
> >> raku -ne 'state @i;@i.push($_) if .starts-with(q[WARN]); END .say
> for @i.sort' sample.log
> >>
> >> Or adapting Brad's answer with the feed operator for fun
> >>
> >> raku -e 'for lines() ==> grep /^WARN/ ==> sort() {.say}' sample.log
> >>
> >> Now, I didn't want to use 'map' in there, because of a habit of only
> using 'map' when I want the return values. When looping for side-effects
> only, like saying each value in a list, I want to use 'for'. UnFORtunately
> though I cannot find anything as clean looking as
> >>
> >> raku -e 'lines() ==> grep /^WARN/ ==> sort() ==> map *.say'
> sample.log
> >>
> >> reading entirely L-to-R which does NOT use map... ideas?
> >>
> >> -y
> >>
> >>
> >> On Fri, May 8, 2020 at 10:10 AM William Michels via perl6-users <
> perl6-users@perl.org> wrote:
> >> >
> >> > On Fri, May 8, 2020 at 5: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
> >> >
> >> > Hi Wolfgang,
> >> >
> >> > This is a first attempt at doing what you want: I'm sure it can be
> >> > shortened. Since one of your requirements is doing a sort on filtered
> >> > values stored in an array, I abandoned use of the "-ne" one-liner
> >> > flag, using "-e"  and "for lines()" instead. I also used grep instead
> >> > of smart-matching:
> >> >
> >> > perl6 -e 'my @i; for lines() {if .grep(/^WARN/) -> ($s)
> >> > {@i.push($s)};}; .say for @i.sort;'
> >> >
> >> > Note: the "-> ($s)" section where I store grepped matches comes from a
> >> > Jonathan Worthington answer found here (thanks Jonathan!):
> >> >
> >> >
> stackoverflow.com/questions/58982745/raku-one-line-expression-to-capture-group-from-string
> >> >
> >> > I certainly would be interested to learn if there's a phaser solution
> >> > to this problem (and I also have a sneaking suspicion that Supply
> >> > might be useful  here... ).
> >> >
> >> > HTH, Bill.
> >
> >
> >
> > --
> > Fernando Santagata
>


Re: Raku -npe command line usage

2020-05-08 Thread yary
Ooops forgot the sort... let's golf with the hyper-operator again...

raku -ne'push my @i: $_ if .starts-with: q[WARN]; END @i.sort>>.say'
sample.log

-y


On Fri, May 8, 2020 at 1:10 PM yary  wrote:

> ooh neat! I didn't know. Indeed this works. Thanks Sean!
>
> raku -ne'push my @i: $_ if .starts-with: q[WARN]; END .say for @i'
> sample.log
>
> -y
>
>
> On Fri, May 8, 2020 at 1:04 PM Sean McAfee  wrote:
>
>> On Fri, May 8, 2020 at 6:53 AM Brad Gilbert  wrote:
>>
>>> So together that would be:
>>>
>>> raku -ne 'BEGIN my @i; @i.push($_) if /^WARN/; END .say for @i.sort'
>>>
>>
>> Or alternately the main body of the loop can be written:
>>
>> (my @i).push($_) if /^WARN/;
>>
>> Or even:
>>
>> push my @i: $_ if /^WARN/;
>>
>> It's so nice how Raku essentially compiles the body of these file loops
>> into a little subroutine so that the "my" declaration only occurs once,
>> unlike how Perl 5 just textually wraps the loop with "while (<>) {" and "}"
>> which makes the declaration occur on every iteration.
>>
>> I originally figured this out when I idly worked up a classic
>> word-frequency-count one-liner:
>>
>> raku -ne '++(my %freq){$_} for m:g/\w+/; END .say for
>> %freq.antipairs.sort.reverse' file ...
>>
>>


Re: Raku -npe command line usage

2020-05-08 Thread yary
ooh neat! I didn't know. Indeed this works. Thanks Sean!

raku -ne'push my @i: $_ if .starts-with: q[WARN]; END .say for @i'
sample.log

-y


On Fri, May 8, 2020 at 1:04 PM Sean McAfee  wrote:

> On Fri, May 8, 2020 at 6:53 AM Brad Gilbert  wrote:
>
>> So together that would be:
>>
>> raku -ne 'BEGIN my @i; @i.push($_) if /^WARN/; END .say for @i.sort'
>>
>
> Or alternately the main body of the loop can be written:
>
> (my @i).push($_) if /^WARN/;
>
> Or even:
>
> push my @i: $_ if /^WARN/;
>
> It's so nice how Raku essentially compiles the body of these file loops
> into a little subroutine so that the "my" declaration only occurs once,
> unlike how Perl 5 just textually wraps the loop with "while (<>) {" and "}"
> which makes the declaration occur on every iteration.
>
> I originally figured this out when I idly worked up a classic
> word-frequency-count one-liner:
>
> raku -ne '++(my %freq){$_} for m:g/\w+/; END .say for
> %freq.antipairs.sort.reverse' file ...
>
>


Re: Raku -npe command line usage

2020-05-08 Thread yary
I like this formulation Fernando posted (removed a set of parens not needed
with method calls)

raku -e'lines.grep(/^WARN/).sort».say' sample.log

It is clean, all left-to-right, and doesn't use "map" for its side-effects
only.
Putting the feed operator back in where it would work–have to keep the
hyper-operator–

raku -e'(lines() ==> grep(/^WARN/) ==> sort)».say' sample.log

-y


On Fri, May 8, 2020 at 12:10 PM Fernando Santagata <
nando.santag...@gmail.com> wrote:

> raku -e'.say for lines() ==> grep(/^WARN/) ==> sort' sample.log
>
> is not very satisfying because for the "for" which breaks the flow.
> OTOH this
>
> raku -e'lines().grep(/^WARN/).sort».say' sample.log
>
> doesn't use the feed operator and this
>
> raku -e'lines() ==> grep(/^WARN/) ==> sort() ==> say()' sample.log
>
> outputs a list on one line, not each line on its own. This one works, but
> it feels awkward:
>
> raku -e'lines() ==> grep(/^WARN/) ==> sort() ==> reduce({$^a ~ "\n" ~
> $^b}) ==> say()' sample.log
>
> On Fri, May 8, 2020 at 5:49 PM yary  wrote:
>
>> All good ideas so far, in the "more than one way to do it" spirit, can
>> use "state" instead of "my", since state only initializes 1st time it's hit.
>>
>> raku -ne 'state @i;@i.push($_) if .starts-with(q[WARN]); END .say
>> for @i.sort' sample.log
>>
>> Or adapting Brad's answer with the feed operator for fun
>>
>> raku -e 'for lines() ==> grep /^WARN/ ==> sort() {.say}' sample.log
>>
>> Now, I didn't want to use 'map' in there, because of a habit of only
>> using 'map' when I want the return values. When looping for side-effects
>> only, like saying each value in a list, I want to use 'for'. UnFORtunately
>> though I cannot find anything as clean looking as
>>
>> raku -e 'lines() ==> grep /^WARN/ ==> sort() ==> map *.say' sample.log
>>
>> reading entirely L-to-R which does NOT use map... ideas?
>>
>> -y
>>
>>
>> On Fri, May 8, 2020 at 10:10 AM William Michels via perl6-users <
>> perl6-users@perl.org> wrote:
>> >
>> > On Fri, May 8, 2020 at 5: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
>> >
>> > Hi Wolfgang,
>> >
>> > This is a first attempt at doing what you want: I'm sure it can be
>> > shortened. Since one of your requirements is doing a sort on filtered
>> > values stored in an array, I abandoned use of the "-ne" one-liner
>> > flag, using "-e"  and "for lines()" instead. I also used grep instead
>> > of smart-matching:
>> >
>> > perl6 -e 'my @i; for lines() {if .grep(/^WARN/) -> ($s)
>> > {@i.push($s)};}; .say for @i.sort;'
>> >
>> > Note: the "-> ($s)" section where I store grepped matches comes from a
>> > Jonathan Worthington answer found here (thanks Jonathan!):
>> >
>> >
>> stackoverflow.com/questions/58982745/raku-one-line-expression-to-capture-group-from-string
>> >
>> > I certainly would be interested to learn if there's a phaser solution
>> > to this problem (and I also have a sneaking suspicion that Supply
>> > might be useful  here... ).
>> >
>> > HTH, Bill.
>>
>
>
> --
> Fernando Santagata
>


Re: Raku -npe command line usage

2020-05-08 Thread yary
All good ideas so far, in the "more than one way to do it" spirit, can use
"state" instead of "my", since state only initializes 1st time it's hit.

raku -ne 'state @i;@i.push($_) if .starts-with(q[WARN]); END .say for
@i.sort' sample.log

Or adapting Brad's answer with the feed operator for fun

raku -e 'for lines() ==> grep /^WARN/ ==> sort() {.say}' sample.log

Now, I didn't want to use 'map' in there, because of a habit of only using
'map' when I want the return values. When looping for side-effects only,
like saying each value in a list, I want to use 'for'. UnFORtunately though
I cannot find anything as clean looking as

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

reading entirely L-to-R which does NOT use map... ideas?

-y


On Fri, May 8, 2020 at 10:10 AM William Michels via perl6-users <
perl6-users@perl.org> wrote:
>
> On Fri, May 8, 2020 at 5: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
>
> Hi Wolfgang,
>
> This is a first attempt at doing what you want: I'm sure it can be
> shortened. Since one of your requirements is doing a sort on filtered
> values stored in an array, I abandoned use of the "-ne" one-liner
> flag, using "-e"  and "for lines()" instead. I also used grep instead
> of smart-matching:
>
> perl6 -e 'my @i; for lines() {if .grep(/^WARN/) -> ($s)
> {@i.push($s)};}; .say for @i.sort;'
>
> Note: the "-> ($s)" section where I store grepped matches comes from a
> Jonathan Worthington answer found here (thanks Jonathan!):
>
>
stackoverflow.com/questions/58982745/raku-one-line-expression-to-capture-group-from-string
>
> I certainly would be interested to learn if there's a phaser solution
> to this problem (and I also have a sneaking suspicion that Supply
> might be useful  here... ).
>
> HTH, Bill.


Re: I need help with sub MAIN

2020-05-05 Thread yary
Oops my example was missing the important $*USAGE message. And it makes
sense to show the wrong named args before the wrong list args.

example.raku:
  multi sub MAIN(:$these ="These", :$are="Are") { say "$these $are"; };
  multi sub MAIN(*@wrong-list,:$these ="These", :$are="Are",*%wrong-named)
is hidden-from-USAGE
{say "$*USAGE\nGot bad args " ~ %wrong-named ~ " "~ @wrong-list}'
raku example.raku -these=HIHIHI -foo=BABABA


On Tue, May 5, 2020 at 3:20 PM yary  wrote:
>
> Here's something to play with (without explanation from me, busy enough
sorry!)
>
>
> example.raku:
>   multi sub MAIN(:$these ="These", :$are="Are") { say "$these $are"; };
>   multi sub MAIN(*@wrong-list,:$these ="These",
:$are="Are",*%wrong-named) is hidden-from-USAGE
> {say "Got bad args " ~ @wrong-list ~ " "~ %wrong-named}'
>
>
> raku example.raku -these=HIHIHI -foo=BABABA
>
> -y
>
>
> On Tue, May 5, 2020 at 1:09 PM ToddAndMargo via perl6-users <
perl6-users@perl.org> wrote:
>>
>> >> On Tue, 5 May 2020, 06:46 ToddAndMargo via perl6-users,
>> >> mailto:perl6-users@perl.org>> wrote:
>> >>
>> >> Hi All,
>> >>
>> >> Just to prove I read the stinker:
>> >> https://docs.raku.org/routine/MAIN
>> >>
>> >> I am trying to get the following to do
>> >>
>> >> #!/usr/bin/env perl6
>> >> sub MAIN(:$these ="These", :$are="Are") { say "$these $are"; }
>> >>
>> >> This is working:
>> >>
>> >> $ MainTest.pl6 --are=our --these=those
>> >> those our
>> >>
>> >>
>> >> These two are not:
>> >>
>> >> 1) I am trying to get MAIN to give me an error I can
>> >>  call my help sub if a stray entry is placed in
>> >>  the run line
>> >>
>> >> $ MainTest.pl6 --are=our --these=those --saywhat=abc
>> >> Usage:
>> >> MainTest.pl6 [--these=] [--are=]
>> >>
>> >> Here it find `--saywhat=abc` and MAIN writes out the above
>> >> usage statement.
>> >>
>> >>  A) I want to write it out myself.  I would like the
>> >> string too, but don't have to have it.
>> >>
>> >>  B) I would like the stray entry.
>> >>
>> >>
>> >> 2) Here I want to pick up the remainder (abc) at the end,
>> >>  but can't figure out the syntax in the sub declaration.
>> >>
>> >>  Something like:
>> >>dnf --excluderepo=acb* install raku
>> >>
>> >> $ MainTest.pl6 --are=our --these=those abc
>> >> Usage:
>> >> MainTest.pl6 [--these=] [--are=]
>> >>
>> >> Instead of MAIN writing out usage.
>> >>
>> >> Many thanks,
>> >> -T
>> >>
>>
>> On 2020-05-05 00:38, Simon Proctor wrote:
>> > I would suggest starting by reading this page in the docs :
>> > https://docs.raku.org/language/create-cli
>> >
>> > Covers how $*USAGE is created and the various options you have for
>> > providing help data.
>> >
>>
>> Hi Simon,
>>
>> I must be missing something.  That is just a rehash of the manual page I
>> first posted with a few extra paragraphs at he top.
>>
>> :'(
>>
>> Maybe I should just write my own based on @*ARGS  ?
>>
>> -T


Re: I need help with sub MAIN

2020-05-05 Thread yary
Here's something to play with (without explanation from me, busy enough
sorry!)


example.raku:
  multi sub MAIN(:$these ="These", :$are="Are") { say "$these $are"; };
  multi sub MAIN(*@wrong-list,:$these ="These", :$are="Are",*%wrong-named)
is hidden-from-USAGE
{say "Got bad args " ~ @wrong-list ~ " "~ %wrong-named}'


raku example.raku -these=HIHIHI -foo=BABABA

-y


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

> >> On Tue, 5 May 2020, 06:46 ToddAndMargo via perl6-users,
> >> mailto:perl6-users@perl.org>> wrote:
> >>
> >> Hi All,
> >>
> >> Just to prove I read the stinker:
> >> https://docs.raku.org/routine/MAIN
> >>
> >> I am trying to get the following to do
> >>
> >> #!/usr/bin/env perl6
> >> sub MAIN(:$these ="These", :$are="Are") { say "$these $are"; }
> >>
> >> This is working:
> >>
> >> $ MainTest.pl6 --are=our --these=those
> >> those our
> >>
> >>
> >> These two are not:
> >>
> >> 1) I am trying to get MAIN to give me an error I can
> >>  call my help sub if a stray entry is placed in
> >>  the run line
> >>
> >> $ MainTest.pl6 --are=our --these=those --saywhat=abc
> >> Usage:
> >> MainTest.pl6 [--these=] [--are=]
> >>
> >> Here it find `--saywhat=abc` and MAIN writes out the above
> >> usage statement.
> >>
> >>  A) I want to write it out myself.  I would like the
> >> string too, but don't have to have it.
> >>
> >>  B) I would like the stray entry.
> >>
> >>
> >> 2) Here I want to pick up the remainder (abc) at the end,
> >>  but can't figure out the syntax in the sub declaration.
> >>
> >>  Something like:
> >>dnf --excluderepo=acb* install raku
> >>
> >> $ MainTest.pl6 --are=our --these=those abc
> >> Usage:
> >> MainTest.pl6 [--these=] [--are=]
> >>
> >> Instead of MAIN writing out usage.
> >>
> >> Many thanks,
> >> -T
> >>
>
> On 2020-05-05 00:38, Simon Proctor wrote:
> > I would suggest starting by reading this page in the docs :
> > https://docs.raku.org/language/create-cli
> >
> > Covers how $*USAGE is created and the various options you have for
> > providing help data.
> >
>
> Hi Simon,
>
> I must be missing something.  That is just a rehash of the manual page I
> first posted with a few extra paragraphs at he top.
>
> :'(
>
> Maybe I should just write my own based on @*ARGS  ?
>
> -T
>


Re: subst :g and captures in the replacement

2020-04-19 Thread yary
How would one do s/(.+),(.+)/$1,$0/ using .subst ?
-y


On Sun, Apr 19, 2020 at 6:21 PM Tobias Boege  wrote:

> On Sun, 19 Apr 2020, yary wrote:
> > Question from today's Raku meetup. This works in a way I expect
> >
> > > 'fosdffgg'.subst(/f+/,"( "~ * ~" )", :g);
> > ( f )osd( ff )gg
> >
> > This one, $0 gets the single f each time
> >
> > > 'fosdffgg'.subst(/(f+)/,"( $0 )", :g);
> > ( f )osd( f )gg
> >
> > Bug or misunderstanding on my part?
> >
>
> Not a bug. You are calling the subst method on a string. Naturally, in
> order
> to perform the call, all the arguments you pass have to be evaluated first.
> This includes interpolating $0 into the string "( $0 )". You take whatever
> $0 contains, put it into a string and pass that into subst. In your case $0
> seemed to confusingly stringify to "f". Consider this instead:
>
>   "oops" ~~ /^(..)/ andthen say 'fosdffgg'.subst(/(f+)/,"( $0 )", :g)
>   # OUTPUT: «( oo )osd( oo )gg»
>
> where I deliberately set $0 beforehand.
>
> Your first variant works because you pass a Callable into subst and when
> you
> do that subst will repeatedly evaluate the Callable. Not so when you pass a
> string value.
>
> Regards,
> Tobias
>
> --
> "There's an old saying: Don't change anything... ever!" -- Mr. Monk
>


subst :g and captures in the replacement

2020-04-19 Thread yary
Question from today's Raku meetup. This works in a way I expect

> 'fosdffgg'.subst(/f+/,"( "~ * ~" )", :g);
( f )osd( ff )gg

This one, $0 gets the single f each time

> 'fosdffgg'.subst(/(f+)/,"( $0 )", :g);
( f )osd( f )gg

Bug or misunderstanding on my part?

-y


Re: Can a sub be released?

2020-04-07 Thread yary
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-users@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
>>
>
>
> --
> __
>
> :(){ :|:& };:
>


  1   2   3   4   >