On Sun, 30 Sep 2018, 12:05 ToddAndMargo, <toddandma...@zoho.com> wrote:

> Hi All,
>
> https://docs.perl6.org/routine/join#(List)_routine_join
>
> method join(List:D: $separator --> Str:D)
>
> $ p6 'say (1, <a b c>).join("|");'
> 1|a b c
>
>
> In this instance you have passed in two objects the Int 1 and a list of
> Str's <a b c> (<> being similar to qw () in perl5. Join works on Str's to
> the first thing it does is convert each of the two parameters to Str, the
> default Str conversion for a list is space separated hence "a b c" which is
> then joined with "1" to get "1|a b c"
>
>
> It states in the manual that this will happen.
>
> Questions:
>
>     1) why?
>
>     2) where in the method definition does it state
>        this will happen?
>
>     3) why does this work?
>           $ p6 'join( "|", <1 2 3>).say;'
>           1|2|3
>
> In this case the join sub will be using the + slurpy so it's flattening
> the given input into it's parameter list and then joining it.
>
> Many thanks,
> -T
>

I think you really want to get a solid understanding of signatures, they
are what gives Perl6 a lot of it's flexibility. Unlike Perl5 where many
functions have special rules handling input in Perl6 a lot of it is done
with Signatures.

Simon

>

Reply via email to