Re: I do not understand method":"

2020-05-26 Thread ToddAndMargo via perl6-users

On 2020-05-25 14:00, Brad Gilbert wrote:

In the following the 「:」 makes it so you don't need parenthesis


You have created a monster!

> my $s="a:c"; say $s.index: ":"
1

:-)


Re: I do not understand method":"

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

my $var =  *.raku();

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

The long way to write that would be:

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

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

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

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

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

So it is something like the following:

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

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

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

say @result

---

Note that the following two lines are identical.

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

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

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

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


Re: I do not understand method":"

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


Hi All,

Looking at the following:

  > my @things = .sort: *.Version; dd
@things; for @things {say $_;}

Array @things = ["a1b33", "a1", "a2rc2", "a2.3", "a5.1", "b1a23"]

a1b33
a1
a2rc2
a2.3
a5.1
b1a23

Other than not quite getting the alpha, beta, and
release candidate thing down, I do not understand:

.sort: *.Version

1) What does the `:` do?

2) Why the space?

3) What does the `*` do?

4) Is the dot before Version mean something other
than .Version being a method?

Yours in confusion,
-T



On 2020-05-25 14:00, Brad Gilbert wrote:


In the following the 「:」 makes it so you don't need parenthesis

     (…).sort: …

     (…).sort(…)

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

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


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

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

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

     say-the-type  *;  # Whatever

     say -the-type *.method; # WhateverCode





Hi Brad,

Thank you!

So the same as
> my @things = <5 2 1 33 22>.sort( *.Version )
[1 2 5 22 33]


Why don't these two work?  Or at least give the
wrong answer.  I thought Version was a method.

> my @things = <5 2 1 33 22>.sort.Version
No such method 'Version' for invocant of type 'Seq'
  in block  at  line 1

> my @things = <5 2 1 33 22>.Version.sort
No such method 'Version' for invocant of type 'List'
  in block  at  line 1


What is a "lambda" λ?

-T


Re: I do not understand method":"

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

(…).sort: …

(…).sort(…)

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

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

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

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

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

say-the-type  *;  # Whatever

say -the-type *.method; # WhateverCode


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

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


I do not understand method":"

2020-05-25 Thread ToddAndMargo via perl6-users

Hi All,

Looking at the following:

> my @things = .sort: *.Version; dd 
@things; for @things {say $_;}


Array @things = ["a1b33", "a1", "a2rc2", "a2.3", "a5.1", "b1a23"]

a1b33
a1
a2rc2
a2.3
a5.1
b1a23

Other than not quite getting the alpha, beta, and
release candidate thing down, I do not understand:

.sort: *.Version

1) What does the `:` do?

2) Why the space?

3) What does the `*` do?

4) Is the dot before Version mean something other
than .Version being a method?

Yours in confusion,
-T