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

    Hi All,

    Looking at the following:

      > my @things = <a5.1 a2.3 b1a23 a1b33 a1 a2rc2>.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 <unit> at <unknown file> line 1

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


What is a "lambda" λ?

-T

Reply via email to