Re: A nice touch

2021-11-04 Thread Laurent Rosenfeld via perl6-users
It is the exponentiation operator:

$ perl -E 'say 3 ** 2;'
9

Cheers,
Laurent.

Le mer. 3 nov. 2021 à 20:05, Wes Peng  a écrit :

> What's the "**" operator in perl? I most of the time use R for math, not
> familiar with this operation.
>
> Thanks
>
> On Sun, Oct 31, 2021 at 3:38 AM Sean McAfee  wrote:
>
>> Recently I was golfing the "hyperfactorial," defined for a number 푛 as
>> 푛**푛 × (푛-1)**(푛-1) × (푛-2)**(푛-2) × ... × 1.  I created a quite
>> concise Raku function:
>>
>> { [*] [\*] $_...1 }
>>
>> The only problem was that this function returns zero for a zero input,
>> whereas the hyperfactorial of 0 is supposed to be 1.  Of course I could
>> have just handled zero as a special case, but I hoped to find something
>> comparably short.  After a bit of thought I tried reversing both the range
>> and the operator:
>>
>> { [*] [\R*] 1..$_ }
>>
>> It worked!  But I couldn't quite see how.  * is commutative, so isn't it
>> exactly the same as R*?
>>
>> It turns out, in Raku it isn't quite the same.  On the operators page, I
>> found that the R metaoperator produces an operator that reverses the order
>> of the arguments, but *also* has the opposite associativity.  So, for
>> example, [\R*] 1..4 reduces from the right, producing the list (4, 12, 24,
>> 24).  Somehow I had formed the idea that Raku operators are left-, right-,
>> or list-associative, but I was wrong.
>>
>> Anyway, pretty cool!
>>
>>


Re: How do I address individual elements inside an object

2020-12-19 Thread Laurent Rosenfeld via perl6-users
Yeah, right. $FruitStand.apples is not a direct access to the attribute,
but a method invocation (a call to a method implicitly created by Raku), so
it doesn't get interpolated within the string. So it should be outside the
string or used with a code interpolation block.

For example:

say "Fruitstand in {$FruitStand.location} has {$FruitStand.apples} apples.";

or

say "Fruitstand in ", $FruitStand.location,  "has ", $FruitStand.apples, "
apples.";

or the construct with the ~ concatenation operator that you used.

Cheers,
Laurent..


Garanti
sans virus. www.avast.com

<#DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2>

Le ven. 18 déc. 2020 à 23:55, ToddAndMargo via perl6-users <
perl6-users@perl.org> a écrit :

> On 12/18/20 9:42 AM, William Michels via perl6-users wrote:
> > Hi Laurent, I get:
> >
> > Fruitstand in Fruit<140431957910656>.location has
> >   Fruit<140431957910656>.apples apples.
> >
> > [Rakudo v2020.10]
> >
> > Best, Bill.
> >
>
> Hi Bill,
>
>  From my notes in progress:
>
> -T
>
>
> *** addressing values inside and object ***
>
> Reading:
>say $FruitStand.apples
>400
>
>$FruitStand.apples.say
>400
>
>print $FruitStand.location ~ " has " ~ $FruitStand.apples ~"
> apples in stock\n";
>Cucamonga has 400 apples in stock
>
>Note: an "oops!".  Separate the variables from the string, or else:
>say "$FruitStand.location has $FruitStand.apples apples in
> stock";
>Fruit<79300336>.location has Fruit<79300336>.apples apples in
> stock
>
>Writing (must be declared as "rw"):
>


Re: How do I address individual elements inside an object

2020-12-18 Thread Laurent Rosenfeld via perl6-users
Hi Todd,

1. Yes, a class is a blueprint for manufacturing objects, you can construct
as many object as you want.

2. As an example, you can try:

say " Fruitstand in $FruitStand.location has  $FruitStand.apples apples.";

2. As you declared your class the object attributes will not be mutable.
But if you had declared the apple attribute like so in the class:

has UInt $.apples is rw;

then you could write:

$FruitStand.apples += 42;

Cheers,
Laurent.

Le ven. 18 déc. 2020 à 08:12, ToddAndMargo via perl6-users <
perl6-users@perl.org> a écrit :

> Hi All,
>
> class Fruit {
> has Str $.location;
> has UInt $.apples;
> has UInt $.oranges;
> has UInt $.bananas;
> }
>
> my $FruitStand = Fruit.new( location => "Cucamonga",
> apples   => 400,
> oranges  => 200,
> bananas  => 50  );
>
> 1)  am I correct that I can make as many objects as I
>  want out of a particular class?
>
> 2 ) what is the syntax to read an element inside an
>  object?
>
> 3)  what is the syntax to write to an element inside an
>  object?
>
> I am confused, again.
>
> -T
>


Re: root cubic

2020-07-09 Thread Laurent Rosenfeld via perl6-users
Do you expect something else? The result appears to be correct.

Please note that, when dealing with square or cubic roots, Raku will not
use rationals, but ordinary floats.

Le jeu. 9 juil. 2020 à 17:27, Aureliano Guedes 
a écrit :

> Hi all,
>
> A quick question.
>
> This is expected?
>
> raku -e 'say 9 ** (1/3)'
> 2.080083823051904
>
>
> Why do I'm asking this?
> I know about the computational floating problem and I also know that the
> Raku deal with rational whenever it is possible and store numbers as
> expressions (actually I don't know if there are more details). That's why
> 0.2 + 0.1 == 0.3 in Raku returns True whilst in other languages like
> Python, Perl5, and Ruby return False.
>
> Then, I was just playing around and I'd like to check if it is expected.
>
> Thanks
>
>
> --
> Aureliano Guedes
> skype: aureliano.guedes
> contato:  (11) 94292-6110
> whatsapp +5511942926110
>


Re: I need help with IO.e

2020-05-16 Thread Laurent Rosenfeld via perl6-users
Hi,

it should be:

$ raku *-e* "your one-liner script here"

Best regards,
Laurent.

Le sam. 16 mai 2020 à 12:16, ToddAndMargo via perl6-users <
perl6-users@perl.org> a écrit :

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


Re: More questions on the "-pe" one-liner flag: in conjunction with s/// and tr///

2020-05-07 Thread Laurent Rosenfeld via perl6-users
Hi William,

I guess that you now have answers to your questions. I would suggest,
however, that you take a look as Andrew Shitov's book *Raku One-Liners*,
available on-line (
https://andrewshitov.com/wp-content/uploads/2020/01/Raku-One-Liners.pdf).

There are (around page 12) some explanations on your original question.

Consider especially the following equivalent one-liner programs:

$ raku-npe'.=flip' data.txt

and

$ raku-ne'.flip.say' data.txt

and the related explanations.

Cheers,
Laurent.




Le jeu. 7 mai 2020 à 10:12, Gianni Ceccarelli  a
écrit :

> On 2020-05-06 William Michels via perl6-users 
> wrote:
> > Are there any other "operators that modify their operands" in
> > Raku/Perl6 that don't require an initializing "." (dot)?
>
> The dot is used to call a method on an object.
>
> > I checked the "subst" command and it requires an initial ".=" when
> > used with the "-pe" one-liner flag:
>
> ``subst`` is a method https://docs.raku.org/type/Str#method_subst
>
> To summarise:
>
> * ``-e`` tells raku "execute the next argument as a program"
>
> * both the ``-p`` and ``-n`` command-line switches wrap the program in
>   a loop like::
>
> for $*ARGFILES.lines -> {
>
> }
>
>   ``-p`` additionally puts a ``say $_`` at the end of the block
>
> * inside that loop, the variable ``$_`` will have its value set to
>   each line of the input, one at a time
>
> * you can do whatever you want inside the loop
>
> * the dot calls a method, and if you don't specify an object to call
>   the method on (on the left hand side of the dot), ``$_`` is used
>
> * some operators (like ``s///`` or ``tr///``) operate on ``$_`` unless
>   told otherwise
>
> * assignment (``=``) can be combined with other operators (``+=``,
>   ``/=``, ``.=``, ``~=``, )
>
> If, having seen all that, the behaviour of all your examples is still
> not clear, maybe you should start writing your programs without
> shortcuts and implicit terms: the languages in the Perl family are
> very good at letting you write compact code, but sometimes this comes
> at the expense of clarity. While learning, code that's clear,
> explicit, and straightforward is often more helpful.
>
> --
> Dakkar - 
> GPG public key fingerprint = A071 E618 DD2C 5901 9574
>  6FE2 40EA 9883 7519 3F88
> key id = 0x75193F88
>


Re: More questions on the "-pe" one-liner flag: in conjunction with s/// and tr///

2020-05-06 Thread Laurent Rosenfeld via perl6-users
The s/// substitution operator is not a method (and tr/// also not). They
both modify their operands, so there is no need anyway for a '.=' syntax,
since they do already what the '.=' syntax is aimed at.

Cheers,
Laurent.


Garanti
sans virus. www.avast.com

<#DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2>

Le mer. 6 mai 2020 à 23:11, William Michels  a
écrit :

> Hello,
>
> Can anyone answer why--in a one-liner using the "-pe" flag--the s///
> and tr/// functions do not require a "." (dot) preceding the function
> call? Clearly adding a "." (dot) before either one results in an error
> (code below). Also, adding a ".=" (dot-equals) sign before the either
> the s/// or the tr/// function results in an error (code below).
> Additionally, I would like to know if this is a related-or-different
> issue compared to the question I posted earlier this week.
>
> Any explanation or assistance appreciated,
>
> Thank you, Bill.
>
> mbook:~ homedir$ cat demo1.txt
> this is a test,
> I love Unix,
> I like Linux too,
> mbook:~ homedir$
>
> mbook:~ homedir$ perl6 -pe 's/love|like/admire/; ' demo1.txt
> this is a test,
> I admire Unix,
> I admire Linux too,
> mbook:~ homedir$ perl6 -pe '.s/love|like/admire/; ' demo1.txt
> ===SORRY!=== Error while compiling -e
> Missing required term after infix
> at -e:1
> --> .s/love|like/admire/;
> expecting any of:
> prefix
> term
> mbook:~ homedir$ perl6 -pe '.=s/love|like/admire/; ' demo1.txt
> ===SORRY!=== Error while compiling -e
> Missing required term after infix
> at -e:1
> --> .=s/love|like/admire/;
> expecting any of:
> prefix
> term
> mbook:~ homedir$
>
> mbook:~ homedir$ perl6 -pe 'tr/aeiou/12345/;' demo1.txt
> th3s 3s 1 t2st,
> I l4v2 Un3x,
> I l3k2 L3n5x t44,
> mbook:~ homedir$ perl6 -pe '.tr/aeiou/12345/;' demo1.txt
> ===SORRY!=== Error while compiling -e
> Missing required term after infix
> at -e:1
> --> .tr/aeiou/12345/;
> expecting any of:
> prefix
> term
> mbook:~ homedir$ perl6 -pe '.=tr/aeiou/12345/;' demo1.txt
> ===SORRY!=== Error while compiling -e
> Missing required term after infix
> at -e:1
> --> .=tr/aeiou/12345/;
> expecting any of:
> prefix
> term
> mbook:~ homedir$
>


Re: Inconsistency between one-liner flags (-ne, -pe) using chop example?

2020-05-05 Thread Laurent Rosenfeld via perl6-users
In:
perl6 -ne 'put .chop' demo1.txt

the script prints out the value returned by the chop method, because put
acts on this value.

In:
perl6 -pe '.chop' demo1.txt
the value returned by chop is discarded and the script print $_ unaltered.

Cheers,
Laurent.

Le mar. 5 mai 2020 à 21:07, William Michels via perl6-users <
perl6-users@perl.org> a écrit :

> On Tue, May 5, 2020 at 8:01 AM Gianni Ceccarelli 
> wrote:
> >
> > On 2020-05-05 William Michels via perl6-users 
> > wrote:
> > > mbook:~ homedir$ perl6 -ne 'put .chop' demo1.txt
> > > this is a test
> > > I love Unix
> > > I like Linux too
> > > mbook:~ homedir$ perl6 -pe '.chop' demo1.txt
> > > this is a test,
> > > I love Unix,
> > > I like Linux too,
> >
> > The ``.chop`` method does not mutate its argument, it only returns a
> > chopped value. If you want to mutate, you need to say so::
> >
> >   raku -pe '.=chop' demo1.txt
> >
> > Notice that the ``.=`` operator is:
> >
> > * not specific to ``chop``
> > * not even specific to calling methods
> >
> > In the same way that ``$a += 1`` is the same as ``$a = $a + 1``, so
> > ``$a .= chop`` is the same as ``$a = $a.chop``.
> >
> > So, if you wanted, you could do::
> >
> >   raku -pe '.=uc' # print upper-case
> >
> > --
>
> I appreciate the reply, but your answer fails to explain one thing:
> why does chop work without ".=" assignment using the "-ne" one-liner
> flag, but not with the "-ne" one-liner flag"? According to the help
> screen (running 'perl6 -help' at the bash command prompt), this is
> what it says about the "-n" and the "-e" flags:
>
> -n   run program once for each line of input
> -p   same as -n, but also print $_ at the end of lines
>
> So what strikes me from the definitions above is the part where "-p"
> is the "same as -n... (with autoprinting of $_)." That leads people to
> believe that they can write a short one-liner with the -ne flag ('put
> .chop') and an even shorter one-liner with the -pe flag ('.chop').
>
> If the only difference between the "-n" and "-p" flags is really that
> the second one autoprints $_, I would have expected the "-pe" code
> above to work identically to the "-ne" case (except "-ne" requires a
> print, put or say). Presumably  'perl6 -ne "put .chop" '  is the same
> as  'perl6 -ne ".chop.put" ' , so if  ".put"  isn't returning $_ ,
> what is it returning then?
>
> Look, It's no big deal if I have to write 'perl6 -pe ".=chop" '
> instead of  'perl6 -pe ".chop" ', I just want to resolve in my mind a
> perceived inconsistency wherein there's no requirement to write
> 'perl6 -ne "put .=chop" ' for the "-ne" case, but there IS a
> requirement to write 'perl6 -pe ".=chop" ' for the "-pe" case.
>
> Best Regards, Bill.
>


Re: My keeper on hashes

2020-01-16 Thread Laurent Rosenfeld via perl6-users
 > one of those "Magic" variables that is unbounded, meaning
> I can have a 1024 bit integer if I choose?

Yeah, and even a 1024-digit integer, or much larger, if so you wish.



Le jeu. 16 janv. 2020 à 04:28, ToddAndMargo via perl6-users <
perl6-users@perl.org> a écrit :

> >> On Wed, Jan 15, 2020 at 6:00 PM ToddAndMargo via perl6-users
> >> mailto:perl6-users@perl.org>> wrote:
> >>
> >> A recent addition to my hashes keeper:
> >>
> >>
> >>  Confining hashes:
> >>  Note: as of 2020-01-15, confining only works with Str.
> >>And you must confine the entire hash, not each member
> >>
> >> my Str %h = A => "a"
> >> {A => a}
> >>
> >> my int %h = A => 123
> >> native value types for hashes not yet implemented. Sorry.
> >>
>
> On 2020-01-15 18:27, yary wrote:
> > Capital I in Int, to not use native type
> >
> >> my Int %h = A => 123
> >
> > {A => 123}
> >
> >
> > -y
>
> Hi Yary,
>
> Updated and awesome!  Thank you!
>
> Is Int
>
> https://docs.raku.org/type/Int
> Int objects store integral numbers of arbitrary size
>
> one of those "Magic" variables that is unbounded, meaning
> I can have a 1024 bit integer if I choose?
>
> -T
>


Re: Once again - You say one thing and do another Re: Bug to report: cardinal called an integer

2020-01-15 Thread Laurent Rosenfeld via perl6-users
The point is really not whether people like you or don't, and also not
about whether you like specific  people or don't.

I don't know you (at least personally), you don't know me personally, and
nobody cares about whether I like you or whether you like me.

The whole point is about being polite, constructive, courteous, and
respectful with other people. I suspect you probably know what I mean, you
know, the Netiquette. We can disagree on one point (or on many points, for
that matter) and still listen to the other's arguments in good faith and
reply politely.

Consider the documentation issue. I remember what the documentation was
like 6 or 7 years ago when I really started working on Raku (or Perl 6 at
the time). Yes, it was quite bad. And I complained about this problem in
various tutorials I wrote in French at the time. But it has improved
tremendously since. And I strongly disagree with you on that: I think it is
quite good now. Certainly not perfect, but really much better.

Now, one thing you might be interested to know is that JJ Merelo launched
in August 2018 (at the Edinburgh Perl Conference) a project to improve the
Perl6/Raku documentation. I strongly suspect that he did that because he
found that there was a lot of opportunity for improvement (although I
briefly spoke with him at the time, we did not discuss his deep
motivations, but I would submit that he would not have done that if he
thought the documentation was completely OK). In the 18 months since that,
JJ has committed a lot or effort to improve the documentation. It is still
not perfect. But it has improved a lot, thanks to JJ's efforts, among
others. So, the way you behave with him is just nasty and evil. Please stop
doing that. JJ has contributed an immense service to the community. Please
stop bashing him, this is really awful behavior toward someone who has made
some much effort to improve it.

BTW; thank you, JJ, for that.




Le mer. 15 janv. 2020 à 23:39, ToddAndMargo via perl6-users <
perl6-users@perl.org> a écrit :

> On 2020-01-15 14:18, Elizabeth Mattijsen wrote:
> > Thank you Richard for this long and thoughtful answer.
> >
> > I have already given up on Todd, I'm glad to see others haven't (yet).
> What will follow is probably a response that is either: a. everybody is
> against me, b. the Raku community won't listen, c. the various variations
> on those themes.  I sincerely hope that I'm wrong.
> >
> > Liz
>
> Hi Liz,
>
> Richard has not liked me for a long time.  There
> is really not anything I can do about it but
> maybe wait him out.  I can say the sky is a lovely
> shade of blue and he would find something offensive
> in the remark.
>
>   "a. everybody is against me, b. the Raku
>   community won't listen, c. the various variations
>   on those themes"
>
> U.  I complain about the documentation and the
> difficulty in try to get it fixed.  The rest of Raku,
> I absolute adore and have said so, so many times
> that I fear I am being tiresome.
>
> And the "everybody is against me" remark is in your
> head.  I have NEVER said anything like this.  Complaining
> about the state of the documentation is not complaining
> that everyone is against me.
>
> And to add, I really like the folks on this group
> as well as thank them profusely when they help me.
> I am also starting to be able to return the favor and
> help others.
>
> And I even like you too.  You help me with things
> and you don't even like me.  That is a good character
> trait on your part.  I will wear you down eventually.
>
> Raku and the members of this group are awesome.
>
> -T
>


Re: Once again - You say one thing and do another Re: Bug to report: cardinal called an integer

2020-01-15 Thread Laurent Rosenfeld via perl6-users
I join with Liz and Tom to thank you, Richard, for this long and thoughtful
answer.



Le mer. 15 janv. 2020 à 22:57, Richard Hainsworth 
a écrit :

> Todd,
>
> Once again I find myself writing to you directly in response to a post
> of yours and asking again that you be respectful to others in this
> community. Striving for respect for everyone from everyone directly
> benefits us all.
>
> And disrespect harms you: your long emails defending your points of view
> have no persuasive power because you refuse to listen or to change.
>
> Further the self-aggrandising tone and disrespect to others are - to be
> quite blunt - also consistent with the word and phrases one might
> consider to be indicative of the intellectually challenged. It might be
> wise therefore to re-parse your responses before sending lest the
> readers of this list find their perceptions harden into belief.
>
> You have asked in response to a previous thread that if you are
> disrespectful, that it be pointed out. So here goes.
>
> On 15/01/2020 18:13, ToddAndMargo via perl6-users wrote:
> > On 2020-01-14 01:13, JJ Merelo wrote:
> >
> >> Never miss a good chance to bash documentation...
> >
> > Guilty as charged?
>
> No one has ever called the documentation perfect, but there is only one
> person who goes beyond the reasonable to vilify both the documentation
> and its volunteer creators.
>
> Guilty as charged! (An indication of humility as well as humour on your
> part would have been to replace the '?' with ':)' or some such emoji)
>
> >
> >
> >> By the way, "C String" REQUIRES a nul at the end:
> >> an error in the NativeCall documentation.
> >
> >> No, it does not. And even if it did, it should better go to the C,
> >> not Raku, documentation
>
> Your original complaint was that you had encountered a problem with '\0'
> on strings and you wanted that problem to be included in the Raku
> documentation.
>
> a) Irrespective of whether null-ended strings are a part of C or an
> implementation detail, it is not a Raku problem. So of the two
> assertions that JJ made, one might be debatable within the context of a
> C-language based list, not a Raku list, and the second is True about
> reference materials in Raku,  but arguably the tutorial materials could
> be enhanced.
>
> b) The way in which you present your point of view is
> counter-productive. I would agree with you that for irregular users of C
> working with some libraries, strings without '\0' terminations could
> trigger unexpected responses. It would be useful, therefore, if at an
> appropriate point in the NativeCall POD file, a comment is included to
> this effect.
>
> c) You could provide a useful service to the Raku community by offering
> a PR (Github Pull Request) with a patch.
>
> d) Within the NativeCall POD there is a fairly extended tutorial about
> interfacing to an Internet function in a C library. I wrote that part of
> the document, having myself worked hard to get the function to work. I
> documented my work, created a patch and offered it to the Perl 6
> community. I think it was my first patch. It was accepted. The
> documentation can be changed by newcomers. So long as the contributor is
> willing to LISTEN to requests for changes, as in grammar and spelling.
> Or in placing. By way of another example, I wrote a fairly long document
> about CompUnits, submitted a PR, which was not accepted. So be it. I
> understood the rationale for the rejection.
>
> >
> > Oh Great And Mighty Gatekeeper of the Documentation!
> This is plain disrespect. Calling JJ a dog was also disrespectful.
> Reversing a derogatory term for hyperbole is no less disrespectful.
> >
> > You are in error.  The problem is the mistake in the
> > documentation
> Several people have pointed out to you that they do not consider your
> interpretation of C to be definitive. Nor does it matter. What I could
> agree on (as said above) is that there are peculiarities of some
> versions of C that can trip the unwary, and that the TUTORIALS about an
> interface system, such as NativeCall, could include mention of the trap.
> > you won't fix
>
> It is not JJ's job to FIX the documentation. He has provided substantial
> and significant contributions to the documentation system as a whole. I
> am profoundly grateful to JJ for his efforts.
>
> You could also contribute to the community generated documentation by
> providing a PR.
>
> And please do not refer to your own reference notes. If you do in this
> thread, I will not refrain, as I have done so far, in subjecting them to
> the sort of searing review they deserve.
>
> > and your misunderstand of
> > the C programming language.
>
> Once again this is disrespectful. (In case English is your second
> language, I will not point out the grammatical error.) Since you were
> obviously not given any lessons in etiquette during your long life,
> perhaps a little pointer would be in order here. Rather than directly
> accusing someone of being in error, or 

Re: Bug to report: cardinal called an integer

2020-01-13 Thread Laurent Rosenfeld via perl6-users
> What makes you think I did not understand the documentation?

Your own record over the last years shows that you very often don't
understand documentation (and I actually sometimes wonder whether you're
even really interested in trying to understand it).

Your disdain for the documentation just confirms that. But since you also
explained very clearly times and again in the past that you don't want to
read books or tutorials either, I also wonder whether you're interested in
learning the language. I mean, *really* interested, to the point of making
*real* efforts in that direction.

The way you consistently mixed up uint and Uint in the last hours, despite
having been warned about this mistake, also shows a lack of proper
consideration for the documentation.

The way you obstinately use the word  "cardinal" these last days also shows
it, since there is simply no such thing as cardinals in the Raku types,
subsets, or whatever, and, even though some languages have used it in the
past (and, yes, I have also used Modula-2 in a quite distant past),
"cardinal" is certainly NOT a common IT concept (I mean in the way integer,
unsigned integer, or float are common concepts, often defined by CPU
manufacturers). Granted, most people here probably have a good
understanding of the word "cardinal," but it's essentially a math concept,
and has no precise definition in a programming language, unless of course
the programming language in question does define it, which Raku doesn't.
Yes, cardinals may be loosely described as integers equal to or larger than
zero, but that doesn't make a definition and that tells us nothing about
their range or maximal value, or about the methods that can be invoked on
them, and so on.

So, please, stop using the word "cardinal,", which is just improper,
useless and essentially meaningless in the context of thee Raku language.
Please use the types, subsets and other concept properly defined in Raku.

Sorry, I really don't mean to be blunt, but you should try harder to learn
from what knowledgeable people tell you. Most of those who answered you
know better.

Regards,
Laurent.


Le lun. 13 janv. 2020 à 22:45, ToddAndMargo via perl6-users <
perl6-users@perl.org> a écrit :

> On 2020-01-13 12:43, The Sidhekin wrote:
>
>
>
> On Mon, Jan 13, 2020 at 8:51 PM ToddAndMargo via perl6-users <
> perl6-users@perl.org> wrote:
>
>> On 2020-01-13 11:10, ToddAndMargo via perl6-users wrote:
>> >
>> > https://docs.raku.org/type/UInt
>> > Subset UInt
>> > Unsigned integer (arbitrary-precision)
>> > The UInt is defined as a subset of Int:
>> > my subset UInt of Int where {not .defined or $_ >= 0};
>> > Consequently, it cannot be instantiated or subclassed;
>> > however, that shouldn't affect most normal uses
>>
>> Trivia:
>>
>> In https://docs.raku.org/type/UInt, a cardinal (uint)
>> is a subset
>>
>
>   Nope.  Case matters.  It's mixed case "UInt" (not "uint") that's a
> subset.
>
>
> Absolutely!  uint belongs to UInt
>
>
>
>> In https://docs.raku.org/language/nativetypes, a
>> cardinal (unit) gets their own "native type".
>>
>
>   … whereas (lower case) "uint" is a native type.
>
>   Documentation is easier to understand if you read what it says, and not
> what you expect it to say.
>
>
> Eirik
>
>
> Hi Erik,
>
> "uint" belongs to "UInt".  The error message should tell me one
> of the other.  I prefer "unit", but will compromise on "UInt".
> The ONLY beef I have is with the error message.
>
> What makes you think I did not understand the documentation?
> Perhaps it is you who does not understand me?
>
> Oh this is interesting:
> https://docs.perl6.org/type/UInt  (the raku one is missing the graphic)
>
> "The UInt is defined as a subset of Int:" but does not show on
> the graph.
>
> UInt --> Any --> Mu , but no "Int"
>
> Perhaps better stated would be
> UInt --> Int --> Any --> Numeric --> Mu
>
> I may have Mu and Numeric reversed
>
>
>
> Documentation is a thankless task  and those that do
> it are never appreciated.
>
> -T
>
>
>
>
>
>
>
> --
> ~~
> Computers are like air conditioners.
> They malfunction when you open windows
> ~~
>
>


Re: rakudo.org outdated?

2020-01-03 Thread Laurent Rosenfeld via perl6-users
Hi Patrick,

I'm sure you have plenty of things to do and I don't want to put too much
pressure on you, but it would be really nice to have a good and more
recent  Rakudo Star version available, especially in view of the recent
renaming of the language. I'm writing every week at least two or three blog
posts in which I still have to use "perl6," or "$some-var.perl6" and so on,
because we still don't have a real Raku release. Although I admit that I
wasn't really a big fan of the renaming, now that it has been decided, I
would really prefer to be able to abide to the new naming convention.

Also, I have started to prepare a new *Thing Raku* version of my *Think
Perl 6* book (almost complete), but I can't publish it for the time being
because there is no Rakudo Starr release available right now.

And, by the way, more generally, having a nine-month-old release to offer
on the main download site looks quite bad anyway. It's not you, but
something must be wrong in the process.

Happy new year and best regards,
Laurent.

Le ven. 3 janv. 2020 à 19:02, Patrick Spek via perl6-users <
perl6-users@perl.org> a écrit :

> On Fri, 3 Jan 2020 14:21:14 +0100
> Marc Chantreux  wrote:
>
> > hello people,
> >
> > i read an annoncement for rakudo 2019.11
> > and the last github release confirms that.
> >
> > so i started to update the guix package
> > before discovering that the rakudo.org page
> > still points to 2019.03.
> >
> > is there a problem with the last version or
> > os rakudo.org just outdated?
> >
> > regards.
> >
> > marc
>
> Hi Marc,
>
> I've been working on Rakudo Star 2019.11-rc1, which is available from
> my file server[1]. However, I don't think I've made a regular (non -rc)
> release out of it, as I'm waiting on Naoum to test the release for
> Windows first.
>
> I don't see it listed on the releases page[2] on the GitHub repository
> either, can you tell me where you saw this?
>
> [1]: https://dist.tyil.nl/raku/rakudo-star/
> [2]: https://github.com/rakudo/star/releases
>
> --
> With kind regards,
>
> Patrick Spek
>
>
> www:  https://www.tyil.nl/
> mail: p.s...@tyil.nl
> pgp:  1660 F6A2 DFA7 5347 322A  4DC0 7A6A C285 E2D9 8827
>
> social: https://soc.fglt.nl/tyil
> git:https://gitlab.com/tyil/
>


Re: My Windows Modules

2020-01-03 Thread Laurent Rosenfeld via perl6-users
Hy Todd,

why don't you use GitHub or GitLab? This is really a better solution for
software source and revision control.

Have a nice new year,
Laurent.


Le ven. 3 janv. 2020 à 21:29, ToddAndMargo via perl6-users <
perl6-users@perl.org> a écrit :

> On 2019-12-31 23:12, ToddAndMargo via perl6-users wrote:
> > Hi All,
> >
> > My latest three modules.  two more in the works that use these:
> >
> > WinReg.pm6
> > WinMessageBox
> > NativeConstants.pm6
> >
> > WinReg.pm6 about killed me!
> >
> > -T
> >
>
> Hi All,
>
> Anyone using this code, it is going through some
> major changes.
>
> When I get to another stopping point, I will put it
> on vpaste.net, so as to not overload this list.
>
> -T
>


Re: My keeper on "contains"

2019-12-10 Thread Laurent Rosenfeld via perl6-users
You've made a very interesting point on how difficult it is to write proper
documentation. I hope that Todd will reflect on that.



Le mar. 10 déc. 2019 à 23:45, Rocco Caputo  a écrit :

> On Dec 10, 2019, at 15:35, ToddAndMargo via perl6-users <
> perl6-users@perl.org> wrote:
>
> A method is a routine that you feed: Str.foo.
>
>
> It seems that you're saying the difference between a method and other
> kinds of routines is that methods are "fed" something?
>
> The only thing I can think of that routines are fed are parameters.  So it
> seems that you're saying methods must have parameters, and conversely,
> routines without parameters must not be methods.
>
> But that method invocation doesn't have parameters.  By your definition,
> foo is not a method.
>
> I know what routines and methods are, and I know what feeding is in the
> transitive sense, and what you just wrote doesn't seem to describe a method
> call (or its difference from other function calls).
>
> You seem to be describing technical things with metaphor.  Precision is
> important.  Without it you run a significant risk of being misunderstood
> unless the reader shares your particular frame of reference.
>
> Think of "contains" as looking for a Needle in a Haystack.
> You feed contains data and what you are lookig for.  In
> return is tells you True or False
>
>   say "abc".contains( "a" );
>   True
>
>
> So you want "feed" to mean both passing parameters and supplying an
> invocant?
>
> You could just have said so.  Something like "A method is a routine called
> on an object."  I can see why you'd want to use metaphor to spice that up.
> It's silly, if not tedious, if not completely pointless to restate common
> OO knowledge everywhere you intend to use OO.
>
> Case insensitive contains:
>Note: "fc" converts you to lower case.  It also converts weird charters
> to
>  something on your keyboard
>
>
> I can't use this as documentation.  "something on [my] keyboard" is too
> imprecise (what language is my keyboard?).  I'll need to consult the
> technical documentation to understand "fc" well enough to actually use it.
> Even worse, I suspect "fc" is some kind of mnemonic, and I'd probably have
> understood it better if the expanded term was mentioned.
>
> It seems like using and documenting "fc" adds extraneous details and
> distracts from what this article intends to discuss.  Splitting it into two
> articles with better focus in each would probably be an improvement.
>
> "Str"
>is the string data (Haystack) that will be operated on by the method
> (contains)
>
>
> "data" is wasted everywhere you've used it.  You should consider removing
> it.
>
> ""is the string that will be searched by the 'contains' method" is better
> without "data" and possibly without "(Haystack)".
>
> Your personal note is probably fine since you know what you meant when you
> wrote it.  As documentation for a general audience, I'd say it's badly
> written and needs significant edits.  You should totally self-publish it
> anyway.  Probably in a public repository so that interested people will
> help you improve it.
>
> --
> Rocco Caputo 
>


Re: vulgar?

2019-12-06 Thread Laurent Rosenfeld via perl6-users
Manual pages (which are reference material) and tutorials are two very
different kinds of writing. Manual pages are usually more difficult to
understand than (good) tutorials, because they have to be *very accurate*
and as complete as possible (if not exhaustive), while tutorials can leave
out some intricacies or gory details.



Le ven. 6 déc. 2019 à 07:30, ToddAndMargo via perl6-users <
perl6-users@perl.org> a écrit :

> On 2019-12-05 02:38, Tom Browder wrote:
> > I have had several email conversations with Andrew and he seems like a
> > nice person to me. I sometimes think non-native English speakers pick up
> > bad speech habits because of the absolutely sewer-mouthed "popular"
> > folks on Twitter.
>
>
> For a non-native speaker, he sure runs circles around my
> native speaking ability.  Kind of humbling.
>
> I am glad this is a not a typical thing for him.  His
> writing and examples are really well done.  Not
> one sign of IEEE-eese anywhere.  And I perfectly
> understand everything he says.  He makes the complex
> seem simple.  And that takes talent.
>
> In college, I had several Vietnamese friends that when
> they got together and started speaking Vietnamese to
> each other, they swore in English like a sailor.  When
> I started laughing, I got the "what?" from them.  When
> I told them they were swearing in English, they
> adamantly denied it.  They did not even realizing
> they were.   It was hysterical.
>
> Maybe we could talk him into a re-write of the manual pages?
>


Re: perl6 for web development

2019-09-29 Thread Laurent Rosenfeld via perl6-users
Hi,

you probably want to take a look at Cro. 

Cheers, Laurent.


Le dim. 29 sept. 2019 à 11:37, 星沉  a écrit :

> Hello,
>
> I have been learning perl6 for some days.
> I want to switch to the actual project using perl6.
> Is there any book/guide for web development with perl6?
> I also checked this url:
>
> https://www.reddit.com/r/perl6/comments/6j7b1q/how_much_is_perl_6_ready_for_web_development_what/
>
> But want to find more suggestions from you.
>
> Thanks.
>


Re: Variable character class

2019-09-08 Thread Laurent Rosenfeld via perl6-users
Because sets are unordered collections of items. And the (&) operator
returns a set.



Le dim. 8 sept. 2019 à 00:18, Aureliano Guedes 
a écrit :

> Why does it dont return ordered for neither of those lists?
> I mean:
>
> my $u = "24680";
> my @s = $u.comb.unique;
> say @s ; # [2 4 6 8 0]
>
> sub matching_chars(Str $a, Str $b) {
>my @c = $a.comb.unique;
>my @d = $b.comb.unique;
>return ~[@c (&) @d];
> }
>
> say matching_chars("24680", "1234567890"); # says 2 0 8 4
>
> On Mon, Sep 2, 2019 at 1:20 AM William Michels via perl6-users <
> perl6-users@perl.org> wrote:
>
>> Thanks Simon, good point. I ran into the same trouble as others trying
>> to get the answer via regex, and switched over to sets as an
>> alternative. I'll confess I completely missed that Yary's Perl5 code
>> returned the substring "8420" present in his test "19584203" string,
>> and that was the answer he was going for.
>>
>> Simon and Eirik, I still think there might be some value in calling
>> the .unique method on $chars.comb as in "$chars.comb.unique". But I
>> haven't had the opportunity to check code efficiency  +/-  the
>> ".unique" method call.
>>
>> For those interested in using Sets as a solution, you can stringifying
>> the 'return' line (below). Still working on using "join()" to
>> concatenate!
>>
>> sub matching_chars(Str $a, Str $b) {
>>my @c = $a.comb.unique;
>>my @d = $b.comb.unique;
>>#return (~[@c (&) @d]).^name;
>>return ~[@c (&) @d];
>> }
>>
>> say matching_chars("24680", "19584203"); # says 2 0 8 4
>> say matching_chars('+\/\]\[', 'Apple ][+//e'); # says [ + ] /
>> say matching_chars("Lorem ipsum dolor sit amet, consectetuer
>> adipiscing elit.", "abcdef"); # says c a d e
>>
>>
>> HTH, Bill.
>>
>> PS. Simon, thanks for all the great Youtube videos you've done from
>> LondonPM!
>>
>> https://youtu.be/yt8SrZ_V_50
>> https://youtu.be/9M1xZQ0_Skw
>>
>>
>>
>>
>>
>>
>>
>>
>> On Sun, Sep 1, 2019 at 9:59 AM Simon Proctor 
>> wrote:
>> >
>> > Using a set would be good but it doesn't give you the matching string
>> from the original (which is what I thought was required) otherwise Sets
>> would be my first thought.
>> >
>> > On Sun, 1 Sep 2019, 17:57 William Michels, 
>> wrote:
>> >>
>> >> Hi Yary and Paul and Simon,
>> >>
>> >> I ran into the same difficulties as Yary with repeated characters, so
>> >> I tried the .unique method. Then after a while, I realized that
>> >> problems like this might best be treated as "Set" problems in Perl6.
>> >> Note the Set Intersection operator "(&)" below:
>> >>
>> >> sub matching_chars(Str $a, Str $b) {
>> >>my @c = $a.comb.unique;
>> >>my @d = $b.comb.unique;
>> >>#say @c; say @d;
>> >>return @c (&) @d;
>> >> }
>> >>
>> >> say matching_chars("24680", "19584203"); #RETURNS set(0 2 4 8)
>> >> say matching_chars('+\/\]\[', 'Apple ][+//e'); #RETURNS set(+ / [ ])
>> >>
>> >>
>> >> https://docs.perl6.org/routine/Set
>> >> https://docs.perl6.org/language/operators#infix_(&),_infix_∩
>> >>
>> >> HTH, Bill.
>> >>
>> >>
>> >> On Sat, Aug 31, 2019 at 8:59 PM Paul Procacci 
>> wrote:
>> >> >
>> >> > I'm not entirely sure if this is the correct answer, but if you
>> define your own custom character class
>> >> > with a 'regex' object, you can use that in the grouping.
>> >> >
>> >> > sub matching_chars(Str $chars_to_match, Str $_) {
>> >> > my regex x { $chars_to_match ** 1 };
>> >> > m/<[]>/;
>> >> > }
>> >> >
>> >> > The above worked for me in the very small testing I did.
>> >> >
>> >> > ~Paul
>> >> >
>> >> > On Sat, Aug 31, 2019 at 9:54 PM yary  wrote:
>> >> >>
>> >> >> I found something easy in Perl 5 that's puzzling me in Perl 6-
>> specifying a character class via a variable.
>> >> >>
>> >> >> Perl 5:
>> >> >> sub matching_chars {
>> >> >>   (my $chars_to_match, local $_) = @_;
>> >> >>   /([$chars_to_match]+)/
>> >> >> }
>> >> >>
>> >> >> say matching_chars('24680', '19584203'); # says 8420
>> >> >> say matching_chars('+\/\]\[', 'Apple ][+//e'); # says ][+//
>> >> >>
>> >> >> Perl 6:
>> >> >> sub matching_chars(Str $chars_to_match, Str $_) {
>> >> >> # warnings, treats as string not variable
>> >> >> m/<[$chars_to_match]>/;
>> >> >> }
>> >> >>
>> >> >> How do I get Perl 6 to interpret a variable in the contents of a
>> character class?
>> >> >> From http://docs.perl6.org/language/regexes#Regex_interpolation
>> I'd think that  Rakudo would use the literal contents of $chars_to_match,
>> instead it's using the literal chars "$ c h a r s _ t o _ m a t c h" and
>> warning about repeated c, underscore, etc.
>> >> >>
>> >> >> -y
>> >> >
>> >> >
>> >> >
>> >> > --
>> >> > __
>> >> >
>> >> > :(){ :|:& };:
>>
>
>
> --
> Aureliano Guedes
> skype: aureliano.guedes
> contato:  (11) 94292-6110
> whatsapp +5511942926110
>


Re: learning resources for perl6 beginner

2019-08-24 Thread Laurent Rosenfeld via perl6-users
Just one additional point:

*Think Perl 6* is available in printed form (e.g. from Amazon), but is also
available for free download in PDF format:
https://greenteapress.com/wp/think-perl-6/

Le sam. 24 août 2019 à 20:32, Parrot Raiser <1parr...@gmail.com> a écrit :

> Some books:
>
> "Think Perl 6"http://shop.oreilly.com/product/0636920065883.do
> "Learning Perl 6"http://shop.oreilly.com/product/0636920062776.do
> "Perl 6 At a Glance"   https://perl6.online/perl6-at-a-glance/ (which
> Andrew did mention)
>
> On 8/24/19, William Michels via perl6-users  wrote:
> > Hi Wesley,
> >
> > Andy's being modest. In addition to the official Perl6 docs at:
> > http://docs.perl6.org (as Andy suggests), Check out his many Perl6
> > resources (including videos) at:
> >
> > https://perl6.online/
> > https://perl6.online/contents/
> > https://perl6.online/category/talks/
> >
> > I'm using Andy Shitov's "Perl6 One-Liners" slides to teach myself
> > Perl6 on the command-line, as a modern replacement for sed/awk:
> >
> > https://perl6.online/2019/03/08/perl-6-one-liners-slides/
> >
> https://perl6.online/2018/12/20/using-command-line-options-in-perl-6-one-liners/
> >
> https://perl6.online/2018/12/24/overview-of-the-perl-6-one-liner-advent-calendar-2018/
> >
> > Also check out David Farrell's "Perl6-One-Liners" Github repo:
> >
> > https://github.com/dnmfarrell/Perl6-One-Liners#tutorial
> >
> > Finally, take a look Naoum Hankache's "Perl6Intro" site, and
> > associated Github repo. As an added bonus, Naoum's site is available
> > in thirteen (13) languages:
> >
> > https://perl6intro.com
> > https://github.com/hankache/perl6intro
> >
> > This just scratches the surface (apologies to anyone I've overlooked),
> >
> > HTH, Bill.
> >
> >
> >
> > On Sat, Aug 24, 2019 at 4:15 AM Andrew Shitov  wrote:
> >>
> >> https://perl6.online/perl6-at-a-glance/
> >>
> >> http://docs.perl6.org
> >>
> >>
> >> On Sat, 24 Aug 2019 at 13:13, Wesley Peng  wrote:
> >>>
> >>> Hello,
> >>>
> >>> I am a programmer most time writing code with c/perl 5/ruby.
> >>>
> >>> I know perl6 is coming to the world, have the interest to take a glance
> >>> on it.
> >>>
> >>> For beginner of perl6, can you suggest some resources including online
> >>> documentation or books to get start?
> >>>
> >>> thanks & regards
> >>> Wesley
> >>
> >> --
> >> Andrew Shitov
> >> __
> >> a...@shitov.ru | http://shitov.ru
> >
>


Re: perl6's new name?

2019-08-20 Thread Laurent Rosenfeld via perl6-users
Maybe I wasn't clear enough.  What I meant to say it that I wasn't
enthusiastic about a name change, but, if the name really has to change,
then Camelia is my favorite name.



Le mer. 14 août 2019 à 05:49, Eliza  a écrit :

> Hi,
>
> on 2019/8/14 5:19, Laurent Rosenfeld via perl6-users wrote:
> > Having said that, I should add that if the name should really change, I
> > think Camelia is probably the least bad idea that I can think of.
> >
>
> Following the link:
>
> https://medium.com/@ThePearlSource/pearls-and-birthstones-the-pearl-month-giveaway-f8c0da46fdc0
>
> June - Pearl
> July - Ruby
> August - Peridot
>
> So how about perl6 renames to Peridot or Peri?
>
> regards,
> Eliza
>


Re: perl6's new name?

2019-08-13 Thread Laurent Rosenfeld via perl6-users
I don't think the decision has been made so far. At this point, it is a
proposal  by one (or possibly several) individual(s) whom I very much
respect.

And it is definitely not going to hapopen this week (and quite probably not
this month).

Even though my opinion on the subject is probably irrelevant to most
people, I want to say for the record that I'm personally not in favor of a
name change, as I'm afraid that this will make things even more complicated
than they currently are. Perl 6 has been known under this name for almost
20 years by now, giving it a new name now might just blur everything in the
mind of most people. "The ship has sailed," as they say. I'm afraid that
changing the name today might actually become a marketing disaster. And I
am not saying that as an author of one of the Perl 6 books, my concern is
really not to lose sales on my book (if it were, my book wouldn't be freely
available on-line and open source).

At the same time, I can certainly understand some of the arguments for a
name change.

Having said that, I should add that if the name should really change, I
think Camelia is probably the least bad idea that I can think of.

Cheers,
Laurent.


Le mar. 13 août 2019 à 21:46, William Michels via perl6-users <
perl6-users@perl.org> a écrit :

> I've put up two name suggestions for Perl 6:
>
> NUPERL:
> www.nuperl.orgwww.nuperl.comwww.nuperl.net
>
> NEUPERL:
> www.neuperl.orgwww.neuperl.comwww.neuperl.net
>
> Specifics:
> https://github.com/perl6/problem-solving/issues/81#issuecomment-520960546
>
> I'm not sure why this decision has to be made now. A number of good
> books just released under the "Perl 6" name, so those authors will
> lose sales traction. But if a name-change is inevitable, it seems that
> the 5 year anniversary of the release of Perl 6 is coming up on
> Christmas Day, 2020. Why not then?
>
> I's primary season and election season in the US, so if someone wants
> to put up a Doodle-Poll, this might be fun. We can get a better idea
> of how popular the names Camelia, Raku, ofun, Nuperl, Neuperl,
> larrylang, Albus, Perlsix, Zeta, etc. are .
>
> https://beta.doodle.com/free-poll
>
> Otherwise, why this month? Why this week?
>


Re: [golf?] list of matches

2019-07-09 Thread Laurent Rosenfeld via perl6-users
A small example as a complement to my previous post:

my @a = 1, 2;
my @b = 3, 4;
my @c = @a X @b;   # -> [(1,3), (1,4), (2,3), (2,4)]



Le mar. 9 juil. 2019 à 23:36, Marc Chantreux  a écrit :

> hello people,
>
> i have a game where every opponent much play every other ones
> so i implemented vs to get a list of all the matches from a list
> of opponents.
>
> i'm pretty sure that there is a shorter/more beautiful solution than
> mine so i really would like to see.
>
> mine is
>
>   sub vs (@xs ( $head, *@tail ) ) {
> |($head X @tail),
> |(vs @tail if +@tail)
>   }
>
>   my @rounds = .
>
>   for @rounds -> ( $a, $b )  { say "$a vs $b" };
>
> anyone want to share?
>
> regards,
> marc
>


Re: [golf?] list of matches

2019-07-09 Thread Laurent Rosenfeld via perl6-users
You might want to take a look at the cross ("X") operator, which takes two
or more lists as arguments and returns a list or all lists that can be
constructed combining the elements of each list (or, in other words, a
Cartesian product of the input lists).

Cheers,
Laurent.


Le mar. 9 juil. 2019 à 23:36, Marc Chantreux  a écrit :

> hello people,
>
> i have a game where every opponent much play every other ones
> so i implemented vs to get a list of all the matches from a list
> of opponents.
>
> i'm pretty sure that there is a shorter/more beautiful solution than
> mine so i really would like to see.
>
> mine is
>
>   sub vs (@xs ( $head, *@tail ) ) {
> |($head X @tail),
> |(vs @tail if +@tail)
>   }
>
>   my @rounds = .
>
>   for @rounds -> ( $a, $b )  { say "$a vs $b" };
>
> anyone want to share?
>
> regards,
> marc
>


Re: documentation translation effort ?

2019-07-09 Thread Laurent Rosenfeld via perl6-users
I have updated the Wikipedia page linked in Marc's message. @Marc: please
check it and let me know if you see any remaining issues.

@JJMerelo: I have devoted a lot of efforts translating various P6
documentation into French over the last 5 years or so, including
perl6intro, and probably 250 to 300 additional pages of tutorials and other
public documentation. So, I certainly don't think that this is a waste of
resources. But I fully agree that undertaking to translate the full
official documentation would be a too big project diverting resources from
other useful projects.

Cheers,
Laurent.


Le mar. 9 juil. 2019 à 22:44, JJ Merelo  a écrit :

> There have been some efforts to translate perl6intro; but as Laurent says,
> we can hardly say the documentation is complete, so diverting resources to
> translation is probably not such a good idea.
>
> El mar., 9 jul. 2019 a las 21:53, Laurent Rosenfeld via perl6-users (<
> perl6-users@perl.org>) escribió:
>
>> Hi Marc,
>>
>> the French Wikipedia page you refer to is not really wrong, but rather
>> terribly outdated and, therefore, no longer correct. I have a Wikipedia
>> account and can easily fix that page (using, if needed, the updated English
>> Wikipedia page on the same subject).
>>
>> Translating the whole Perl 6/Raku documentation is a totally different
>> game. It's just too big (and it's a moving target), I won't undertake that.
>>
>> Best,
>> Laurent.
>>
>>
>>
>> Le mar. 9 juil. 2019 à 11:25, Marc Chantreux  a écrit :
>>
>>> hello people,
>>>
>>> i just read this https://linuxfr.org/news/sortie-de-perl-5-30-0 in which
>>> the informations about perl6 are wrong. it points to
>>> https://fr.wikipedia.org/wiki/Rakudo_Perl which is wrong too and i was
>>> thinking that instead of writting wrong stuff on wrong sites, it would
>>> be nice to have a recap of the raku ecosystem (even the historical
>>> parts) directly in the perl6 site. but in french :)
>>>
>>> my broken english disqualify me to write the article itself but i
>>> obviously can translate it. which leads me to the translation effort:
>>>
>>> what if i want to translate the raku documentation? is there an official
>>> workflow? my own would be to get the hash of each file to be translated
>>> and start to translate it in another repo.
>>>
>>> regards,
>>> marc
>>>
>>
>
> --
> JJ
>


Re: Announce: french perl workshop (Aka Journées Perl)

2019-05-23 Thread Laurent Rosenfeld via perl6-users
Hello Mark,

I was thinking about submitting a talk on the P6 Object System, but I could
also change it to Grammars (or do both).

Cheers,
Laurent.


Le mar. 21 mai 2019 à 10:30, Marc Chantreux  a écrit :

> hello perl6 people,
>
> we hope there will be some events around the French Perl Worshop
> (aka journées perl)
>
> https://journeesperl.fr/jp2019/
>
> there will be at least a "perl6 modules hackathon" (trying to contribute
> to the perl6 ecosystem). however i really would like to see a talk or a
> workshop about perl6. some ideas of topics that can be appreciated by
> the audience as well as trivial for some of you:
>
> * perl6 module path (and bytecoded version)
> * getting started with
> * zef and mi6
> * Cro
> * NativeCall
> * Grammars
>
> so we'll be pleased to see you all and if you think you can give a talk:
> don't be shy and show us your perl6 :)
>
> regards
> marc
>


Re: FatRat's falling back to Num's

2019-04-19 Thread Laurent Rosenfeld via perl6-users
Sure Tom,

for example, let's print the first 200 digits of pi.

Since I am getting about 1.2 * $n correct digits for a 0..$n range when
calling the plouffe subroutine, it is sufficient to use the 0..200 range to
get (more than) 200 correct digits.

sub plouffe (Int $k) {
my $result = (1.FatRat / 16 ** $k) * (  (4 / (8 * $k + 1)) - (2 / (8 *
$k + 4)) - (1 / (8 * $k + 5)) - (1 / (8 * $k + 6) )  );
}
# printing 200 digits of pi
my $pi = [+] (plouffe $_ for  0..200);
print substr $pi, 0, 201;

Result (reformatted):
3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348
253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055
596446229489549303819

Note that $pi contains a lot more digits, many of which are not correct,
but the first 201 digits are correct, so I only need to keep the number
that are required.
Cheers,
Laurent.




Le ven. 19 avr. 2019 à 21:47, Tom Browder  a écrit :

> On Fri, Apr 19, 2019 at 08:37 Laurent Rosenfeld via perl6-users <
> perl6-users@perl.org> wrote:
>
>> Hello,
>>
>> in the context of the Perl Weekly Challenge, I was trying to use one of
>> Franco-Canadian mathematician Simon Plouffe's formulas to compute the
>> digits of pi.
>>
>
> Laurent, now that you have the algorithm working as desired, can you show
> how to print all the digits for any N?
>
> Best,
>
> -Tom
>


Re: FatRat's falling back to Num's

2019-04-19 Thread Laurent Rosenfeld via perl6-users
Yes, Brian, you're right, it seems that it is enough to use a FatRat for
the first term, even with an integer input of 400. Thank you very much.

Quite likely because the first term's denominator is the only one that is
growing very fast with an exponentiation, 16 ** $k, while the others only
have multiplications and their growth is much slower.

And BTW, with a summation of the Plouffe terms from 0 to 400, I now get 491
correct digits for pi in less than one second. This is incredibly fast
compared to the other infinite formulas I had tried before (Stévin, Wallis,
Newton, etc.) that converge very slowly. And the code is really simple.

Thank you both, Fernando and Brian, for your help, this solves my little
but interesting problem.
Laurent.



Le ven. 19 avr. 2019 à 18:46, Brian Duggan  a écrit :

> It looks like one FatRat is enough :-)
>
>   $ cat fat.p6
>   sub plouffe (Int $k) {
> my $result = (1.FatRat / 16 ** $k) * (  (4 / (8 * $k + 1)) - (2 /
> (8 * $k + 4)) - (1 / (8 * $k + 5)) - (1 / (8 * $k + 6) )  );
>   }
>
>   say (plouffe $_).WHAT for 0..15;
>
>   say [+]  (plouffe $_ for 0..15)
>
>   $ perl6 fat.p6
>   (FatRat)
>   (FatRat)
>   (FatRat)
>   (FatRat)
>   (FatRat)
>   (FatRat)
>   (FatRat)
>   (FatRat)
>   (FatRat)
>   (FatRat)
>   (FatRat)
>   (FatRat)
>   (FatRat)
>   (FatRat)
>   (FatRat)
>   (FatRat)
>   3.141592653589793238462593174670682882792683045699610435502
>
>
> On Friday, April 19, Laurent Rosenfeld via perl6-users wrote:
> > Thank you very much, Fernando, I'll try that as soon as I get back home.
> >
> > Cheers,
> > Laurent.
> >
> >
> > Le ven. 19 avr. 2019 à 16:00, Fernando Santagata <
> nando.santag...@gmail.com>
> > a écrit :
> >
> > > This one works fine:
> > >
> > > sub plouffe (Int $k) {
> > >   my $result = 1.FatRat *  (1 / 16 ** $k).FatRat * ((4 / (8 * $k +
> > > 1)).FatRat - (2 / (8 * $k + 4)).FatRat - (1 / (8 * $k + 5)).FatRat -
> (1 /
> > > (8 * $k + 6)).FatRat );
> > > }
> > >
> > > say (plouffe $_).WHAT for ^20
> > >
> > > I guess that until a certain point all the terms not specifically cast
> to
> > > FatRat are of type Rat. After reaching the maximum possible Rat they're
> > > converted to Num and FatRat * Num = Num.
> > >
> > > On Fri, Apr 19, 2019 at 3:37 PM Laurent Rosenfeld via perl6-users <
> > > perl6-users@perl.org> wrote:
> > >
> > >> Hello,
> > >>
> > >> in the context of the Perl Weekly Challenge, I was trying to use one
> of
> > >> Franco-Canadian mathematician Simon Plouffe's formulas to compute the
> > >> digits of pi.
> > >>
> > >> For this, I have written the following subroutine:
> > >>
> > >> sub plouffe (Int $k) {
> > >> my $result =   (1 / 16 ** $k) * (  (4 / (8 * $k + 1)) - (2 / (8 *
> $k
> > >> + 4)) - (1 / (8 * $k + 5)) - (1 / (8 * $k + 6) )  );
> > >> }
> > >>
> > >> With this, it should be possible to compute the pi decimals with
> > >> something like this:
> > >>
> > >> > my $k = [+]  (plouffe $_ for 0..15)
> > >> 3.141592653589793129614170564041344859
> > >> >
> > >>
> > >> That doesn't work properly, however as the digitss are wrong after a
> > >> certain rank (16th). The reason seems to be that, after a while,
> rationals
> > >> are converted to floats and precision is lost:
> > >>
> > >> > say (plouffe $_).WHAT for 0..15;
> > >> (Rat)
> > >> (Rat)
> > >> (Rat)
> > >> (Rat)
> > >> (Rat)
> > >> (Rat)
> > >> (Rat)
> > >> (Rat)
> > >> (Rat)
> > >> (Rat)
> > >> (Rat)
> > >> (Num)
> > >> (Num)
> > >> (Num)
> > >> (Num)
> > >> (Num)
> > >> >
> > >>
> > >> So, for an input value of 11 or more, the plouffe subroutine returns a
> > >> Num.
> > >>
> > >> So I decided to try with FatRat:
> > >>
> > >> sub plouffe (Int $k) {
> > >> my $result = 1.FatRat *  (1 / 16 ** $k) * (  (4 / (8 * $k + 1)) -
> (2
> > >> / (8 * $k + 4)) - (1 / (8 * $k + 5)) - (1 / (8 * $k + 6) )  );
> > >> }
> > >>
> > >> It is a bit better, but I am again falling back to Num when the
> > >> subroutine input value reaches 17 or above:
> > >&

Re: FatRat's falling back to Num's

2019-04-19 Thread Laurent Rosenfeld via perl6-users
Thank you very much, Fernando, I'll try that as soon as I get back home.

Cheers,
Laurent.


Le ven. 19 avr. 2019 à 16:00, Fernando Santagata 
a écrit :

> This one works fine:
>
> sub plouffe (Int $k) {
>   my $result = 1.FatRat *  (1 / 16 ** $k).FatRat * ((4 / (8 * $k +
> 1)).FatRat - (2 / (8 * $k + 4)).FatRat - (1 / (8 * $k + 5)).FatRat - (1 /
> (8 * $k + 6)).FatRat );
> }
>
> say (plouffe $_).WHAT for ^20
>
> I guess that until a certain point all the terms not specifically cast to
> FatRat are of type Rat. After reaching the maximum possible Rat they're
> converted to Num and FatRat * Num = Num.
>
> On Fri, Apr 19, 2019 at 3:37 PM Laurent Rosenfeld via perl6-users <
> perl6-users@perl.org> wrote:
>
>> Hello,
>>
>> in the context of the Perl Weekly Challenge, I was trying to use one of
>> Franco-Canadian mathematician Simon Plouffe's formulas to compute the
>> digits of pi.
>>
>> For this, I have written the following subroutine:
>>
>> sub plouffe (Int $k) {
>> my $result =   (1 / 16 ** $k) * (  (4 / (8 * $k + 1)) - (2 / (8 * $k
>> + 4)) - (1 / (8 * $k + 5)) - (1 / (8 * $k + 6) )  );
>> }
>>
>> With this, it should be possible to compute the pi decimals with
>> something like this:
>>
>> > my $k = [+]  (plouffe $_ for 0..15)
>> 3.141592653589793129614170564041344859
>> >
>>
>> That doesn't work properly, however as the digitss are wrong after a
>> certain rank (16th). The reason seems to be that, after a while, rationals
>> are converted to floats and precision is lost:
>>
>> > say (plouffe $_).WHAT for 0..15;
>> (Rat)
>> (Rat)
>> (Rat)
>> (Rat)
>> (Rat)
>> (Rat)
>> (Rat)
>> (Rat)
>> (Rat)
>> (Rat)
>> (Rat)
>> (Num)
>> (Num)
>> (Num)
>> (Num)
>> (Num)
>> >
>>
>> So, for an input value of 11 or more, the plouffe subroutine returns a
>> Num.
>>
>> So I decided to try with FatRat:
>>
>> sub plouffe (Int $k) {
>> my $result = 1.FatRat *  (1 / 16 ** $k) * (  (4 / (8 * $k + 1)) - (2
>> / (8 * $k + 4)) - (1 / (8 * $k + 5)) - (1 / (8 * $k + 6) )  );
>> }
>>
>> It is a bit better, but I am again falling back to Num when the
>> subroutine input value reaches 17 or above:
>>
>> > say (plouffe $_).WHAT for 0..20;
>> (FatRat)
>> (FatRat)
>> (FatRat)
>> (FatRat)
>> (FatRat)
>> (FatRat)
>> (FatRat)
>> (FatRat)
>> (FatRat)
>> (FatRat)
>> (FatRat)
>> (FatRat)
>> (FatRat)
>> (FatRat)
>> (FatRat)
>> (FatRat)
>> (Num)
>> (Num)
>> (Num)
>> (Num)
>> (Num)
>>
>> Has anyone an idea why we are not keeping FatRat values all the way? Or,
>> is there a better way to guarantee that we continue to use FatRat's?
>>
>> Note that I have found other ways of computing many pi digits, but the
>> one described above would be much simpler and much more elegant, if only it
>> worked OK. So my question is really not how to compute pi's digits, but
>> more this: why are the above computations falling from FatRat to Num after
>> a while, and is there something to do to keep FatRat calculation all the
>> way?
>>
>> Thanks to anyone who would be able to shed light on this.
>>
>>
>>
>>
>>
>>
>>
>>
>>
>
> --
> Fernando Santagata
>


FatRat's falling back to Num's

2019-04-19 Thread Laurent Rosenfeld via perl6-users
Hello,

in the context of the Perl Weekly Challenge, I was trying to use one of
Franco-Canadian mathematician Simon Plouffe's formulas to compute the
digits of pi.

For this, I have written the following subroutine:

sub plouffe (Int $k) {
my $result =   (1 / 16 ** $k) * (  (4 / (8 * $k + 1)) - (2 / (8 * $k +
4)) - (1 / (8 * $k + 5)) - (1 / (8 * $k + 6) )  );
}

With this, it should be possible to compute the pi decimals with something
like this:

> my $k = [+]  (plouffe $_ for 0..15)
3.141592653589793129614170564041344859
>

That doesn't work properly, however as the digitss are wrong after a
certain rank (16th). The reason seems to be that, after a while, rationals
are converted to floats and precision is lost:

> say (plouffe $_).WHAT for 0..15;
(Rat)
(Rat)
(Rat)
(Rat)
(Rat)
(Rat)
(Rat)
(Rat)
(Rat)
(Rat)
(Rat)
(Num)
(Num)
(Num)
(Num)
(Num)
>

So, for an input value of 11 or more, the plouffe subroutine returns a Num.

So I decided to try with FatRat:

sub plouffe (Int $k) {
my $result = 1.FatRat *  (1 / 16 ** $k) * (  (4 / (8 * $k + 1)) - (2 /
(8 * $k + 4)) - (1 / (8 * $k + 5)) - (1 / (8 * $k + 6) )  );
}

It is a bit better, but I am again falling back to Num when the subroutine
input value reaches 17 or above:

> say (plouffe $_).WHAT for 0..20;
(FatRat)
(FatRat)
(FatRat)
(FatRat)
(FatRat)
(FatRat)
(FatRat)
(FatRat)
(FatRat)
(FatRat)
(FatRat)
(FatRat)
(FatRat)
(FatRat)
(FatRat)
(FatRat)
(Num)
(Num)
(Num)
(Num)
(Num)

Has anyone an idea why we are not keeping FatRat values all the way? Or, is
there a better way to guarantee that we continue to use FatRat's?

Note that I have found other ways of computing many pi digits, but the one
described above would be much simpler and much more elegant, if only it
worked OK. So my question is really not how to compute pi's digits, but
more this: why are the above computations falling from FatRat to Num after
a while, and is there something to do to keep FatRat calculation all the
way?

Thanks to anyone who would be able to shed light on this.


Re: split and nils?

2019-02-06 Thread Laurent Rosenfeld via perl6-users
Brad told you already: use comb.


Le mer. 6 févr. 2019 à 20:57, ToddAndMargo via perl6-users <
perl6-users@perl.org> a écrit :

> On 2/6/19 5:19 AM, Brad Gilbert wrote:
> > The reason there is a Nil, is you asked for the ord of an empty string.
> >
> >  "".ord =:= Nil
> >
> > The reason there are two empty strings is you asked for them.
>
> What would be the most practice way of converting a string to and
> array of characters?
>
> $x="abc" goes to @y[0]="a", @y[1]="b", @y[2]="c"
>


Re: Exactly what is type match?

2018-12-21 Thread Laurent Rosenfeld via perl6-users
You're free to use a Str method call if you prefer, but using the ~ to
stringify $0 and the like works perfectly for me in perl -e ... context.

$ perl6 -e' "abc" ~~ /.(\w)./; put $0.perl; my $c = ~$0; put $c;'
Match.new(list => (), made => Any, pos => 2, hash => Map.new(()), orig =>
"abc", from => 1)
b

If you get a crash using it, I suspect you made another mistake somewhere.
Please provide the exact P6 one-liner giving you a crash.


Le ven. 21 déc. 2018 à 00:45, ToddAndMargo via perl6-users <
perl6-users@perl.org> a écrit :

> On 12/20/18 2:59 PM, Laurent Rosenfeld via perl6-users wrote:
> > $0 /does /work with "perl6 -e" if you use correctly the tilde ~
> > operator. For example:
> >
> > $ perl6 -e ' "abc" ~~ /.(\w)./; say ~$0;'
> > b
> >
>
> This is because "say" is also a converter.  My issue
> is when assigning to another variable that has been
> "typed".
>


Re: so as a method: Is this expected or a bug?

2018-12-21 Thread Laurent Rosenfeld via perl6-users
Hi Richard,

I don't think it's a bug.  In:
put +@a.so;
the @a array is coerced into a Boolean value (True) by the so method, and
the resulting Boolean value is then coerced into an integer by the +
operator.
Cheers, Laurent.




Le ven. 21 déc. 2018 à 09:28, Richard Hainsworth  a
écrit :

> A snippet:
>
>  my @a = 1..10;
>  put +@a.so; # output 1
>  put so(+@a); # output True
>  put (+@a).so; # output True
>
> This caught me because I used +@s.so when I tried to do something like:
>
>  # in a class with 'has Bool $.pass;'
>  return unless ( $!pass = +@a.so );
>  # fails with a Type mismatch of Int being assigned to Bool
>
> Is this an expected result, or a bug?
>
>
> (I was going to ask this on StackOverflow, but it seems so like a bug
> that I decided to ask here first)
>


Re: Exactly what is type match?

2018-12-20 Thread Laurent Rosenfeld via perl6-users
 ~$0 *does *work with "perl6 -e" if you use correctly the tilde ~ operator.
For example:

$ perl6 -e ' "abc" ~~ /.(\w)./; say ~$0;'
b



Le jeu. 20 déc. 2018 à 23:44, ToddAndMargo via perl6-users <
perl6-users@perl.org> a écrit :

> >> On Thu, Dec 20, 2018 at 5:17 PM ToddAndMargo via perl6-users
> >>  wrote:
> >>>
> > El jue., 20 dic. 2018 21:43, ToddAndMargo via perl6-users
> > mailto:perl6-users@perl.org>> escribió:
> >
> >  Hi All,
> >
> >  Exactly what is type "Match"?
> >
> >  Here I want $D0..$D3 to only be strings.  And it throws a match
> error.
> >
> >  $ p6 'my $x="11.2.3.4"; my Str $D0; my Str $D1; my Str $D2; my
> Str $D3;
> >  $x~~m{ (<:N>) [.] (\d+) [.] (\d+) [.] (\d+) }; $D0 = $0; $D1 =
> $1;
> >  $D2 =
> >  $2; $D3 = $3; print "$D0 $D1 $D2 $D3\n";'
> >
> >  Type check failed in assignment to $D0; expected Str but got
> Match
> >  (Match.new(from => 1, made ...)
> >  in block  at -e line 1
> >
> >  Here is my work around:
> >
> >  $ p6 'my $x="11.2.3.4"; my Str $D0; my Str $D1; my Str $D2; my
> Str $D3;
> >  $x~~m{ (<:N>+) [.] (\d+) [.] (\d+) [.] (\d+) }; $D0 = $0.Str;
> $D1 =
> >  $1.Str; $D2 = $2.Str; $D3 = $3.Str; print "$D0 $D1 $D2 $D3\n";'
> >  11 2 3 4
> >
> >
> >  Many thanks,
> >  -T
> >>>
> >>> On 12/20/18 2:08 PM, JJ Merelo wrote:
>  Put a wriggly ~ in front of $0 to turn it into a Str; it's the Str
>  contextualizer
> 
> >>>
> >>> Hi JJ,
> >>>
> >>> You did not actually answer the question I asked.  What is type
> "Match"?
> >>>
> >>> And I am missing something in your answer
> >>>
> >>> This works:
> >>>
> >>> $ p6 'my $x="11.2."; my Str $D0; my Str $D1; $x~~m{ (<:N>+) [.] (\d+)
> };
> >>> $D0 = $0.Str; $D1 = $1.Str;  print "$D0 $D1\n";'
> >>> 11 2
> >>>
> >>>
> >>> This does not.  One with a space after the ~, one without it.
> >>>
> >>> $ p6 'my $x="11.2."; my Str $D0; my Str $D1; $x~~m{ (<:N>+) [.] (\d+)
> };
> >>> $D0 ~$0; $D1 ~ $1;  print "$D0 $D1\n";'
> >>> WARNINGS for -e:
> >>> Useless use of "~" in expression "$D1 ~ $1" in sink context (line 1)
> >>> Useless use of "~" in expression "$D0 ~$0" in sink context (line 1)
> >>> Use of uninitialized value of type Str in string context.
> >>> Methods .^name, .perl, .gist, or .say can be used to stringify it to
> >>> something meaningful.
> >>> in block  at -e line 1
> >>> Use of uninitialized value of type Str in string context.
> >>> Methods .^name, .perl, .gist, or .say can be used to stringify it to
> >>> something meaningful.
> >>> in block  at -e line 1
> >>> Use of uninitialized value of type Str in string context.
> >>> Methods .^name, .perl, .gist, or .say can be used to stringify it to
> >>> something meaningful.
> >>> in block  at -e line 1
> >>> Use of uninitialized value of type Str in string context.
> >>> Methods .^name, .perl, .gist, or .say can be used to stringify it to
> >>> something meaningful.
> >>> in block  at -e line 1
> >>>
> >>> I am confused,
> >>> -T
>
> On 12/20/18 2:34 PM, Will Coleda wrote:
> > "Match objects are the result of a successful regex match, this does
> > include any zero-width match. They store a reference to the original
> > string (.orig), positional and named captures, the positions of the
> > start and end of the match in the original string, and a payload
> > referred to as AST (abstract syntax tree), which can be used to build
> > data structures from complex regexes and grammars." -
> > https://docs.perl6.org/type/Match
> >
> > When you say $0, you're using the Match. If you want the Str version,
> > explicitly cast it to Str with:
> >
> > ~$0
> >
> > or
> >
> > $0.Str
> >
> > Regards.
> >
>
> So similar to type "Mu".  Kind of all things but doesn't take on
> a particular type until you assign it to something.
>
> I will stick with $0.Str as ~$0 does not work with "perl6 -e".
> And .Str means something to me immediately.  ~ means concatenate
> strings to me, so it takes a bit of thinking.
>
> Thank you!
>


Re: Exactly what is type match?

2018-12-20 Thread Laurent Rosenfeld via perl6-users
Match is a class defining the type of the objects that you get (for example
in variable $/) when a regex match is successful or through regex captures
into $0, $1, etc. or into named captures.

JJ Merelo accurately responded that such objects can be coerced into
strings with the tilde ~ prefix operator. For example, in the code of your
original post:
$D0 = ~$0; $D1 = ~$1; # ...

You may also used double quotes around the match object to the same effect.




Le jeu. 20 déc. 2018 à 23:17, ToddAndMargo via perl6-users <
perl6-users@perl.org> a écrit :

> >> El jue., 20 dic. 2018 21:43, ToddAndMargo via perl6-users
> >> mailto:perl6-users@perl.org>> escribió:
> >>
> >> Hi All,
> >>
> >> Exactly what is type "Match"?
> >>
> >> Here I want $D0..$D3 to only be strings.  And it throws a match
> error.
> >>
> >> $ p6 'my $x="11.2.3.4"; my Str $D0; my Str $D1; my Str $D2; my Str
> $D3;
> >> $x~~m{ (<:N>) [.] (\d+) [.] (\d+) [.] (\d+) }; $D0 = $0; $D1 = $1;
> >> $D2 =
> >> $2; $D3 = $3; print "$D0 $D1 $D2 $D3\n";'
> >>
> >> Type check failed in assignment to $D0; expected Str but got Match
> >> (Match.new(from => 1, made ...)
> >> in block  at -e line 1
> >>
> >> Here is my work around:
> >>
> >> $ p6 'my $x="11.2.3.4"; my Str $D0; my Str $D1; my Str $D2; my Str
> $D3;
> >> $x~~m{ (<:N>+) [.] (\d+) [.] (\d+) [.] (\d+) }; $D0 = $0.Str; $D1 =
> >> $1.Str; $D2 = $2.Str; $D3 = $3.Str; print "$D0 $D1 $D2 $D3\n";'
> >> 11 2 3 4
> >>
> >>
> >> Many thanks,
> >> -T
>
> On 12/20/18 2:08 PM, JJ Merelo wrote:
> > Put a wriggly ~ in front of $0 to turn it into a Str; it's the Str
> > contextualizer
> >
>
> Hi JJ,
>
> You did not actually answer the question I asked.  What is type "Match"?
>
> And I am missing something in your answer
>
> This works:
>
> $ p6 'my $x="11.2."; my Str $D0; my Str $D1; $x~~m{ (<:N>+) [.] (\d+) };
> $D0 = $0.Str; $D1 = $1.Str;  print "$D0 $D1\n";'
> 11 2
>
>
> This does not.  One with a space after the ~, one without it.
>
> $ p6 'my $x="11.2."; my Str $D0; my Str $D1; $x~~m{ (<:N>+) [.] (\d+) };
> $D0 ~$0; $D1 ~ $1;  print "$D0 $D1\n";'
> WARNINGS for -e:
> Useless use of "~" in expression "$D1 ~ $1" in sink context (line 1)
> Useless use of "~" in expression "$D0 ~$0" in sink context (line 1)
> Use of uninitialized value of type Str in string context.
> Methods .^name, .perl, .gist, or .say can be used to stringify it to
> something meaningful.
>in block  at -e line 1
> Use of uninitialized value of type Str in string context.
> Methods .^name, .perl, .gist, or .say can be used to stringify it to
> something meaningful.
>in block  at -e line 1
> Use of uninitialized value of type Str in string context.
> Methods .^name, .perl, .gist, or .say can be used to stringify it to
> something meaningful.
>in block  at -e line 1
> Use of uninitialized value of type Str in string context.
> Methods .^name, .perl, .gist, or .say can be used to stringify it to
> something meaningful.
>in block  at -e line 1
>
> I am confused,
> -T
>


Re: Perl6 use cases

2018-11-12 Thread Laurent Rosenfeld via perl6-users
Hi,
answering a bit late, but better late than never. A couple of uses of Perl
6 at $work.

I'm working, among other things, on a very large application running on VMS
(about 3,500 programs). We"re using a few dozens Perl programs on these
platforms, but we're stuck with a very old version of Perl (5.8).

As you might imagine, I'm not using Perl 6 on VMS servers.

But I have been using Perl 6 grammars to parse programs running on these
VMS servers. One such project was a prototype to demonstrate the
possibility to convert programs written in a proprietary programming
language (actually a subset of that programming language) into Java code.
The second one was to analyze DCL scripts (VMS equivalent of shell scripts)
and extract information about which script is calling which script, which
file they read from and write to, and so on, with the purpose of populating
an extensive graphical documentation database (under Neo4J).

I even delivered a talk on these projects (especially the second one) at
The Perl Conference (TPC, formerly YAPC-Eur) in Glasgow last summer. The
video is on line.

Regards,
Laurent.



Le lun. 5 nov. 2018 à 05:19, N6ghost  a écrit :

> Hi all,
>
> Been looking around trying to find, anyone who is actually using Perl6.
> and what they are using it for.
>
> and if they are, what are there thoughts on it?
>
> Thanks
>
> -N6Ghost
>


Re: Need Golf!

2018-11-08 Thread Laurent Rosenfeld via perl6-users
To me, using *map *in such a context is not the best (although it can
obviously be done).

IMHO, *map *is really intended to generate a list from another list. In
your case, a *for *loop would make more sense to me. Even the use of *grep *(or
*first*) would be more natural than *map*.

But that's probably a matter of personal taste.

Best,
Laurent.





Le jeu. 8 nov. 2018 à 23:46, Paul Procacci  a écrit :

> Had time to think about this on the drive home.
> I've eliminated the for loop which was my goal.
> Any "better" or "cleaner" way of doing this, I'm all ears.  ;)
>
> die Some::Exception.new.throw
> if %!panels.elems && !%!panels.values.map({
>   $end_y < .start_y || $start_x > .end_x ||
>   $start_y > .end_y || $end_x < .start_x
> }).so;
>
>
> On Thu, Nov 8, 2018 at 4:27 PM Paul Procacci 
> wrote:
>
>> I don't like this:
>>
>>
>> for %!panels<>:k {
>>  die Some::Exception.new.throw
>>unless $start_y > %!panels{$_}.end_y   || $end_y   <
>> %!panels{$_}.start_y ||
>>   $end_x   < %!panels{$_}.start_x || $start_x >
>> %!panels{$_}.end_x;
>>
>> }
>>
>>
>> In short, I have a objects stored in hash %!panels that contain the
>> (x,y) coordinates of a square.
>>
>> The function above works; throwing an exception if any of the squares
>> overlap, but I don't like using the for loop here.
>>
>> I'm hoping someone here can provide a similar golfed example.
>>
>> I've been looking at `map` and `so`, but I just can't get my brain to
>> work.
>>
>>
>> Thanks in Advance,
>>
>> ~Paul
>>
>>
>
> --
> __
>
> :(){ :|:& };:
>


Re: need :enc help?I

2018-10-15 Thread Laurent Rosenfeld via perl6-users
This is just a way to pass arguments in a method call.

This is called the colon-pair syntax:
https://docs.perl6.org/language/glossary#index-entry-Colon_Pair



Le lun. 15 oct. 2018 à 12:08, ToddAndMargo via perl6-users <
perl6-users@perl.org> a écrit :

> Hi All,
>
> Over on:
>  https://docs.perl6.org/routine/slurp
>
> This I understand
>  enc => "latin1"
>
> What is
>  :$enc
> ?
>
> Many thanks,
> -T
>


Re: eof ?

2018-10-09 Thread Laurent Rosenfeld via perl6-users
Yes, you're right, it is a Seq. I was trying to be pedagogical, but
probably wasn't very accurate. It is a Seq, and the "slurping" will be lazy.



Le mar. 9 oct. 2018 à 15:30, Curt Tilmes  a écrit :

> On Tue, Oct 9, 2018 at 9:27 AM Laurent Rosenfeld via perl6-users <
> perl6-users@perl.org> wrote:
>
>> This:
>> my $f = $fh.lines;
>> will slurp all the lines into $f (but you can still access the individual
>> items with something like $f[4]).
>>
>
> Is that true?  I supposed that it would hold the Seq as a scalar
> (un-iterated) Seq.
>
> I know that my @f = $fh.lines will slurp it all, but I thought you could
> avoid that by assigning it to a scalar.
>
> Curt
>
>


Re: eof ?

2018-10-09 Thread Laurent Rosenfeld via perl6-users
This:
my $f = $fh.lines;
will slurp all the lines into $f (but you can still access the individual
items with something like $f[4]).

So you don't want to use this in a while loop, since everything will be
consumed during the first loop iteration. Either use a for loop to process
the lines one by one (as shown in my previous answer), and the for loop
will stop once you've read the whole file, and this is probably the way to
go if your file is large:
for "test.txt".IO.lines -> $c { say $c }
or possibly
.say for "text.txt".IO.lines;
or you can dump all the lines into an array (and later process the array):
my @f =  "test.txt".IO.lines;


Le mar. 9 oct. 2018 à 14:49, ToddAndMargo via perl6-users <
perl6-users@perl.org> a écrit :

> On 10/9/18 5:42 AM, Fernando Santagata wrote:
> > The answer Laurent Roseenfeld gave you works for read and readchars as
> well.
> > Save the following lines in a file and run it (try and change .read into
> > .readchars too); it will output a series of 10-byte long Buf[uint8]s,
> > until it reaches the end of file.
> >
> > #!/usr/bin/env perl6
> > given $*PROGRAM-NAME.IO.open {
> >while my $bytes = .read: 10 {
> >  $bytes.say;
> >}
> > }
> >
> > On Tue, Oct 9, 2018 at 10:17 AM ToddAndMargo via perl6-users
> > mailto:perl6-users@perl.org>> wrote:
> >
> > On 10/9/18 1:02 AM, ToddAndMargo via perl6-users wrote:
> >  > Hi All,
> >  >
> >  > When reading a text file
> >  > https://docs.perl6.org/routine/lines
> >  > seems pretty straight forward.
> >  >
> >  > Question:  How do I tell when I when I have
> >  > reached the EOF (End Of File)?
> >  >
> >  > Many thanks,
> >  > -T
> >
> > Please expand the question to include `read` and `readchars`.
> >
> >
> >
> > --
> > Fernando Santagata
>
> Hi Frenando,
>
> Thank you for the help!
>
> I am not getting anywhere with `.lines`.  Read the whole thing in the
> first line.
>
> $ p6 'my $fh=open "/home/linuxutil/WhoIsMySub.pl6", :r;  while my $f =
> $fh.lines { say "$f\n"}; $fh.close;'
>
> #!/usr/bin/env perl6  sub f() { put &?ROUTINE.gist; };  sub abc () {
> say "This subroutine's ID is ", f; print "\n";  &?ROUTINE.gist
> ~~ m/' '(.*?)' '\(/;  my $SubName = $0; say "This subroutine is
> called $SubName"; }  abc;
>
> -T
>


Re: eof ?

2018-10-09 Thread Laurent Rosenfeld via perl6-users
The eof method of the IO::Handle class returns True if you exhausted the
contents of the handle, but you generally don't need to use that, since
something like:

for 'input.txt'.IO.lines -> $line {
# Do something with $line
}

will gracefully handle ends of files for you without you having to do
anything special.



Le mar. 9 oct. 2018 à 10:03, ToddAndMargo via perl6-users <
perl6-users@perl.org> a écrit :

> Hi All,
>
> When reading a text file
>  https://docs.perl6.org/routine/lines
> seems pretty straight forward.
>
> Question:  How do I tell when I when I have
> reached the EOF (End Of File)?
>
> Many thanks,
> -T
>


Re: <> thank you

2018-10-05 Thread Laurent Rosenfeld via perl6-users
You don't even need the quotes:

> say [3,1];
(Nil cd)
>



Le ven. 5 oct. 2018 à 10:15, Todd Chester  a écrit :

>
>
> On 10/5/18 1:12 AM, Todd Chester wrote:
> >>> Le ven. 5 oct. 2018 à 08:30, Todd Chester  >>> <mailto:toddandma...@zoho.com>> a écrit :
> >>>
> >>> Hi All,
> >>>
> >>> I went to reply to someone, I think it was Brandon for sending me
> >>> an eMail to my private address and the stinker disappeared!
> >>>
> >>> Anyway whoever sent me
> >>>
> >>>   $ p6 'say [0,2];'
> >>>   (the brown)
> >>>
> >>> I was trying to figure out why this bombed:
> >>>
> >>>   $ p6 ' say "a b c d"[3,1];'
> >>>   Index out of range. Is: 3, should be in 0..0
> >>>   in block  at -e line 1
> >>>
> >>> And you beat me to the punch!  It was the <>.
> >>>
> >>> Thank you!
> >>>
> >>> -T
> >>>
> >
> >
> > On 10/5/18 12:31 AM, Laurent Rosenfeld via perl6-users wrote:
> >> Yeah, Todd, the angle brackets operator in  produces
> >> a list of three words which you can access individually with an index,
> >> whereas quotes in  "a b c d" creates a single string. But to come back
> >> to the start of a very long thread of discussion over the last days,
> >> if you want to access individual words of the string, you can of
> >> course do this:
> >>  > say "a b c d".words[3,1];
> >> (d b)
> >>
> >> Cheers, Laurent.
> >>
> >>
> >>
> >
> > Hi Laurent,
> >
> > Thank you!
> >
> > This makes it clear in my mind what is happening.
> >   $ p6 'dd ;'
> >   ("a", "b", "c", "d")
> >
> > [] need to be given a "list" of things.  And
> >   $ p6 'dd "a b c d";'
> >   "a b c d"
> > a string is not a list.  The give away is the () that dd
> > produces.
> >
> > -T
>
>
> $ p6 ' say <"ab" "cd" "ef">[3,1];'
> (Nil "cd")
>
>
> :-)
>


Re: Feedback requested on playlist of 200 Perl 6 videos

2018-10-05 Thread Laurent Rosenfeld via perl6-users
This list is quite useful, thank you Raiph for it. I've found some that I
did not know about.
Cheers, Laurent.


Le jeu. 4 oct. 2018 à 01:03, Ralph Mellor  a
écrit :

> On Wed, Oct 3, 2018 at 6:16 AM David Green <
> david.gr...@pl-comme.ci-comme.ca> wrote:
>
>> There are  quite a few recorded P6 presentations around, but I
>> don't know if  there's a collected list anywhere, or one that links
>> to recent talks (anything not too out-of-date).
>>
>
> I've been building a collection of P6 videos for about 5 years.
>
> I'm pretty sure I've caught most of the reasonably obvious ones.
>
> I've reviewed them all and added a couple hundred to a playlist.
>
> I include a tweet sized summary for each.
>
> The most recent 100 are post 6.c. Older ones go back a decade.
>
>
> https://www.youtube.com/playlist?list=PLRuESFRW2Fa77XObvk7-BYVFwobZHdXdK_polymer=true
>
> A few months ago google changed something so they start at
> random times. that's badly screwed things up. I've researched
> and it looks like I'll have to rebuild the playlist. So now would
> be a great time for anyone to give me feedback on what they
> think of this list of videos, or the summary I've written for any
> video you watch some of, or any other comment you care to
> make.
>
> TIA.
>
> --
> raiph
>


Re: <> thank you

2018-10-05 Thread Laurent Rosenfeld via perl6-users
Yeah, Todd, the angle brackets operator in  produces a
list of three words which you can access individually with an index,
whereas quotes in  "a b c d" creates a single string. But to come back to
the start of a very long thread of discussion over the last days, if you
want to access individual words of the string, you can of course do this:
> say "a b c d".words[3,1];
(d b)

Cheers, Laurent.



Le ven. 5 oct. 2018 à 08:30, Todd Chester  a écrit :

> Hi All,
>
> I went to reply to someone, I think it was Brandon for sending me
> an eMail to my private address and the stinker disappeared!
>
> Anyway whoever sent me
>
>  $ p6 'say [0,2];'
>  (the brown)
>
> I was trying to figure out why this bombed:
>
>  $ p6 ' say "a b c d"[3,1];'
>  Index out of range. Is: 3, should be in 0..0
>  in block  at -e line 1
>
> And you beat me to the punch!  It was the <>.
>
> Thank you!
>
> -T
>


Re: Could this be any more obscure?

2018-10-02 Thread Laurent Rosenfeld via perl6-users
Yes, [] acts on the result (a positional, e.g. a list) returned by function
or method, it does not act on the function or method itself.

You have more or less the same in Perl 5, for example:

my $first_item = (split /;/, $string)[0];

Here, the [0] acts on the list returned by split.


Le mar. 2 oct. 2018 à 08:05, ToddAndMargo  a écrit :

> On 10/1/18 3:37 PM, Donald Hunter wrote:
> > toddandma...@zoho.com (ToddAndMargo) writes:
> >>
> >> Hi Curt,
> >>
> >> Perfect! Thank you!
> >>
> >> So all methods that respond with --> Positional will accept []
> >>
> >> Awesome!
> >>
> >> -T
> >
> > Not quite.
> >
> > All methods that respond with --> Positional, provide a Positional that
> > will accept []
> >
> > Methods don't accept [], values that are positional do that.
> >
> > Cheers,
> > Donald.
> >
>
> Hi Donald,
>
> I am confused.  I though we both said the same thing?
> Is your distinction that [] is actually a routine in itself
> and not part of the method?  And I am lumping them together?
>
> -T
>


Re: Could this be any more obscure?

2018-09-30 Thread Laurent Rosenfeld via perl6-users
Hi Todd,
I disagree with you. The P6 documentation can certainly be improved, but it
is quite good and clear already. Remember that it is technical
documentation, not a tutorial.

And the example you chose to give does not support your point: the P6
documentation for join is just at least as clear as the P5 documentation on
the same function.

When I wrote my book on Perl 6, there was no other P6 book around, so I had
to rely heavily on the existing documentation for all kinds of syntax
details, and I found that is was quite useful and even easy (and it has
improved quite a bit since then). You're welcome to help improving the
documentation, but, please, don't say it's bad just because you don't want
to make the effort needed to understand it.

If you don't understand the signatures in the documentation, you've
basically two possible solutions: just skip them, as you can certainly
understand how to use a built-in function without understanding the
signature (but it is still very useful to have the signature definition in
the documentation), or bite the bullet and learn how to read signatures.

Despite your denegation, I think that what you really need is to read a
good tutorial or book on Perl 6. If you had made a real effort to read such
introductory material, you would probably not have needed to ask about 90%
of the questions you asked lately. Do yourself a favor: read good
introductory material (tutorials or books).

HTH,
Laurent.


Le dim. 30 sept. 2018 à 11:32, ToddAndMargo  a
écrit :

> On 9/26/18 7:27 PM, Brandon Allbery wrote:
> > And again: this is only because you know perl 5. People are not born
> > knowing perl 5; to someone who doesn't know it, perldoc raises the same
> > kinds of questions you have been asking, and the answers have to be
> > found in perlsyn or perldata, etc. Which is exactly what you have been
> > complaining about with respect to perl 6 doing the same kind of thing.
>
> Geez Louise Bradley!  The above is a really bad argument!
>
> "perldocs -f xxx" is a bazillion times easier to understand
> than Perl 6's manual, regardless if you know Perl 5 or not.
>
> And, by the way, I wonder just how may are coming to Perl 6
> without ANY Perl 5 experience?
>
> In every instance I can look up, perldocs puts Perl 6's
> documentation to shame.
>
> A simple comparison: which one leaves you knowing how to use
> the function and which one leaves you wondering "What the h***???"
>
> $ perldoc -f join
>  join EXPR,LIST
>  Joins the separate strings of LIST into a single string with
>  fields separated by the value of EXPR, and returns that new
>  string. Example:
>
> my $rec = join(':',
> $login,$passwd,$uid,$gid,$gcos,$home,$shell);
>
>  Beware that unlike "split", "join" doesn't take a pattern
>  as its first argument. Compare "split".
>
>
>
> https://docs.perl6.org/routine/join#(List)_routine_join
>
>  (List) routine join
>
>  Defined as:
>
>  subjoin($separator, *@list --> Str:D)
>  method join(List:D: $separator --> Str:D)
>
>  Treats the elements of the list as strings, interleaves
>  them with $separator and concatenates everything into a
>  single string.
>
>  Example:
>
>  join ', ', ; # RESULT: «a, b, c»
>
>  Note that the method form does not flatten sublists:
>
>  say (1, ).join('|'); # OUTPUT: «1|a b c␤»
>
>
> Oh and what the &*@% is a "*@list"?  And why does the sub have one
> and the method does not?  They are suppose to be identical.
>
> -T
>


Re: Could this be any more obscure?

2018-09-30 Thread Laurent Rosenfeld via perl6-users
The star in the signature states that @list is a slurpy (or variadic)
parameter, i.e. that @list will slurp up all remaining arguments provided
to the subroutine.

See: https://docs.perl6.org/type/Signature#index-entry-slurpy_argument



Le dim. 30 sept. 2018 à 11:32, ToddAndMargo  a
écrit :

> On 9/26/18 7:27 PM, Brandon Allbery wrote:
> > And again: this is only because you know perl 5. People are not born
> > knowing perl 5; to someone who doesn't know it, perldoc raises the same
> > kinds of questions you have been asking, and the answers have to be
> > found in perlsyn or perldata, etc. Which is exactly what you have been
> > complaining about with respect to perl 6 doing the same kind of thing.
>
> Geez Louise Bradley!  The above is a really bad argument!
>
> "perldocs -f xxx" is a bazillion times easier to understand
> than Perl 6's manual, regardless if you know Perl 5 or not.
>
> And, by the way, I wonder just how may are coming to Perl 6
> without ANY Perl 5 experience?
>
> In every instance I can look up, perldocs puts Perl 6's
> documentation to shame.
>
> A simple comparison: which one leaves you knowing how to use
> the function and which one leaves you wondering "What the h***???"
>
> $ perldoc -f join
>  join EXPR,LIST
>  Joins the separate strings of LIST into a single string with
>  fields separated by the value of EXPR, and returns that new
>  string. Example:
>
> my $rec = join(':',
> $login,$passwd,$uid,$gid,$gcos,$home,$shell);
>
>  Beware that unlike "split", "join" doesn't take a pattern
>  as its first argument. Compare "split".
>
>
>
> https://docs.perl6.org/routine/join#(List)_routine_join
>
>  (List) routine join
>
>  Defined as:
>
>  subjoin($separator, *@list --> Str:D)
>  method join(List:D: $separator --> Str:D)
>
>  Treats the elements of the list as strings, interleaves
>  them with $separator and concatenates everything into a
>  single string.
>
>  Example:
>
>  join ', ', ; # RESULT: «a, b, c»
>
>  Note that the method form does not flatten sublists:
>
>  say (1, ).join('|'); # OUTPUT: «1|a b c␤»
>
>
> Oh and what the &*@% is a "*@list"?  And why does the sub have one
> and the method does not?  They are suppose to be identical.
>
> -T
>


Re: Could this be any more obscure?

2018-09-30 Thread Laurent Rosenfeld via perl6-users
There is no need for a question mark after the $limit parameter, since
supplying a default value for a parameter is sufficient to make this
parameter optional.



Le dim. 30 sept. 2018 à 11:17, ToddAndMargo  a
écrit :

> On 9/30/18 1:21 AM, JJ Merelo wrote:
> >
> >
> > El dom., 30 sept. 2018 a las 10:15, Laurent Rosenfeld via perl6-users
> > (mailto:perl6-users@perl.org>>) escribió:
> >
> > the words method is extracting items from an input string. The
> > $limit parameter tells the words method to extract not more than
> > $limit items from the string. Setting the default to Inf only tells
> > the  method to extract as many items as it can from the input (i.e.
> > to process the whole string), without any limit. But since the input
> > string cannot be infinite, the number of items will also not be
> > infinite. So, the Inf default for $limit just states that there is
> > no limit, but you'll never get an infinity of items from a
> > non-infinite string.
> >
> >
> > There's no Inf default now in the definition (after latest code
> > changes), and it's been changed in the documentation accordingly. It's
> > left in the examples, however (since that "default" is in the code too,
> > and is tested in roast), but that can be eliminated if it leads to
> > confusion.
> >
> > Cheers
> >
> > JJ
>
>
> Hi JJ,
>
> I am confused.  I thought that
>
>   $limit = Inf
> used in
>
>   multi method words(Str:D $input: $limit = Inf --> Seq)
> meant that the default was "Inf"
>
> Also, it is not stated that $limit is optional.  I would
> propose adding a "?" to the end of $limit:
>
>   multi method words(Str:D $input : $limit? = Inf --> Seq)
>
> This would keep with the subroutine rules for the declarations
> of optional variables.
>
> -T
>


Re: Could this be any more obscure?

2018-09-27 Thread Laurent Rosenfeld via perl6-users
> I am NOT asking it to limit my request to Infinity.

Yes you are, implicitly. If you don't pass any parameter for $limit, $limit
will take the default value supplied by the signature, i.e. Inf.



Le jeu. 27 sept. 2018 à 02:48, ToddAndMargo  a
écrit :

> On 9/26/18 4:33 PM, The Sidhekin wrote:
> > On Wed, Sep 26, 2018 at 11:40 PM ToddAndMargo  > > wrote:
> >
> > What I don't understand is:
> >
> >multi method words(Str:D $input: $limit = Inf --> Positional)
> >
> > Specifically "$limit = Inf".  Why are we using "$limit" instead
> > of "$selection"
> >
> >Perhaps this would be easier if you explain where you're getting
> > "$selection", and what you think it is.
>
> $ p6 '"a b c d e".words[ 2, 4 ].say;'
> (c e)
>
> or
>
> $ p6 '"a b c d e".words()[ 2, 4 ].say;'
> (c e)
>
> I am selecting the 2nd and 4th word starting from zero.  Inside
> the brackets I am asking it to select th e 2nd and 4th words for me.
>
> I am NOT asking it to limit my request to Infinity.
>
>
>
> >
> > And where is it stated what goes in the () and what goes
> > in the []?
> >
> >
> >The () is part of a method call syntax; method arguments go there:
> > https://docs.perl6.org/language/syntax#Subroutine_calls
>
> Where does it state that
>
> $ p6 '"a b c d e".words(3).say;'
> (a b c)
>
> means the first three words, starting at zero?
>
>
> >The [] is a postcircumfix operator; index arguments go there:
> > https://docs.perl6.org/language/operators#postcircumfix_[_]
>
> Where does
>
>  multi method words(Str:D $input: $limit = Inf --> Positional)
>
> state that I can do such?
>
> I ask this because not all methods will take []
>
>
> $ p6 '"a b c d e".contains( "a","b" ).say;'
> Cannot convert string to number: base-10 number must begin with valid
> digits or '.' in '⏏b' (indicated by ⏏)
>in block  at -e line 1
>
> $ p6 '"a b c d e".contains( 1, 3 ).say;'
> Ambiguous call to 'contains(Str: Int, Int)'; these signatures all match:
> :(Str:D: Cool:D $needle, Cool:D $pos, *%_)
> :(Str:D: Cool:D $needle, Cool:D $pos, *%_)
>in block  at -e line 1
>
>
> Also, where is it stated that
>
> $ p6 '"a b c d e".words(3)[ 2, 4 ].say;'
> (c Nil)
>
> will send the first three words to [2,4] ?
>
> Thank you for helping me with this!
>
> -T
>


Re: Could this be any more obscure?

2018-09-26 Thread Laurent Rosenfeld via perl6-users
You can set a limit to the number of items (words) you want to retrieve:
you will get only the first $limit words.

If you don't supply any limit, Inf can be thought as the default value for
the number of items, i.e. there is no limit and the routine will return as
many words as it can from the source input.


Le mer. 26 sept. 2018 à 23:19, ToddAndMargo  a
écrit :

> >> On Wed, Sep 26, 2018 at 2:57 AM Todd Chester  >> multi method words(Str:D $input: $limit = Inf --> Positional)
>
>
> On 9/26/18 7:21 AM, Brandon Allbery wrote:
>
> > $limit sets a limit on how many words it will make. Inf means there's no
> > limit. Your assumption that it must be some kind of array index doesn't
> > make a lot of sense; this doesn't index at all, it splits at whitespace
> > until it's got the number of chunks you told it to make, indexing the
> > result is your problem. Small pieces of functionality, not "god
> > functions" that try to do everything you can possibly think of.
>
> Hi Brandon,
>
> So, "$limit = Inf" means that I can put an infinite number of
> stuff in the [] or ()
>
> p6 '"a b c d e".words(3)[2,4].say;'
> (c Nil)
>
> $ p6 '"a b c d e".words(3).say;'
> (a b c)
>
>
> I really think that could be written better.
>
> First off the parameter is not a "limit".  It is
> a selection.
>
> And second, "Inf" is a "type", meaning "infinity" or larger
> than Perl's memory allocation can handle.  It is confusing
> to use it to state that there can be any number of selections
> in the parameter.
>
> $ p6 '"a b c d e".words()[2,4,1,3,3,3,3,20].say;'
> (c e b d d d d Nil)
>
> It also does not tell that the parameter(s) is/are integers
> or what happens if you supply a sting (error) or a real (it
> truncates):
>
>  $ p6 '"a b c d e".words()["a"].say;'
>  Cannot convert string to number: base-10 number must begin
>  with valid digits or '.' in '⏏a' (indicated by ⏏)
>  in block  at -e line 1
>
> $ p6 '"a b c d e".words()[ 2.5 ].say;'
> c
>
> Third, it does not state the difference between using () and [].
> Or how to mix and match them.
>
> $ p6 '"a b c d e".words(3).say;'
> (a b c)
>
> Where (3) gives you the first three words
>
> -T
>


Re: A comparison between P5 docs and p6 docs

2018-09-11 Thread Laurent Rosenfeld via perl6-users
Hi Todd,

I fully agree with Tom B.'s message that you should really set out to read
a Perl 6 book. Many of the things you asked are covered in most of the
available books. And the available books are easier than the official
documentation for a beginner to start understand the basic underlying
concepts.

I should add that you don't even have to *buy* one book, since my own *Think
Perl 6* book is freely available on the Internet (Creative Commons
license): https://greenteapress.com/wp/think-perl-6/. Well, if you are
interested in reading it, I'd suggest you look for the PDF on my Github
repository (https://github.com/LaurentRosenfeld/thinkperl6/tree/master/PDF),
because it is more up-to-date (number of small corrections made following
comments from readers).

So it would take you just a few minutes (at no cost) to download it and
start enjoying it.

Cheers,
Laurent.

Le mar. 11 sept. 2018 à 13:26, ToddAndMargo  a
écrit :

> Hi All,
>
> Not to beat a dead horse, but Perl 6's docs are
> miserably hard to understand.
>
> Here is a comparison of Perl 5's perldocs and Perl 6's
> docs:
>
> Perl 5:
>
> $ perldoc -f index
>  index STR,SUBSTR,POSITION
>  index STR,SUBSTR
> The index function searches for one string within another,
> but without the wildcard-like behavior of a full regular-
> expression pattern match. It returns the position of
> the first occurrence of SUBSTR in STR at or after POSITION.
> If POSITION is omitted, starts searching from the beginning
> of the string. POSITION before the beginning of the string
> or after its end is treated as if it were the beginning
> or the end, respectively. POSITION and the return value
> are based at zero. If the substring is not found, "index"
> returns -1.
>
> Perl 6:
>
>  https://docs.perl6.org/routine/index
>
>  Documentation for sub index assembled from the following types:
>  class Cool
>
>  From Cool
>  (Cool) routine index
>
>  Defined as:
>
>  multi subindex(Str(Cool) $s, Str:D $needle, Int(Cool) $startpos
> = 0 --> Int)
>  multi method index(Str(Cool) $needle, Int(Cool) $startpos = 0 --> Int)
>
>  Coerces the first two arguments (in method form, also counting
>  the invocant) to Str, and searches for $needle in the string
>  starting from $startpos. It returns the offset into the string
>  where $needle was found, and an undefined value if it was not
>  found.
>
>  See the documentation in type Str for examples.
>
>
> "Cources"??? Seriously:
>
>  https://www.merriam-webster.com/dictionary/coerce
>  Definition of coerce coerced; coercing
> transitive verb
> 1 : to compel to an act or choice
> was coerced into agreeing
> abusers who coerce their victims into silence
>
> 2 : to achieve by force or threat
> coerce compliance
> coerce obedience
>
> 3 : to restrain or dominate by force
>
> And what the heck is a "multi sub" and a "multi method" anyway?
> AND WHY DO I EVEN CARE?  I just what to know how to use the
> stinking thing!  Geepers Creapers !!!  (I am trying to avoid
> swearing.)
>
> Perl 5's perldoc just tells you what you need to know to use the
> stinker.  It is concise and to the point.  Perl 6 is a nightmare
> to understand.
>
> Thank for putting up with my frustration.
>
> -T
>


Re: case insensitive "contains"?

2018-09-10 Thread Laurent Rosenfeld via perl6-users
Yes, copy and paste error on the last code snippet.

say "Yes" if "2018 xJul 7" ~~ m/j :i ul/;

Cheers,
Laurent.


Le lun. 10 sept. 2018 à 16:54, yary  a écrit :

> > say "Yes" if "2018 xJul 7" ~~ m:i/j :i ul/;
> you mean
>
> say "Yes" if "2018 xJul 7" ~~ m/j :i ul/;
>
> m/.../ - not m:i at the start!
>
> -y
>
> On Mon, Sep 10, 2018 at 4:54 AM, Laurent Rosenfeld via perl6-users <
> perl6-users@perl.org> wrote:
>
>> Hi Todd,
>>
>> you may use:
>>
>> say "Yes" if "2018 xJul 7" ~~ /:i jul/;
>>
>> or:
>>
>> say "Yes" if "2018 xJul 7" ~~ m:i/jul/;
>>
>> In the second case, the adverb will apply to the whole pattern. In the
>> first case, it will start to apply from the point where the adverb is. In
>> this specific example, those two code samples will be equivalent since the
>> adverb is at the beginning of the pattern. But it would make a difference
>> if the adverb is somewhere else within the pattern. For example, this would
>> fail:
>>
>> say "Yes" if "2018 xJul 7" ~~ m:i/j :i ul/;
>>
>> because the ignore case adverb would apply only on the 'ul' characters of
>> the pattern, but not on the 'j'.
>>
>> More on adverbs in regexes:
>> https://docs.perl6.org/language/regexes#Adverbs
>>
>> Cheers,
>> Laurent.
>>
>>
>> Le lun. 10 sept. 2018 à 00:00, ToddAndMargo  a
>> écrit :
>>
>>> On 09/08/2018 12:23 PM, Laurent Rosenfeld via perl6-users wrote:
>>> > Using the fc method is certainly a good way to do case insensitive
>>> > string comparisons, but you may at this point also use a regex with
>>> the
>>> > :i (ignore case) adverb.
>>> >
>>> >  > if "2018 xJul 7" ~~ /:i jul/ {say "Yes";}
>>> > Yes
>>> >
>>>
>>> Hi Laurent,
>>>
>>> Thank you!  Another weapon in my tool box!
>>>
>>> Question:  this confused me when I first look at it.  I am use to
>>> the ":x" command being outside the first "/".  For instance
>>>  s:g/
>>>
>>> What are the rules for what goes inside and what goes outside?
>>>
>>> Also, do y have a link to what the various ":x" commands are
>>> that I can use?
>>>
>>> I generally prefer to use "contains", "starts-with", and
>>> "ends-with" when the string is full of trash that regex needs
>>> to escape.  For example:
>>>
>>> if $Line.contains( 'HWiNFO ' & '
>>> Installer' ) {
>>>
>>>
>>> Many thanks,
>>> -T
>>>
>>>
>>> --
>>> ~
>>> When we ask for advice, we are usually looking for an accomplice.
>>> --  Charles Varlet de La Grange
>>> ~
>>>
>>
>


Re: case insensitive "contains"?

2018-09-10 Thread Laurent Rosenfeld via perl6-users
Hi Todd,

you may use:

say "Yes" if "2018 xJul 7" ~~ /:i jul/;

or:

say "Yes" if "2018 xJul 7" ~~ m:i/jul/;

In the second case, the adverb will apply to the whole pattern. In the
first case, it will start to apply from the point where the adverb is. In
this specific example, those two code samples will be equivalent since the
adverb is at the beginning of the pattern. But it would make a difference
if the adverb is somewhere else within the pattern. For example, this would
fail:

say "Yes" if "2018 xJul 7" ~~ m:i/j :i ul/;

because the ignore case adverb would apply only on the 'ul' characters of
the pattern, but not on the 'j'.

More on adverbs in regexes: https://docs.perl6.org/language/regexes#Adverbs

Cheers,
Laurent.


Le lun. 10 sept. 2018 à 00:00, ToddAndMargo  a
écrit :

> On 09/08/2018 12:23 PM, Laurent Rosenfeld via perl6-users wrote:
> > Using the fc method is certainly a good way to do case insensitive
> > string comparisons, but you may at this point also use a regex with the
> > :i (ignore case) adverb.
> >
> >  > if "2018 xJul 7" ~~ /:i jul/ {say "Yes";}
> > Yes
> >
>
> Hi Laurent,
>
> Thank you!  Another weapon in my tool box!
>
> Question:  this confused me when I first look at it.  I am use to
> the ":x" command being outside the first "/".  For instance
>  s:g/
>
> What are the rules for what goes inside and what goes outside?
>
> Also, do y have a link to what the various ":x" commands are
> that I can use?
>
> I generally prefer to use "contains", "starts-with", and
> "ends-with" when the string is full of trash that regex needs
> to escape.  For example:
>
> if $Line.contains( 'HWiNFO ' & '
> Installer' ) {
>
>
> Many thanks,
> -T
>
>
> --
> ~
> When we ask for advice, we are usually looking for an accomplice.
> --  Charles Varlet de La Grange
> ~
>


Re: case insensitive "contains"?

2018-09-08 Thread Laurent Rosenfeld via perl6-users
Using the fc method is certainly a good way to do case insensitive string
comparisons, but you may at this point also use a regex with the :i (ignore
case) adverb.

> if "2018 xJul 7" ~~ /:i jul/ {say "Yes";}
Yes


Le sam. 8 sept. 2018 à 00:56, ToddAndMargo  a écrit :

> On 09/07/2018 03:49 PM, ToddAndMargo wrote:
> > Hi All,
> >
> > How do I use "contains" without regard to case?
> >
> > $ p6 'if "2018 Jul 7".contains( "jul", 3 ) {say "Yes";}'
> >
> >
> > Many thanks,
> > -T
>
>
> The chat line helped me figure it out:
>
> $ p6 'if "2018 Jul 7".fc.contains( "jul".fc ) {say "Yes";}'
> Yes
>
> $ p6 'if "2018 xJul 7".fc.contains( "jul".fc ) {say "Yes";}'
> Yes
>
> p6 'if "2018 xul 7".fc.contains( "jul".fc ) {say "Yes";}'
> 
>


Re: A grammar to provide substitution

2018-08-29 Thread Laurent Rosenfeld via perl6-users
Surely, Timo, it might happen with some data, but not with the type of data
shown by the OP (where the words to be replaced were all in the form
$(something) and not the replacements. In fact, I suspect that many other
things might go wrong with spurious data.

The point is that my suggestion was just a quick syntactic example on how
to perform substitution using the regex substitution operator, rather than
a grammar.

The OP did not give enough details anyway to be able to design a detailed
solution.

Cheers,
Laurent.

Le mer. 29 août 2018 à 16:22, Timo Paulssen  a écrit :

> There's a problem with your code, if any of the substitutions contains
> something that looks like the placeholder thing, and if it comes later in
> the iteration of the hash keys (which is randomized now) it will substitute
> again. This is very likely not what you want, though.
>
> HTH
>   - Timo
>
> On 28/08/18 20:04, Laurent Rosenfeld via perl6-users wrote:
> > Hi Patrick, > > for note that this codeline: > > my Str $input = "Here
> be a $(placeholder), for $(purpose) purposes."; > > will not compile
> because Perl will try to interpolate $(placeholder) and $(purpose) as
> vairables that have not been declared. > > You need to use non
> interpolating quotes: > > my Str $input = 'Here be a $(placeholder), for
> $(purpose) purposes.'; > > Then, I would probably use simple substitutions,
> as with this example: > > my Str $input = 'Here be a $(placeholder), for
> $(purpose) purposes.'; > > sub format-string ($input, %substitutions) { >
> my $str = $input; > for keys %substitutions -> $key { > $str ~~
> s/$key/%substitutions{$key}/; > } > return $str; > } > my %substitutes =
> '$(placeholder)' => "placeholder", '$(purpose)' => "testing"; > my $output
> = format-string($input, %substitutes); > say $output; > > This is the
> output running this under the REPL: > > > my Str $input = 'Here be a
> $(placeholder), for $(purpose) purposes.'; > Here be a $(placeholder), for
> $(purpose) purposes. > > > > sub format-string ($input, %substitutions) { >
> * my $str = $input; > * for keys %substitutions -> $key { > * $str ~~
> s/$key/%substitutions{$key}/; > * } > * return $str; > * } > sub
> format-string ($input, %substitutions) { #`(Sub|214745424) ... } > > my
> %substitutes = '$(placeholder)' => "placeholder", '$(purpose)' =>
> "testing"; > {$(placeholder) => placeholder, $(purpose) => testing} > > my
> $output = format-string($input, %substitutes); > Here be a placeholder, for
> testing purposes. > > say $output; > Here be a placeholder, for testing
> purposes. > > I hope this helps. > > Cheers, > Laurent. > > > > > Le mar.
> 28 août 2018 à 12:25, Patrick Spek via perl6-users  <mailto:perl6-users@perl.org> > a écrit : >
>
> Hi all,
>
> I'm trying to substitute parts of a string, and thought this might be a
> good use of a grammar. Sadly, grammars aren't my strong suit, so I
> thought I'd ask the wider community for help. Maybe you guys know an
> even better solution than using a grammar here.
>
> So, consider a string, "Here be a $(placeholder), for $(purpose)
> purposes.". I want to be able to put that into a sub, along with some
> Pairs, and get a string with the placeholders replaced back.
>
> my Str $input = "Here be a $(placeholder), for $(purpose) purposes.";
> my Str $output = format-string(
> $input,
> placeholder => "placeholder",
> purpose => "testing",
> );
>
> dd $output; # "Here be a placeholder, for testing purposes."
>
> The `format-string` sub would call the grammar and apply the actual
> substitution, and that's where I need your help. I am not quite sure
> how I would implement the grammar (and presumably it's actions) to do
> what I want.
>
> Thanks in advance for your help!
>
> >
>
>


Re: A grammar to provide substitution

2018-08-28 Thread Laurent Rosenfeld via perl6-users
Hi Patrick,

for note that this codeline:

my Str $input = "Here be a $(placeholder), for $(purpose) purposes.";

will not compile because Perl will try to interpolate $(placeholder) and
$(purpose) as vairables that have not been declared.

You need to use non interpolating quotes:

my Str $input = 'Here be a $(placeholder), for $(purpose) purposes.';

Then, I would probably use simple substitutions, as with this example:

my Str $input = 'Here be a $(placeholder), for $(purpose) purposes.';

sub format-string ($input, %substitutions) {
 my $str = $input;
 for keys %substitutions -> $key {
$str ~~ s/$key/%substitutions{$key}/;
   }
   return $str;
}
my %substitutes = '$(placeholder)' => "placeholder", '$(purpose)' =>
"testing";
my $output = format-string($input, %substitutes);
say $output;

This is the output running this under the REPL:

> my Str $input = 'Here be a $(placeholder), for $(purpose) purposes.';
Here be a $(placeholder), for $(purpose) purposes.
>
> sub format-string ($input, %substitutions) {
*  my $str = $input;
*  for keys %substitutions -> $key {
* $str ~~ s/$key/%substitutions{$key}/;
*}
*return $str;
* }
sub format-string ($input, %substitutions) { #`(Sub|214745424) ... }
> my %substitutes = '$(placeholder)' => "placeholder", '$(purpose)' =>
"testing";
{$(placeholder) => placeholder, $(purpose) => testing}
> my $output = format-string($input, %substitutes);
Here be a placeholder, for testing purposes.
> say $output;
Here be a placeholder, for testing purposes.

I hope this helps.

Cheers,
Laurent.




Le mar. 28 août 2018 à 12:25, Patrick Spek via perl6-users <
perl6-users@perl.org> a écrit :

> -BEGIN PGP SIGNED MESSAGE-
> Hash: SHA256
>
> Hi all,
>
> I'm trying to substitute parts of a string, and thought this might be a
> good use of a grammar. Sadly, grammars aren't my strong suit, so I
> thought I'd ask the wider community for help. Maybe you guys know an
> even better solution than using a grammar here.
>
> So, consider a string, "Here be a $(placeholder), for $(purpose)
> purposes.". I want to be able to put that into a sub, along with some
> Pairs, and get a string with the placeholders replaced back.
>
> my Str $input = "Here be a $(placeholder), for $(purpose) purposes.";
> my Str $output = format-string(
> $input,
> placeholder => "placeholder",
> purpose => "testing",
> );
>
> dd $output; # "Here be a placeholder, for testing purposes."
>
> The `format-string` sub would call the grammar and apply the actual
> substitution, and that's where I need your help. I am not quite sure
> how I would implement the grammar (and presumably it's actions) to do
> what I want.
>
> Thanks in advance for your help!
>
> - --
> With kind regards,
>
> Patrick Spek
>
>
> www:  https://www.tyil.work/
> mail: p.s...@tyil.nl
> pgp:  EB9E A484 1672 2D37 16F5  A799 9ACF E193 FFBC 1F50
>
> mastodon: @tyil@mastodon.social
> github:   @Tyil
> gitlab:   @tyil
>
> -BEGIN PGP SIGNATURE-
>
> iQEzBAEBCAAdFiEE4eL662U9iK2ST2MqN/W6H45XOE8FAluFIw0ACgkQN/W6H45X
> OE+9pAgAry3KwoOS+A5g+y9V0hPHx24nQ6U8TcbZh/HIuvwwbinkCi4oxfhGwTBX
> FXeogYj18OF+K7KEq45fAtB7sqrAelo59elu+ZCXZmiFH1BNHFNWbINkKKWQdHAs
> uYTL7poMwSQ+XQVBTCu3dY32jVl3qasSr4dAM0g6za8TTtgw0TTblF/aNO6A0KC6
> cf757hWxZ7VqprIbpPfvQnB/0BreVu467Va7EGdzZDwi3WfQTg9R0H1NTSkpdS0M
> fyhMJ21rjBhhiUZt+DOHThcd5s7ikk1d1fX5x/hEgRNIcmbQVZ7N3STGSxtqFm6h
> thQ2zhTXGgE/VrTaOHP0a8NiqPamEQ==
> =RlqT
> -END PGP SIGNATURE-
>


Re: Special token names, or my mistake

2018-08-12 Thread Laurent Rosenfeld via perl6-users
Hi Yary,

I'm not sure whether this is really the reason, but sum is the name of a
built-in function (see https://docs.perl6.org/routine/sum). It seems that
the compiler interprets your token as a subroutine call of that builtin.

HTH,
Laurent.


2018-08-12 9:28 GMT+02:00 yary :

> If I call a token "sum", this example gives an error. If I call it
> "something-else", it doesn't. I didn't expect an error in either case.
> What's going on?
>
> ~~ actions-test.p6 ~~
> grammar A {
>   rule TOP {  }
>   token something-else { + % '+' }
>   token int { \d+ }
> }
>
> grammar B {
>   rule TOP {  }
>   token sum { + % '+' }
>   token int { \d+ }
> }
>
> class An-Action {
> }
>
> say A.parse('5',actions => An-Action.new); # OK
> say B.parse('5',actions => An-Action.new); # hopes, dashed
>
> __END__
>
> The B.parse says "Too many positionals passed; expected 1 argument but got
> 2
>   in regex sum at action-test.p6 line 9
>   in regex TOP at action-test.p6 line 8
>   in block  at action-test.p6 line 17"
>
> perl6 -v
> This is Rakudo Star version 2018.06 built on MoarVM version 2018.06
>
>
> -y
>


Re: OT: catch the bash error?

2018-08-04 Thread Laurent Rosenfeld via perl6-users
I'm really not very good at bash scripting (because I would almost always
to such things in Perl), but I guess that the initial $G is an error (there
should not be a $ sigil).


2018-08-04 7:08 GMT+02:00 ToddAndMargo :

> Hi All,
>
> I wanted to do a mass rename of "Apple.*" to "Mac.*" with
> bash and I could not figure out the error.
>
> I eventually did find it and I have to blame Perl for it!
>
> Chuckle.
>
> for F in Apple*; do $G=$(echo $F | sed -e 's/^Apple/Mac/'); mv $F $G; echo
> "$F --> $G"; done
>
> Did you catch the error?  I stared and stared at it for about
> ten minutes.
>
> -T
>
>
>
>
>
>
>
>
>
>
> It is "do G=" not "do $G="
>


Re: need regex help

2018-08-02 Thread Laurent Rosenfeld via perl6-users
Set operations seem to be unsupported on predefined character classes (or
subrules). (Or, if they are supported, I don't know what the right syntax
might be.)

Set operations seem to work properly, though, with escaped character
classes. For example:

perl6 -e 'my $x = "9.0v1"; say so $x ~~ /<[\w] - [\d_]>;/'

or with Unicode properties' short names:

perl6 -e 'my $x = "9.0v1"; say  $x ~~ /<[\w] - :N>/;'
or, to find digits instead of letters:
perl6 -e 'my $x = "9.0v1"; say  $x ~~ /<[\w] - :L>/;'
or this:
perl6 -e 'my $x = "9.0v1"; say  $x ~~ /<[\w] - [:L_]>/;'

But I agree that  using //  is probably better. For example:

perl6 -e 'my $x = "9.0v1"; say  $x ~~ /^+$/;

or possibly:
perl6 -e 'my $x = "9.0v1'; say  $x !~~ /<-[\d]>/;'

Best,
Laurent.

2018-08-02 7:00 GMT+02:00 Brandon Allbery :

> Set operations have to be inside the <>. You want something like:
> /<[alnum-alpha]>/.
>
> That said, this would be the same as //, I think? Please describe
> in words what you intended with that regex. (I suspect /<[alpha]>/ is what
> you really want, based on your earlier statement.)
>
> On Thu, Aug 2, 2018 at 12:57 AM ToddAndMargo 
> wrote:
>
>> Hi All,
>>
>> If there are any letter in the string, I want it to fail
>>
>>
>>
>> $ p6 'my $x="9.0v1"; if $x~~/<+alnum>-[]>/ {say "Y";}'
>> ===SORRY!===
>> Unrecognized regex metacharacter - (must be quoted to match literally)
>> at -e:1
>> --> my $x="9.0v1"; if $x~~/<+alnum>⏏-[]>/ {say "Y";}
>> Unable to parse regex; couldn't find final '/'
>> at -e:1
>> --> my $x="9.0v1"; if $x~~/<+alnum>-⏏[]>/ {say "Y";}
>>
>>
>>
>> What am I doing wrong?
>>
>> Many thanks,
>> -T
>>
>
>
> --
> brandon s allbery kf8nh
> allber...@gmail.com
>


Re: start up delay?

2018-08-01 Thread Laurent Rosenfeld via perl6-users
Yes, I agree, start-up time is sometimes quite long. But sorry, I do not
have a solution.

Best,
Laurent.


2018-08-01 20:14 GMT+02:00 ToddAndMargo :

> Hi All,
>
> Is it just me or does Perl 6 take about three times as long to
> start up as Perl 5?  I do have a very fast machine and it takes
> about seven see for some of my Perl 6 stuff to get past the
> ruminating phase and start running.
>
> Any workaround for this, or is this just growing pains for Perl 6?
>
> Many thanks,
> -T
>


Re: parsing in different modes

2018-08-01 Thread Laurent Rosenfeld via perl6-users
Hi Theo,

You probably cannot use a grammar rule to change a dynamic variable (unless
you include some action code into the rule), I agree, but I think you can
use an action method attached to a rule to do it. I have actually done it
recently in a real $work grammar that I intend to present at The Perl
Conference in Glasgow in two weeks from now. Your use case and mine are
admittedly very different, but it seems to me that they are syntactically
very similar.

As an alternative, you could use an action object with an attribute (a
mutable attribute, *is rw*) for the mode. Basically, you instantiate an
object of the actions class (with the desired attribute set to the proper
initial mode at object creation), and then pass the object instead of the
class to the grammar when calling the *parse* method. It should be easy
then to modify the attribute as needed. This is perhaps slightly cleaner
than using a dynamic variable.

I hope this helps.
Laurent.

2018-08-01 21:21 GMT+02:00 Theo van den Heuvel :

>
> Hi Laurent,
>
> dynamic variables were my first attempt (see original post). The problem
> as I see it,
> but I may well be mistaken, is that I cannot use the grammar rule to
> change the variable, e.g,
> switching it on before and off after handling the item in question, Sum in
> my example, and use that in my action class,
> because these actions take place later.
>
> Best,
> Theo
>
>
> Laurent Rosenfeld schreef op 2018-08-01 20:57:
>
>> Theo,
>>
>> if you define a dynamic variable (with the * twigil, for example
>> $*mode)) in the section of the code right before calling the parse (or
>> equivalent) method, then your actions class should be able to read it
>> and to modify it when needed. Then, it is a matter of defining your
>> action methods to do different things depending on the value of that
>> dynamic variable, and to change that variable value depending on the
>> result of the parsing.
>>
>> Best,
>> Laurent.
>>
>> 2018-08-01 20:29 GMT+02:00 Theo van den Heuvel
>> :
>>
>> Hi Laurent,
>>>
>>> yes I have, but the mode switching is supposed to happen
>>> mid-parsing. I hope to avoid having to interrupt the parse, because
>>> picking up after a subparse is going to be hard.
>>> I was looking for a way to communicate a change of mode with the
>>> action class, but:
>>> a) I don't think there is a way to make the grammar parameter
>>> visible to the action class. At least, I can't think of one.
>>> b) the relation between rule X in the grammar and method X in the
>>> action class is hiding within the engine.
>>> c) loosely formulated grammar and action handling don't seem to
>>> share a timeline.
>>>
>>> Thanks,
>>>
>>> Laurent Rosenfeld schreef op 2018-08-01 19:57:
>>> Hi Theo,
>>>
>>> have you considered using only one grammar but simply calling it
>>> with
>>> two different actions classes as a parameter depending on the mode
>>> you
>>> want to use?
>>>
>>> 2018-08-01 16:41 GMT+02:00 Theo van den Heuvel
>>> :
>>>
>>> Hi Perl6-people,
>>>
>>> I am looking for some inspiration. I am working with a grammar that
>>> I would like to have operate in two different modes.
>>> In both modes the rules are identical, but the methods should behave
>>> differently. There are probably better ways to do this than I can
>>> think of at this point.
>>>
>>> As an illustration (not the actual problem), say we want to proces
>>> arithmetical expressions in two modes: normally we just copy the
>>> input, but within a pair of braces we directly calculate the result.
>>> grammar actions are easy to write per mode, but the combination is
>>> harder.
>>>
>>> In our example we would like to convert "{3 + 5} + {2 -1}" into "8 +
>>> 1". In my original case the grammar is large.
>>>
>>> So far, I have considered the following ideas:
>>> - using a parameter on the grammar rules
>>> - meddling with the AST
>>> - using a dynamic variable (but actions are performed later)
>>> - using the actions method (I don't see how I could use that here)
>>>
>>> One way to get this done is by combining the first two ideas:
>>>
>>> grammar Sum {
>>> token TOP { ^  $ }
>>> rule Sum($p) { + %  **{$p}}
>>> rule Expr {  | '[' ~ ']'  }
>>> token op { <[-+]> }
>>> token num { \d+ }
>>> token flag {  }
>>> }
>>>
>>> The presence of the flag is the clue for the actions.
>>>
>>> This is less than satisfactory because we would have to pass on the
>>> parameter to all non-terminals.
>>>
>>> Can anyone think of a better way to do this?
>>>
>>> thanks,
>>>
>>> --
>>> Theo van den Heuvel
>>>
>>
>> --
>> Theo van den Heuvel
>> Van den Heuvel HLT Consultancy
>>
>
> --
> Theo van den Heuvel
> Van den Heuvel HLT Consultancy
>


Re: parsing in different modes

2018-08-01 Thread Laurent Rosenfeld via perl6-users
Theo,

if you define a dynamic variable (with the * twigil, for example $*mode))
in the section of the code right before calling the parse (or equivalent)
method, then your actions class should be able to read it and to modify it
when needed. Then, it is a matter of defining your action methods to do
different things depending on the value of that dynamic variable, and to
change that variable value depending on the result of the parsing.

Best,
Laurent.

2018-08-01 20:29 GMT+02:00 Theo van den Heuvel :

> Hi Laurent,
>
> yes I have, but the mode switching is supposed to happen mid-parsing. I
> hope to avoid having to interrupt the parse, because picking up after a
> subparse is going to be hard.
> I was looking for a way to communicate a change of mode with the action
> class, but:
> a) I don't think there is a way to make the grammar parameter visible to
> the action class. At least, I can't think of one.
> b) the relation between rule X in the grammar and method X in the action
> class is hiding within the engine.
> c) loosely formulated grammar and action handling don't seem to share a
> timeline.
>
> Thanks,
>
> Laurent Rosenfeld schreef op 2018-08-01 19:57:
>
>> Hi Theo,
>>
>> have you considered using only one grammar but simply calling it with
>> two different actions classes as a parameter depending on the mode you
>> want to use?
>>
>> 2018-08-01 16:41 GMT+02:00 Theo van den Heuvel
>> :
>>
>> Hi Perl6-people,
>>>
>>> I am looking for some inspiration. I am working with a grammar that
>>> I would like to have operate in two different modes.
>>> In both modes the rules are identical, but the methods should behave
>>> differently. There are probably better ways to do this than I can
>>> think of at this point.
>>>
>>> As an illustration (not the actual problem), say we want to proces
>>> arithmetical expressions in two modes: normally we just copy the
>>> input, but within a pair of braces we directly calculate the result.
>>> grammar actions are easy to write per mode, but the combination is
>>> harder.
>>>
>>> In our example we would like to convert "{3 + 5} + {2 -1}" into "8 +
>>> 1". In my original case the grammar is large.
>>>
>>> So far, I have considered the following ideas:
>>> - using a parameter on the grammar rules
>>> - meddling with the AST
>>> - using a dynamic variable (but actions are performed later)
>>> - using the actions method (I don't see how I could use that here)
>>>
>>> One way to get this done is by combining the first two ideas:
>>>
>>> grammar Sum {
>>> token TOP { ^  $ }
>>> rule Sum($p) { + %  **{$p}}
>>> rule Expr {  | '[' ~ ']'  }
>>> token op { <[-+]> }
>>> token num { \d+ }
>>> token flag {  }
>>> }
>>>
>>> The presence of the flag is the clue for the actions.
>>>
>>> This is less than satisfactory because we would have to pass on the
>>> parameter to all non-terminals.
>>>
>>> Can anyone think of a better way to do this?
>>>
>>> thanks,
>>>
>>> --
>>> Theo van den Heuvel
>>>
>>
> --
> Theo van den Heuvel
> Van den Heuvel HLT Consultancy
>


Re: parsing in different modes

2018-08-01 Thread Laurent Rosenfeld via perl6-users
Hi Theo,

have you considered using only one grammar but simply calling it with two
different actions classes as a parameter depending on the mode you want to
use?



2018-08-01 16:41 GMT+02:00 Theo van den Heuvel :

>
>
> Hi Perl6-people,
>
> I am looking for some inspiration. I am working with a grammar that I
> would like to have operate in two different modes.
> In both modes the rules are identical, but the methods should behave
> differently. There are probably better ways to do this than I can think of
> at this point.
>
> As an illustration (not the actual problem), say we want to proces
> arithmetical expressions in two modes: normally we just copy the input, but
> within a pair of braces we directly calculate the result. grammar actions
> are easy to write per mode, but the combination is harder.
>
> In our example we would like to convert "{3 + 5} + {2 -1}" into "8 + 1".
> In my original case the grammar is large.
>
> So far, I have considered the following ideas:
> - using a parameter on the grammar rules
> - meddling with the AST
> - using a dynamic variable (but actions are performed later)
> - using the actions method (I don't see how I could use that here)
>
> One way to get this done is by combining the first two ideas:
>
> grammar Sum {
>   token TOP { ^  $ }
>   rule Sum($p) { + %  **{$p}}
>   rule Expr {  | '[' ~ ']'  }
>   token op { <[-+]> }
>   token num { \d+ }
>   token flag {  }
> }
>
> The presence of the flag is the clue for the actions.
>
> This is less than satisfactory because we would have to pass on the
> parameter to all non-terminals.
>
> Can anyone think of a better way to do this?
>
> thanks,
>
> --
> Theo van den Heuvel
>


Re: What does ^parents really tell you?

2018-07-29 Thread Laurent Rosenfeld via perl6-users
Hi,

Try this:


my $stringy = "abc";
say  $stringy.^parents(:all);

This should display:

((Cool) (Any) (Mu))

Cheers,
Laurent.

2018-07-29 19:27 GMT+02:00 Joseph Brenner :

> If you look at the type diagram:
>
>   https://docs.perl6.org/type/Str#___top
>
> You can see that:
>Str is Cool is Any is Mu
>
> But if you use the ^parents method on a string, you don't get
> "Cool", instead you get "()":
>
>my $stringy = "abc";
>say $stringy.^name;  # Str
>say $stringy.^parents;   # ()
>
>say (Str).^parents;  # ()
>
> So what exactly does ^parents tell you about?
> Is there some other method you could use to trace the chain
> of ancestors upwards?
>


Re: MAIN subroutine

2018-07-19 Thread Laurent Rosenfeld via perl6-users
Thanks Brandon for your answer. Yes, I agree that it makes sense that
declarations (and initializations) outside any sub should run before the
MAIN sub.

And I agree that we should probably avoid  combining a MAIN sub with
non-declaring code. (And, as I said, I've never hit the case before because
I would normally not do that: to me, if I have a MAIN sub, any executable
code should be in MAIN or in subs called (directly or indirectly) from MAIN.

But then, perhaps the documentation should be clearer on that.

And many thanks for the others who answered meanwhile.

Best,
Laurent.

2018-07-19 23:48 GMT+02:00 Brandon Allbery :

> Consider that "declarations" are actually executable code. They have
> compile-time meaning, but many also have runtime meaning. This is most
> obvious when it's a variable with an initializer: the initialization is at
> runtime, not compile time. Which means MAIN has to run after all such, or
> variables won't be initialized properly.
>
> Most commonly you would not combine a MAIN sub with non-declaring code.
>
> On Thu, Jul 19, 2018 at 5:32 PM Laurent Rosenfeld via perl6-users <
> perl6-users@perl.org> wrote:
>
>> Hi folks,
>>
>> The documentation for the MAIN sub says that "the sub with the special
>> name MAIN is executed after all relevant phasers."
>>
>> My understanding is that MAIN automatically executes before any code
>> other than phasers happening at compile time or at the end or right after
>> the end of compilation. It seems that this is not the case. It seems that
>> my perception is wrong and that code not belonging to any sub is executed
>> before MAIN.
>>
>> For example, take this code:
>>
>> sub execute_after_main(Str $string) {
>> say "this $string after MAIN?";
>> }
>> execute_after_main("1");
>>
>> sub MAIN() {
>> say "This is MAIN so this should print first";
>> }
>> execute_after_main("2");
>>
>> This prints the following:
>>
>> this 1 after MAIN?
>> this 2 after MAIN?
>> This is MAIN so this should print first
>>
>> I was expecting the MAIN message to be printed first.
>>
>> Did I miss something? Is my understanding wrong? I'd never seen that, but
>> I guess all my scripts using MAIN had all the code in subs called from
>> MAIN. So maybe I've never hit that case.
>>
>> Cheers,
>> Laurent.
>>
>
>
> --
> brandon s allbery kf8nh   sine nomine
> associates
> allber...@gmail.com
> ballb...@sinenomine.net
> unix, openafs, kerberos, infrastructure, xmonad
> http://sinenomine.net
>


MAIN subroutine

2018-07-19 Thread Laurent Rosenfeld via perl6-users
Hi folks,

The documentation for the MAIN sub says that "the sub with the special name
MAIN is executed after all relevant phasers."

My understanding is that MAIN automatically executes before any code other
than phasers happening at compile time or at the end or right after the end
of compilation. It seems that this is not the case. It seems that my
perception is wrong and that code not belonging to any sub is executed
before MAIN.

For example, take this code:

sub execute_after_main(Str $string) {
say "this $string after MAIN?";
}
execute_after_main("1");

sub MAIN() {
say "This is MAIN so this should print first";
}
execute_after_main("2");

This prints the following:

this 1 after MAIN?
this 2 after MAIN?
This is MAIN so this should print first

I was expecting the MAIN message to be printed first.

Did I miss something? Is my understanding wrong? I'd never seen that, but I
guess all my scripts using MAIN had all the code in subs called from MAIN.
So maybe I've never hit that case.

Cheers,
Laurent.