El jue., 27 sept. 2018 a las 3:51, ToddAndMargo (<toddandma...@zoho.com>)
escribió:

> On 9/26/18 6:31 PM, ToddAndMargo wrote:
> > On 9/26/18 6:18 PM, Curt Tilmes wrote:>
> >  >      > The methods don't take [].  You are calling [] on the thing
> > that the
> >  >      > methods return.
> >
> >>>
> >>>     Yes, I know.  And it is human readable too.  It is one of the
> >>>     many reasons I adore Perl 6.
> >>>
> >>>     Where in
> >>>          multi method words(Str:D $input: $limit = Inf --> Positional)
> >>>     does it state that "words" will do that?  Not all methods will.
> >>>     So it need to be stated when they will.
> >>>
> >>>
> >
> >
> >
> >  > The part where it says "--> Positional" says the thing that gets
> >  > returned is Positional.
> >  >
> >  > A Positional thing has all sorts of methods and operators you can use,
> >  > including []
> >  >
> >  > Not all methods will, of course.  Only those that say "--> Positional"
> >  > return a Positional that acts like that.
> >  >
> >  > Curt
> >
> > Hi Curt,
> >
> > Perfect! Thank you!
> >
> > So all methods that respond with --> Positional will accept []
> >
> > Awesome!
> >
> > -T
>
>
>
> I do believe the reason I spaced on this was that when I see "-->"
> what goes through my head is "this is the value(s) returned".
> I had not idea it would reflect backwards and affect the method.
>

It does not.

    say "Flim Flam Flum".words[2] # OUTPUT: «Flum␤»

is exactly the same as

    say "Flim Flam Flum".words()[2] # OUTPUT: «Flum␤»

And exactly the same as

    say "Flim Flam Flum".words(Inf)[2] # OUTPUT: «Flum␤»

And exactly the same as

    my @flim-flam-flum = "Flim Flam Flum".words; # @flim-flam-flum carries
an @, ergo it's a Positional
    say @flim-flam-flum[2] # OUTPUT: «Flum␤»

In Perl 6 you can chain calls, that's what is meant by postcircumfix, it
means you can put the operator like thing (in this case, []) _behind_
(post) the thing you are calling, plus you are putting the arguments
_inside_ the operator (that's the circumfix part). You can also do

    say "Flim Flam Flum".words[1,2][0] # OUTPUT: «Flam␤»

You are first post-circumfixing [] over the return value of words, getting
2 elements in a Positional (an List in this case, Positional is a Role, not
a Class), and them post-circumfixing again getting the first of these two
elements. You can do this to exhaustion, as long as it's an object method
or a post-circumfix operator, chaining the one after the other. None of
them is "reflecting" on anything, you are just chaining calls, which is a
nice and compact thing to do.

Cheers
-- 
JJ

Reply via email to