Re: odd and even

2018-04-30 Thread JJ Merelo
Check out the docs.perl6.org page... And no, we don't.

El lun., 30 abr. 2018 a las 8:48, ToddAndMargo ()
escribió:

> Hi All,
>
> I know it would only take me 25 seconds to write one,
> but do we have an odd and even function build in?
>
>
> Many thanks,
> -T
>
> $ perl6 -e 'my $x=3; say $x.odd;'
> No such method 'odd' for invocant of type 'Int'. Did you mean 'ord'?
>in block  at -e line 1
>
> $ perl6 -e 'my $x=3; say $x.even;'
> No such method 'even' for invocant of type 'Int'
>in block  at -e line 1
>


-- 
JJ


Re: odd and even

2018-04-30 Thread ToddAndMargo

On 04/30/2018 12:04 AM, JJ Merelo wrote:
Check out the docs.perl6.org  page... And no, we 
don't.


Love the docs.  Not always really helpful though.


Re: odd and even

2018-04-30 Thread JJ Merelo
When they are not, please raise an issue. We'll try to solve it ASAP.

El lun., 30 abr. 2018 a las 9:46, ToddAndMargo ()
escribió:

> On 04/30/2018 12:04 AM, JJ Merelo wrote:
> > Check out the docs.perl6.org  page... And no, we
> > don't.
>
> Love the docs.  Not always really helpful though.
>


-- 
JJ


inheritance and default attributes

2018-04-30 Thread Theo van den Heuvel

Hi all,

trying to make sense of the following excerpt from the documentation on 
object construction:


 Due to the default behavior of BUILDALL and BUILD submethods, named 
arguments to the constructor new derived from Mu
 can correspond directly to public attributes of any of the classes in 
the method resolution order, or to any named

 parameter of any BUILD submethod.


I would like to build a class A and subclasses AB and more such that AB 
and friends differ in the default attribute values. On the basis of the 
docs I expected this to work:


#
class A {
  has Int $.a;
  method sayit() { say $!a }
}

class AB is A {
  submethod BUILD(:$!a = 17){}
}


my $ab = AB.new().sayit;
#

however. I get "Attribute $!a not declared in class AB", which makes 
sense.

How should I write this instead?

Thanks


--
Theo van den Heuvel
Van den Heuvel HLT Consultancy


Re: inheritance and default attributes

2018-04-30 Thread Elizabeth Mattijsen
> On 30 Apr 2018, at 10:55, Theo van den Heuvel  wrote:
> 
> Hi all,
> 
> trying to make sense of the following excerpt from the documentation on 
> object construction:
> 
> Due to the default behavior of BUILDALL and BUILD submethods, named arguments 
> to the constructor new derived from Mu
> can correspond directly to public attributes of any of the classes in the 
> method resolution order, or to any named
> parameter of any BUILD submethod.
> 
> 
> I would like to build a class A and subclasses AB and more such that AB and 
> friends differ in the default attribute values. On the basis of the docs I 
> expected this to work:
> 
> #
> class A {
> has Int $.a;
> method sayit() { say $!a }
> }
> 
> class AB is A {
> submethod BUILD(:$!a = 17){}
> }
> 
> 
> my $ab = AB.new().sayit;
> #
> 
> however. I get "Attribute $!a not declared in class AB", which makes sense.
> How should I write this instead?

Perhaps a recent answer by Jonathan Worthington to a similar question on 
StackOverflow can be of help here:

 
https://stackoverflow.com/questions/50031400/inheriting-private-attributes-in-perl-6


Liz

Re: odd and even

2018-04-30 Thread ToddAndMargo


El lun., 30 abr. 2018 a las 9:46, ToddAndMargo (>) escribió:


On 04/30/2018 12:04 AM, JJ Merelo wrote:
 > Check out the docs.perl6.org 
 page... And no, we
 > don't.

Love the docs.  Not always really helpful though.


On 04/30/2018 01:10 AM, JJ Merelo wrote:
> When they are not, please raise an issue. We'll try to solve it ASAP.
>

Hi JJ,

It is mainly the way the functions are written up.  They give theory
and then a few bad examples.

For instance:
https://docs.perl6.org/routine/split

multi subsplit(  Str:D $delimiter, Str(Cool) $input, $limit = 
Inf, :$k, :$v, :$kv, :$p, :$skip-empty)


which is theory and means absolutely nothing to me.
Please don't try to explain it either.  I won't remember
ten minutes after you tell me.  Maybe if I have been writing
for five years in Perl, it would be different.

And for the examples:

say split(/<[;,]>/, "a;b;c,d").perl;

Without an explanation, it means, again, nothing.  What
the heck is ".perl" and what in the world is "/<[;,]>/?
Again, please do not try to explain.

And real fun search for "perl" in the docs.
You only get about 325,732 hots.  (This is why
I asked about odd and even.)

So, the main issue I have with the docs is that they
"seem" to be written as a refresher for an advanced use
and not as a trainer for a newbie.

What I have been doing is 1) do the the docs, 2) write
up a `perl -e` to see if I can get it to work, 3) if not,
get on the chat line, give the url I looked at and my
one liner.  After I get it all figured out, I write myself
a keeper explaining how it works.

Just an aside, the guys on the chat line are "extraordinary"
fellows.

-T

p.s. I have reported bugs in the docs before.


Re: inheritance and default attributes

2018-04-30 Thread JJ Merelo
El lun., 30 abr. 2018 a las 11:08, Elizabeth Mattijsen ()
escribió:

> > On 30 Apr 2018, at 10:55, Theo van den Heuvel 
> wrote:
> >
> > Hi all,
> >
> > trying to make sense of the following excerpt from the documentation on
> object construction:
> >
> > Due to the default behavior of BUILDALL and BUILD submethods, named
> arguments to the constructor new derived from Mu
> > can correspond directly to public attributes of any of the classes in
> the method resolution order, or to any named
> > parameter of any BUILD submethod.
> >
> >
> > I would like to build a class A and subclasses AB and more such that AB
> and friends differ in the default attribute values. On the basis of the
> docs I expected this to work:
> >
> > #
> > class A {
> > has Int $.a;
> > method sayit() { say $!a }
> > }
> >
> > class AB is A {
> > submethod BUILD(:$!a = 17){}
> > }
> >
> >
> > my $ab = AB.new().sayit;
> > #
> >
> > however. I get "Attribute $!a not declared in class AB", which makes
> sense.
> > How should I write this instead?
>
> Perhaps a recent answer by Jonathan Worthington to a similar question on
> StackOverflow can be of help here:
>
>
> https://stackoverflow.com/questions/50031400/inheriting-private-attributes-in-perl-6
>
>
And this is why I always encourage people to post questions to
StackOverflow. Or also to StackOverflow :-)

JJ


Re: inheritance and default attributes

2018-04-30 Thread Theo van den Heuvel

Thanks Elibeth and JJMerelo,

stupid mistake. I use stack overflow all the time.
Thanks,

Theo



https://stackoverflow.com/questions/50031400/inheriting-private-attributes-in-perl-6

And this is why I always encourage people to post questions to
StackOverflow. Or also to StackOverflow :-)

JJ


--
Theo van den Heuvel
Van den Heuvel HLT Consultancy


Re: odd and even

2018-04-30 Thread Martin Barth

Are you aware of the %% operator?

$var %% 2 checks wether it is dividable by 2.


Am 30.04.2018 um 08:47 schrieb ToddAndMargo:

Hi All,

I know it would only take me 25 seconds to write one,
but do we have an odd and even function build in?


Many thanks,
-T

$ perl6 -e 'my $x=3; say $x.odd;'
No such method 'odd' for invocant of type 'Int'. Did you mean 'ord'?
  in block  at -e line 1

$ perl6 -e 'my $x=3; say $x.even;'
No such method 'even' for invocant of type 'Int'
  in block  at -e line 1


Re: odd and even

2018-04-30 Thread ToddAndMargo



Am 30.04.2018 um 08:47 schrieb ToddAndMargo:

Hi All,

I know it would only take me 25 seconds to write one,
but do we have an odd and even function build in?


Many thanks,
-T

$ perl6 -e 'my $x=3; say $x.odd;'
No such method 'odd' for invocant of type 'Int'. Did you mean 'ord'?
  in block  at -e line 1

$ perl6 -e 'my $x=3; say $x.even;'
No such method 'even' for invocant of type 'Int'
  in block  at -e line 1


On 04/30/2018 02:05 AM, Martin Barth wrote:
> Are you aware of the %% operator?
>
> $var %% 2 checks wether it is dividable by 2.
>
>

No I was not.  Thank you!

I was just going to do a

 sub  odd( $Num ) { return $Num % 2; }
 sub even( $Num ) { return not $Num.odd; }

-T
--
~~
Computers are like air conditioners.
They malfunction when you open windows
~~


Re: nil mystery

2018-04-30 Thread ToddAndMargo



On Sun, Apr 29, 2018 at 10:20:48PM -0700, ToddAndMargo wrote:

On 04/29/2018 10:12 PM, ToddAndMargo wrote:

On 04/29/2018 09:32 PM, Andrew Kirkpatrick wrote:

There is not enough context to answer or even reproduce the problem -
how are the variables declared and what values do they have just prior
to this line?


Some simpler examples:

$ perl6 -e 'my $x="abcde"; say $x;'
abcde

$ perl6 -e 'my $x="abcde"; my $y="$x" ~ ""; say $y;'
abcde

$ perl6 -e 'my $x="abcde"; my $y="$x"; say $y;'
Type Str does not support associative indexing.
in block  at -e line 1

$ perl6 -e 'my $x="abcde"; my $y="{$x}"; say $y;'
abcde

$ perl6 -e 'my $x="abcde"; my $y="$x\"; say $y;'
abcde


So when is "<" and ">" a letter and when is it a redirect?





On 04/30/2018 12:09 AM, Patrick Spek wrote:
> It seems like in the one case it throws an error, it's because `<>` 
are being
> used to index a hash. Or at least tried to. In Perl 6, you can access 
a Hash's

> elements using `%foo`, which will access the index `bar` on the Hash
> `%foo`.
>
> The other cases are explicitly not referring to a variable, or have 
delimiters
> in place to make it known to the compiler that you're not trying to 
access a

> Hash index.
>
> The error you're getting is "Type Str does not support associative 
indexing.",
> which is correct, though perhaps a little unexpected for you. `$x` 
contains a
> Str, not a Hash, but the `` still try to retrieve the index `br` 
from it.
> The solution is to use any of the other options you're using, with my 
personal

> preference going out to `{$x}`.
>


Hi Patrick,

Now it makes sense.  It was trying to resolve a hash.

Thank you!

-T

--
~~
Computers are like air conditioners.
They malfunction when you open windows
~~


Re: odd and even

2018-04-30 Thread Elizabeth Mattijsen

> On 30 Apr 2018, at 12:43, ToddAndMargo  wrote:
> 
> 
>> Am 30.04.2018 um 08:47 schrieb ToddAndMargo:
>>> Hi All,
>>> 
>>> I know it would only take me 25 seconds to write one,
>>> but do we have an odd and even function build in?
>>> 
>>> 
>>> Many thanks,
>>> -T
>>> 
>>> $ perl6 -e 'my $x=3; say $x.odd;'
>>> No such method 'odd' for invocant of type 'Int'. Did you mean 'ord'?
>>>   in block  at -e line 1
>>> 
>>> $ perl6 -e 'my $x=3; say $x.even;'
>>> No such method 'even' for invocant of type 'Int'
>>>   in block  at -e line 1
> 
> On 04/30/2018 02:05 AM, Martin Barth wrote:
> > Are you aware of the %% operator?
> >
> > $var %% 2 checks wether it is dividable by 2.
> >
> >
> 
> No I was not.  Thank you!
> 
> I was just going to do a
> 
> sub  odd( $Num ) { return $Num % 2; }
> sub even( $Num ) { return not $Num.odd; }

If you create this sub to do value checking, then maybe this approach is better 
for you:

subset EvenInt of Int where * %% 2;  # all the even Ints
subset OddInt of Int where * !%% 2;  # all the odd Ints

# works
my EvenInt $x = 42;

# dies with: Type check failed in assignment to $y; expected EvenInt but 
got Int (42)
my OddInt  $y = 42;




Liz

.sub confusion

2018-04-30 Thread ToddAndMargo

Hi All,

I am confused.

With this sub:

sub odd( $Num ) { return $Num % 2; }


Why does this work:

 if odd $LineNum
  { $PartsStr ~= ''; }  # Green
else  { $PartsStr ~= ''; }  # Purple

And this one throw an error:

 if $LineNum.odd
  { $PartsStr ~= ''; }  # Green
else  { $PartsStr ~= ''; }  # PurpleNo

   No such method 'odd' for invocant of type 'Int'. Did
   you mean 'ord'?

What is my misunderstanding?


Many thanks,
-T


Re: odd and even

2018-04-30 Thread ToddAndMargo

On 04/30/2018 05:44 AM, Elizabeth Mattijsen wrote:



On 30 Apr 2018, at 12:43, ToddAndMargo  wrote:



Am 30.04.2018 um 08:47 schrieb ToddAndMargo:

Hi All,

I know it would only take me 25 seconds to write one,
but do we have an odd and even function build in?


Many thanks,
-T

$ perl6 -e 'my $x=3; say $x.odd;'
No such method 'odd' for invocant of type 'Int'. Did you mean 'ord'?
   in block  at -e line 1

$ perl6 -e 'my $x=3; say $x.even;'
No such method 'even' for invocant of type 'Int'
   in block  at -e line 1


On 04/30/2018 02:05 AM, Martin Barth wrote:

Are you aware of the %% operator?

$var %% 2 checks wether it is dividable by 2.




No I was not.  Thank you!

I was just going to do a

 sub  odd( $Num ) { return $Num % 2; }
 sub even( $Num ) { return not $Num.odd; }


If you create this sub to do value checking, then maybe this approach is better 
for you:

 subset EvenInt of Int where * %% 2;  # all the even Ints
 subset OddInt of Int where * !%% 2;  # all the odd Ints

 # works
 my EvenInt $x = 42;

 # dies with: Type check failed in assignment to $y; expected EvenInt but 
got Int (42)
 my OddInt  $y = 42;




Liz



I don't get it.  Why would I want to do this?   I only want to know if
an integer is odd or even.  What am I missing?

For example, I just coded this:

sub odd( $Num ) { return $Num % 2; }

for split( "\n", $ClipStr ).kv -> $LineNum, $Line {
if odd $LineNum
   { $PartsStr ~= ''; }  # Green
 else  { $PartsStr ~= ''; }  # Purple
...
}

It allows me to alternate the color for odd and even lines.

Please remember that I have about 1/100 of your skill when you
explain things to me.  (For instance, I have no clue what
`subset` is or how to use it.)

-T


Re: .sub confusion

2018-04-30 Thread Elizabeth Mattijsen
> On 30 Apr 2018, at 15:04, ToddAndMargo  wrote:
> 
> Hi All,
> 
> I am confused.
> 
> With this sub:
> 
>sub odd( $Num ) { return $Num % 2; }
> 
> 
> Why does this work:
> 
> if odd $LineNum
>  { $PartsStr ~= ''; }  # Green
>else  { $PartsStr ~= ''; }  # Purple
> 
> And this one throw an error:
> 
> if $LineNum.odd
>  { $PartsStr ~= ''; }  # Green
>else  { $PartsStr ~= ''; }  # PurpleNo
> 
>   No such method 'odd' for invocant of type 'Int'. Did
>   you mean 'ord'?
> 
> What is my misunderstanding?

I think you’re confusing Perl 5 with Perl 6.  In Perl 5, a method is just a sub 
that happens to accept the object as the first parameter.

Although this is also true on a much lower level in Perl 6, at this level this 
is *not* true.

So, this is *not* a compilation error:

class Foo {
sub bar {}
method bar {}
}

So the error is correct: there *is* not method “odd” in the class Int.  There’s 
only a sub called “odd” in your package.

Now, if you wanted to, you *could* mix in a “odd” method into an Int, but that 
is cumbersome because it needs to be done to each value you want to work with.

You can also use the subset approach for ad-hoc type checking:

subset Even of Int where * %% 2;
say 42 ~~ Even; # True
say 43 ~~ Even; # False


Use the power  :-)

Re: odd and even

2018-04-30 Thread Elizabeth Mattijsen

> On 30 Apr 2018, at 15:12, ToddAndMargo  wrote:
> 
> On 04/30/2018 05:44 AM, Elizabeth Mattijsen wrote:
>>> On 30 Apr 2018, at 12:43, ToddAndMargo  wrote:
>>> 
>>> 
 Am 30.04.2018 um 08:47 schrieb ToddAndMargo:
> Hi All,
> 
> I know it would only take me 25 seconds to write one,
> but do we have an odd and even function build in?
> 
> 
> Many thanks,
> -T
> 
> $ perl6 -e 'my $x=3; say $x.odd;'
> No such method 'odd' for invocant of type 'Int'. Did you mean 'ord'?
>   in block  at -e line 1
> 
> $ perl6 -e 'my $x=3; say $x.even;'
> No such method 'even' for invocant of type 'Int'
>   in block  at -e line 1
>>> 
>>> On 04/30/2018 02:05 AM, Martin Barth wrote:
 Are you aware of the %% operator?
 
 $var %% 2 checks wether it is dividable by 2.
 
 
>>> 
>>> No I was not.  Thank you!
>>> 
>>> I was just going to do a
>>> 
>>> sub  odd( $Num ) { return $Num % 2; }
>>> sub even( $Num ) { return not $Num.odd; }
>> If you create this sub to do value checking, then maybe this approach is 
>> better for you:
>> subset EvenInt of Int where * %% 2;  # all the even Ints
>> subset OddInt of Int where * !%% 2;  # all the odd Ints
>> # works
>> my EvenInt $x = 42;
>> # dies with: Type check failed in assignment to $y; expected EvenInt but 
>> got Int (42)
>> my OddInt  $y = 42;
>> Liz
> 
> I don't get it.  Why would I want to do this?   I only want to know if
> an integer is odd or even.  What am I missing?
> 
> For example, I just coded this:
> 
>sub odd( $Num ) { return $Num % 2; }
> 
>for split( "\n", $ClipStr ).kv -> $LineNum, $Line {

>if odd $LineNum
>   { $PartsStr ~= ''; }  # Green
> else  { $PartsStr ~= ''; }  # Purple
>...
>}
> 
> It allows me to alternate the color for odd and even lines.
> 
> Please remember that I have about 1/100 of your skill when you
> explain things to me.  (For instance, I have no clue what
> `subset` is or how to use it.)

A subset creates a new Type (like Int) from a base type (such as Int) and 
narrows down the condition that is acceptable for it.

https://docs.perl6.org/language/typesystem#index-entry-subset-subset


Re: odd and even

2018-04-30 Thread Elizabeth Mattijsen

> On 30 Apr 2018, at 15:12, ToddAndMargo  wrote:
> 
> On 04/30/2018 05:44 AM, Elizabeth Mattijsen wrote:
>>> On 30 Apr 2018, at 12:43, ToddAndMargo  wrote:
>>> 
>>> 
 Am 30.04.2018 um 08:47 schrieb ToddAndMargo:
> Hi All,
> 
> I know it would only take me 25 seconds to write one,
> but do we have an odd and even function build in?
> 
> 
> Many thanks,
> -T
> 
> $ perl6 -e 'my $x=3; say $x.odd;'
> No such method 'odd' for invocant of type 'Int'. Did you mean 'ord'?
>   in block  at -e line 1
> 
> $ perl6 -e 'my $x=3; say $x.even;'
> No such method 'even' for invocant of type 'Int'
>   in block  at -e line 1
>>> 
>>> On 04/30/2018 02:05 AM, Martin Barth wrote:
 Are you aware of the %% operator?
 
 $var %% 2 checks wether it is dividable by 2.
 
 
>>> 
>>> No I was not.  Thank you!
>>> 
>>> I was just going to do a
>>> 
>>> sub  odd( $Num ) { return $Num % 2; }
>>> sub even( $Num ) { return not $Num.odd; }
>> If you create this sub to do value checking, then maybe this approach is 
>> better for you:
>> subset EvenInt of Int where * %% 2;  # all the even Ints
>> subset OddInt of Int where * !%% 2;  # all the odd Ints
>> # works
>> my EvenInt $x = 42;
>> # dies with: Type check failed in assignment to $y; expected EvenInt but 
>> got Int (42)
>> my OddInt  $y = 42;
>> Liz
> 
> I don't get it.  Why would I want to do this?   I only want to know if
> an integer is odd or even.  What am I missing?
> 
> For example, I just coded this:
> 
>sub odd( $Num ) { return $Num % 2; }
> 
>for split( "\n", $ClipStr ).kv -> $LineNum, $Line {
>if odd $LineNum
>   { $PartsStr ~= ''; }  # Green
> else  { $PartsStr ~= ''; }  # Purple
>...
>}

Perhaps this is a simpler solution:

for split( "\n", $ClipStr ) -> $evenline, $oddline? {
say “Purple $evenline”;
say “Green $_” with $oddline;
}

Note that in this case if you have a odd total number of lines, you can have 
$oddline come is as a type object.  So you need the ? in the signature of the 
block and the check with “with” in the code (which evaluates to True if the 
value is *not* a type object, and it also sets $_ for you then).


Hope this helps



Re: odd and even

2018-04-30 Thread Theo van den Heuvel

Hi Todd,

different people have different ways of learning things. Diving into the 
documentation isn't ideal for all of us. I find the book by Laurent 
Rosenfeld, "Think Perl 6", O'Reilly, extremely helpful in addition to 
the docs.


My problem is that I am working with many and quite different 
programming languages simultaneously and that drives me nuts on a 
regular basis. Well, not much to be done about that, I'm afraid.


happy perling,




Please remember that I have about 1/100 of your skill when you
explain things to me.  (For instance, I have no clue what
`subset` is or how to use it.)

-T


--
Theo van den Heuvel
Van den Heuvel HLT Consultancy


Re: .sub confusion

2018-04-30 Thread Bruce Gray

> On Apr 30, 2018, at 8:04 AM, ToddAndMargo  wrote:
> 
> Hi All,
> 
> I am confused.
> 
> With this sub:
> 
>sub odd( $Num ) { return $Num % 2; }
> 
> 
> Why does this work:
> 
> if odd $LineNum
>  { $PartsStr ~= ''; }  # Green
>else  { $PartsStr ~= ''; }  # Purple
> 
> And this one throw an error:
> 
> if $LineNum.odd
>  { $PartsStr ~= ''; }  # Green
>else  { $PartsStr ~= ''; }  # PurpleNo
> 
>   No such method 'odd' for invocant of type 'Int'. Did
>   you mean 'ord'?
> 
> What is my misunderstanding?
> 
> 
> Many thanks,
> -T

Short answer: Defining a sub does not define a method. There is a work-around, 
though: `.&`

(Simple primer: A `sub` is named code that can be called on any bits of data 
you choose as arguments. In OO, a `method` is named code that is part of a 
class, and can only be called via an object of that class.)

Detail:
Perl 5 had built-in `functions`, i.e. subs that were provided by the base Perl 
language:
$m = sin $x;
$n = abs $y;
push @z, 15;
See `perldoc perlfunc`, or https://perldoc.perl.org/perlfunc.html .

In Perl 6, the equivalent functions are implemented and available as *methods*, 
but are also exported as subs, to allow for fluidity between procedural and OO 
styles of programming (and also less stress for the Perl 5 coders wading into 
the Perl 6 pool):
New method form:
$m = $x.sin;
$n = $y.abs;
@z.push(15);
@z.push: 15;
Old functions still work though:
$m = sin($x);
$m = sin $x;
$n = abs($y);
$n = abs $y;
push(@z, 15);
push @z, 15;
Outside of this special case, an OO API that double-provides its methods as 
subs is usually a bad idea. You *can* do it, using the same trick as the Perl 6 
built-ins: add `is export` to your method definitions.
(But please don't, unless you are *sure* that the confusion and name-space 
pollution and collisions are justified by the definite needs of the API users.)

The reverse path is not provided for; you cannot define a sub and automatically 
get the method form. This is quite correct for OO design; to do otherwise 
implies that you are shoving new methods at run-time into the very top base 
class (the evil MONKEY-PATCHING)!
Not being able to call your sub via method-call-syntax, well, it only looks so 
glaringly inconvenient from the ground floor of language use.
...which is where most of us are!

So, a bit of syntax is provided, as a sop to us who insist that this:
say MySumTwister( MyWickedSub( %h.keys.grep(*.so)».sqrt.sum ).abs );
would look better as:
say %h.keys.grep(*.so)».sqrt.sum.MyWickedSub.abs.MySumTwister;
You *are* allowed to write it in method form (and keep the reader's eyes from 
having to jump back-and-forth) with `.&` instead of `.` , like so:
say %h.keys.grep(*.so)».sqrt.sum.&MyWickedSub.abs.&MySumTwister;


This syntax is listed as "postfix .&", and can be found here:
https://docs.perl6.org/language/operators#postfix_.&;

So. `.` calls a method, and `.&` calls a sub as if the sub were a method.

-- 
Hope this helps,
Bruce Gray (Util)


[perl #130774] [BUG] Rational.REDUCE-ME has a data race

2018-04-30 Thread Aleks-Daniel Jakimenko-Aleksejev via RT
The issue with .unique was resolved in these commits

Rakudo:
https://github.com/rakudo/rakudo/commit/8cd70d1ee3e17fad78ae5daf0890d1cfb74c2deb
Roast:
https://github.com/perl6/roast/commit/ad38801161c518a3cf3bca9012db973851c4b0c3
Roast:
https://github.com/perl6/roast/commit/032ce8df8533da3c5ff85c22720fe01324dd5adf

On 2017-03-06 05:48:07, c...@zoffix.com wrote:
> Another issue the .REDUCE-ME thing causes:
>
> mscha │ m: say (1/2+1/2, 2/2).unique;
> +camelia │ rakudo-moar 9da50e: OUTPUT: «(1 1)␤»
>
> infix:<+> does not call .REDUCE-ME so the rats are different in this case


Re: nil mystery

2018-04-30 Thread Andrew Kirkpatrick
The original error you quoted was about use of Nil. I couldn't
reproduce this by assigning Nil to a variable, turns out that's
because such an assignment is specified to set the variable to the
default value of the type of the variable. my $x = Nil gives (Any), my
Str $y = Nil gives (Str), and only my Nil $z = Nil actually gives Nil.
In your more complete code snippet it looks like the $Line ~~ match
fails, leaving $0 with the value Nil, leading to the error you first
posted.

I think Patrick is right that using braces to control interpolation is
a good idea.

On 30 April 2018 at 21:21, ToddAndMargo  wrote:
>
>> On Sun, Apr 29, 2018 at 10:20:48PM -0700, ToddAndMargo wrote:
>>>
>>> On 04/29/2018 10:12 PM, ToddAndMargo wrote:

 On 04/29/2018 09:32 PM, Andrew Kirkpatrick wrote:
>
> There is not enough context to answer or even reproduce the problem -
> how are the variables declared and what values do they have just prior
> to this line?
>>>
>>>
>>> Some simpler examples:
>>>
>>> $ perl6 -e 'my $x="abcde"; say $x;'
>>> abcde
>>>
>>> $ perl6 -e 'my $x="abcde"; my $y="$x" ~ ""; say $y;'
>>> abcde
>>>
>>> $ perl6 -e 'my $x="abcde"; my $y="$x"; say $y;'
>>> Type Str does not support associative indexing.
>>> in block  at -e line 1
>>>
>>> $ perl6 -e 'my $x="abcde"; my $y="{$x}"; say $y;'
>>> abcde
>>>
>>> $ perl6 -e 'my $x="abcde"; my $y="$x\"; say $y;'
>>> abcde
>>>
>>>
>>> So when is "<" and ">" a letter and when is it a redirect?
>>
>>
>
>
> On 04/30/2018 12:09 AM, Patrick Spek wrote:
>> It seems like in the one case it throws an error, it's because `<>` are
>> being
>> used to index a hash. Or at least tried to. In Perl 6, you can access a
>> Hash's
>> elements using `%foo`, which will access the index `bar` on the Hash
>> `%foo`.
>>
>> The other cases are explicitly not referring to a variable, or have
>> delimiters
>> in place to make it known to the compiler that you're not trying to access
>> a
>> Hash index.
>>
>> The error you're getting is "Type Str does not support associative
>> indexing.",
>> which is correct, though perhaps a little unexpected for you. `$x`
>> contains a
>> Str, not a Hash, but the `` still try to retrieve the index `br` from
>> it.
>> The solution is to use any of the other options you're using, with my
>> personal
>> preference going out to `{$x}`.
>>
>
>
> Hi Patrick,
>
> Now it makes sense.  It was trying to resolve a hash.
>
> Thank you!
>
> -T
>
> --
> ~~
> Computers are like air conditioners.
> They malfunction when you open windows
> ~~


Re: nil mystery

2018-04-30 Thread ToddAndMargo

On 04/30/2018 05:20 PM, Andrew Kirkpatrick wrote:

I couldn't
reproduce this by assigning Nil to a variable



Well as it transpires, when I tested the {$x} version, I
forgot to press "save".  Also, a one liner operated
differently than a program.  And to top things off,
when reading "this" data back from the secondary clipboard,
a nil got stuck at the end of the string.

I use ${x} a lot in bash and Perl5, so {$x} in Perl6
is my preference too.

Good times!