There are four different types of a function. (both method and sub)

- `multi`
- `proto`
- `only`
- `anon`

A `proto` function is mainly just to declare there will be multiple
functions with same name.
`multi` is short for "multiple", meaning more than one.
`only` is the default, it means there is only one.
`anon` is for creating a lambda. (You only need it if you give the function
a name.)

Again this applies to both subs and methods.
(Also `regex`, `token`, and `rule`. As they are just special methods.)

    only sub foo (){}
    only sub foo (1){} # ERROR: redeclaration
    # note that `only` is optional, as it is the default.

    proto sub bar (|){*}
    multi sub bar (){}
    multi sub bar (1){}
    # note that defining a `proto` function is optional

    my $var = anon sub baz (){ 'fuzz' };
    say baz(); # ERROR: can't find a sub named `baz`
    say $var(); # fuzz
    say $var.name; # baz

On Sun, Jun 7, 2020 at 3:15 AM ToddAndMargo via perl6-users <
perl6-us...@perl.org> wrote:

> Hi All,
>
> Dumb question:
>
> Does the "multi" in "multi method" mean there
> is more than one way to address a method?
>
> Or, are the all methods "multi methods".
>
> If not and the method is a multi, should not the
> documentation show all (more than one) the ways of
> addressing a multi method?
>
> Many thanks,
> -T
>

Reply via email to