Re: more match humility

2017-03-13 Thread ToddAndMargo
On 03/13/2017 10:20 PM, Brandon Allbery wrote: Just to be a little more clear about what is happening here: Perl 5 tended to treat things as strings if you use them as strings, or as numbers if you use them as numbers. Perl 6 is more strict about that, but makes an exception for specifically

Re: more match humility

2017-03-13 Thread Brandon Allbery
Just to be a little more clear about what is happening here: Perl 5 tended to treat things as strings if you use them as strings, or as numbers if you use them as numbers. Perl 6 is more strict about that, but makes an exception for specifically numbers and strings; if you have noticed the class

Re: more match humility

2017-03-13 Thread ToddAndMargo
On 03/13/2017 09:16 PM, ToddAndMargo wrote: What am I doing wrong now !?!?! :'( :'( :'( #!/usr/bin/perl6 sub Test () { my $f = $?FILE; say "\$\?FILE=<$f>"; my $g = $?FILE.IO.basename; say "\$\?FILE.IO.basename=<$g>"; ( my $IAm = $?FILE ) ~~ s|.*"/"||; say "Regex \$IAm=<$IAm>";

more match humility

2017-03-13 Thread ToddAndMargo
What am I doing wrong now !?!?! :'( :'( :'( #!/usr/bin/perl6 sub Test () { my $f = $?FILE; say "\$\?FILE=<$f>"; my $g = $?FILE.IO.basename; say "\$\?FILE.IO.basename=<$g>"; ( my $IAm = $?FILE ) ~~ s|.*"/"||; say "Regex \$IAm=<$IAm>"; # sub Test () { #`(Sub|58588296) ... }

Re: Need help with a match

2017-03-13 Thread Richard Hainsworth
Seems to me because the second '(' is not preceded by a space; it is '`('. But if the second '(' was eg '` (', then the longest match would have been picked and a ? would be necessary. On Tuesday, March 14, 2017 11:21 AM, ToddAndMargo wrote: On 03/13/2017 08:16 PM, ToddAndMargo wrote: On

Re: Need help with a match

2017-03-13 Thread ToddAndMargo
On 03/13/2017 08:16 PM, ToddAndMargo wrote: On 03/13/2017 07:53 PM, yary wrote: I think p6 regexes behave a bit like p5 regexes with the "x" flag turned on, where whitespace can be added in for readability. To have literal whitespace, put quotes around it. Like this (untested) $x ~~ m/sub ' '

Re: Need help with a match

2017-03-13 Thread ToddAndMargo
On 03/13/2017 07:53 PM, yary wrote: I think p6 regexes behave a bit like p5 regexes with the "x" flag turned on, where whitespace can be added in for readability. To have literal whitespace, put quotes around it. Like this (untested) $x ~~ m/sub ' ' (.*) ' ' \(/; Now that was way to easy

Re: Need help with a match

2017-03-13 Thread ToddAndMargo
On 03/13/2017 07:58 PM, Brandon Allbery wrote: There is actually a third issue in that spaces are *ignored* in regexes, so you actually end up with $/[0] eq ' Test'. Use the <.ws> rule to avoid this. (The leading dot prevents that whitespace from additionally being captured as $/ which here

Re: Need help with a match

2017-03-13 Thread Brandon Allbery
There is actually a third issue in that spaces are *ignored* in regexes, so you actually end up with $/[0] eq ' Test'. Use the <.ws> rule to avoid this. (The leading dot prevents that whitespace from additionally being captured as $/ which here would be pointless. You might also want one before

Re: Need help with a match

2017-03-13 Thread yary
I think p6 regexes behave a bit like p5 regexes with the "x" flag turned on, where whitespace can be added in for readability. To have literal whitespace, put quotes around it. Like this (untested) $x ~~ m/sub ' ' (.*) ' ' \(/;

Re: Need help with a match

2017-03-13 Thread Brandon Allbery
You have two problems: (1) matches start from 0, not 1. (2) .* gobbles as much as possible (this is also true in Perl 5) so it matches to the ) at the end of (Sub|63218616). As in Perl 5, you add a ? to make it take the shortest match instead: #!/usr/bin/perl6 my $x='sub Test () {

Need help with a match

2017-03-13 Thread ToddAndMargo
Hi All, Just as soon as I think I understand it, a little humility fall into my lap! #!/usr/bin/perl6 my $x='sub Test () { #`(Sub|63218616) ... }'; $x ~~ m/sub (.*) \(/; say "$x\n$1"; $ WhoTest2.pl6 Use of Nil in string context in block at ./WhoTest2.pl6 line 4 sub Test () {

Re: What to do when a pattern match fails

2017-03-13 Thread ToddAndMargo
On 03/13/2017 04:12 PM, ToddAndMargo wrote: On 03/13/2017 02:06 PM, ToddAndMargo wrote: Hi All, $ perl6 -e 'my $x="ab12cd"; $x ~~ m/ab(1q2)cd/; say "$x\n\$0=<$0>\n";' Use of Nil in string context in block at -e line 1 ab12cd $0=<> With out the "q" in this, it works. I deliberately put the

Re: What to do when a pattern match fails

2017-03-13 Thread ToddAndMargo
On 03/13/2017 02:06 PM, ToddAndMargo wrote: Hi All, $ perl6 -e 'my $x="ab12cd"; $x ~~ m/ab(1q2)cd/; say "$x\n\$0=<$0>\n";' Use of Nil in string context in block at -e line 1 ab12cd $0=<> With out the "q" in this, it works. I deliberately put the "q" to see what would happen when a patter was

Re: What to do when a pattern match fails

2017-03-13 Thread ToddAndMargo
On 03/13/2017 04:03 PM, yary wrote: On Mon, Mar 13, 2017 at 6:16 PM, ToddAndMargo > wrote: So if it only catches some of them, it will still return false? There is no catching some of them- either the pattern matches and all are

Re: What to do when a pattern match fails

2017-03-13 Thread yary
On Mon, Mar 13, 2017 at 6:16 PM, ToddAndMargo wrote: > So if it only catches some of them, it will still return false? There is no catching some of them- either the pattern matches and all are caught, or the pattern fails and none are caught. If you can show us an

Re: Fwd: Re: Variables in modules

2017-03-13 Thread ToddAndMargo
On March 10, 2017 10:32:43 PM Theo van den Heuvel wrote: Not with me it doesn't. my $TheValue = $?FILE.subst(/.* "/"/, "", :g); sub sayfn is export { $TheValue.say } Could something else be wrong here? cheers, Theo ToddAndMargo schreef op 2017-03-10 22:10: On

Re: What to do when a pattern match fails

2017-03-13 Thread ToddAndMargo
On 03/13/2017 02:28 PM, Elizabeth Mattijsen wrote: On 13 Mar 2017, at 22:20, ToddAndMargo wrote: On 03/13/2017 02:11 PM, Elizabeth Mattijsen wrote: On 13 Mar 2017, at 22:06, ToddAndMargo wrote: Hi All, $ perl6 -e 'my $x="ab12cd"; $x ~~

Re: What to do when a pattern match fails

2017-03-13 Thread Elizabeth Mattijsen
> On 13 Mar 2017, at 22:20, ToddAndMargo wrote: > > On 03/13/2017 02:11 PM, Elizabeth Mattijsen wrote: >> >>> On 13 Mar 2017, at 22:06, ToddAndMargo wrote: >>> >>> Hi All, >>> >>> $ perl6 -e 'my $x="ab12cd"; $x ~~ m/ab(1q2)cd/; say

Re: What to do when a pattern match fails

2017-03-13 Thread ToddAndMargo
On 03/13/2017 02:11 PM, Elizabeth Mattijsen wrote: On 13 Mar 2017, at 22:06, ToddAndMargo wrote: Hi All, $ perl6 -e 'my $x="ab12cd"; $x ~~ m/ab(1q2)cd/; say "$x\n\$0=<$0>\n";' Use of Nil in string context in block at -e line 1 ab12cd $0=<> With out the "q" in this,

preassigned names in pattern matches?

2017-03-13 Thread ToddAndMargo
Hi All, I adore this feature of loops: perl6 -e 'my @x=qw[a b z y]; for @x -> $a, $b { say "<$a> <$b>" };' because I can preassign a names to "$_". Question: in a pattern match such as: perl6 -e 'my $x="ab12cd"; $x ~~ m/(ab)(12)(cd)/; say

Re: What to do when a pattern match fails

2017-03-13 Thread Elizabeth Mattijsen
> On 13 Mar 2017, at 22:06, ToddAndMargo wrote: > > Hi All, > > $ perl6 -e 'my $x="ab12cd"; $x ~~ m/ab(1q2)cd/; say "$x\n\$0=<$0>\n";' > Use of Nil in string context in block at -e line 1 > ab12cd > $0=<> > > With out the "q" in this, it works. I deliberately put >

What to do when a pattern match fails

2017-03-13 Thread ToddAndMargo
Hi All, $ perl6 -e 'my $x="ab12cd"; $x ~~ m/ab(1q2)cd/; say "$x\n\$0=<$0>\n";' Use of Nil in string context in block at -e line 1 ab12cd $0=<> With out the "q" in this, it works. I deliberately put the "q" to see what would happen when a patter was not found. Is there a way around the "use

Re: Perl 5 list assignment idiom

2017-03-13 Thread Brock Wilcox
The == operator coerces to Numeric, so like: > sub one-thing { return ("hi",) } sub one-thing () { #`(Sub|93867233982256) ... } > one-thing.Numeric 1 (mentioned in https://docs.perl6.org/routine/$EQUALS_SIGN$EQUALS_SIGN) I think my does indeed do some fancy precidenting with the assignment.

Re: Perl 5 list assignment idiom

2017-03-13 Thread Sean McAfee
On Mon, Mar 13, 2017 at 12:37 PM, Will Coleda wrote: > Works the same in Perl 6, and you can avoid the parens. Using helper > subs that return one or two item lists, here's some sample code: > > $ perl6 > > sub one-thing { return ("hi",) } > sub one-thing () {

Re: Perl 5 list assignment idiom

2017-03-13 Thread Will Coleda
Works the same in Perl 6, and you can avoid the parens. Using helper subs that return one or two item lists, here's some sample code: $ perl6 > sub one-thing { return ("hi",) } sub one-thing () { #`(Sub|140454852043936) ... } > 1 == my $script = one-thing True > $script (hi) > sub two-things {

Perl 5 list assignment idiom

2017-03-13 Thread Sean McAfee
In Perl 5, list assignment in scalar context evaluates to the number of list elements on the right-hand side. That enables an idiom that I rather like: 1 == (my ($script) = $page->find('//script')) or die "Other than exactly one script element found"; Can a similar expression that

Re: lazy gather?

2017-03-13 Thread Siavash
Hi, 「gather」 should work. What version of Perl 6 are you using? (run perl6 -v) I may be wrong, but I think the code should be: my \golden= (1 + sqrt 5) ÷ 2; my \fib = 1, 1, * + * ... ∞ ; my \approx= gather for fib.rotor(2 => -1) { take .[1] ÷ .[0] }; my \distances = approx.map:

Re: lazy gather?

2017-03-13 Thread Theo van den Heuvel
Hi, I think you mean: my \golden= ( 1 + sqrt 5 ) / 2; best, Theo Marc Chantreux schreef op 2017-03-13 14:28: hello, i saw a math show with my son and we tried to use perl6 * to demonstrate the fact that the ratio between the terms n and n-1 in the fibonnaci sequence gets closer to the

lazy gather?

2017-03-13 Thread Marc Chantreux
hello, i saw a math show with my son and we tried to use perl6 * to demonstrate the fact that the ratio between the terms n and n-1 in the fibonnaci sequence gets closer to the golden number * let him know how awesome is perl6 so i wrote my \golden= ( 1 / sqrt 5 ) / 2; my \fib = (

Re: I need help with pattern matching

2017-03-13 Thread Andreas Mueller
$ perl6 -e 'my $x="abc(123)def"; say $x ~~ m/(abc)(\(123\))(def)/;' -am On 13.03.17 00:27, ToddAndMargo wrote: > Hi All, > > What am I doing wrong here? > > $ perl6 -e 'my $x="abc\(123\)def"; $x ~~ m/(abc\))(123)(\(def)/; say > "$x\n\$0=<$0> \$1=<$1> \$2=<$2>\n";' > > Use of Nil in string

Re: Fwd: Re: Variables in modules

2017-03-13 Thread JuhiMarcel LangbroekTimmerman
now we are at it, for readability perhaps instead of substitutes do, my $thevalue = $?FILE.IO.basename; Marcel On March 10, 2017 10:32:43 PM Theo van den Heuvel wrote: Not with me it doesn't. my $TheValue = $?FILE.subst(/.* "/"/, "", :g); sub sayfn is export {

Re: I need help with pattern matching

2017-03-13 Thread Elizabeth Mattijsen
> On 13 Mar 2017, at 08:27, ToddAndMargo wrote: > > Hi All, > > What am I doing wrong here? > > $ perl6 -e 'my $x="abc\(123\)def"; $x ~~ m/(abc\))(123)(\(def)/; say > "$x\n\$0=<$0> \$1=<$1> \$2=<$2>\n";' > > Use of Nil in string context > in block at -e line 1 >

I need help with pattern matching

2017-03-13 Thread ToddAndMargo
Hi All, What am I doing wrong here? $ perl6 -e 'my $x="abc\(123\)def"; $x ~~ m/(abc\))(123)(\(def)/; say "$x\n\$0=<$0> \$1=<$1> \$2=<$2>\n";' Use of Nil in string context in block at -e line 1 Use of Nil in string context in block at -e line 1 Use of Nil in string context in block