Actually, let's try a simpler one: pyanfar Z$ 6 'say ([5])[0]' 5
The list [5] understands Positional, and therefore knows about what to do with the [0]. The parentheses are only because [5][0] looks a bit strange; but that one works the same way. The same is true of the list that words() produces. words() doesn't need to know that, it just gives you a list. Positional describes the "indexable" attribute of a list. (If you look up List in the type documentation, you will see other roles like Iterable that lists know about.) On Wed, Sep 26, 2018 at 10:11 PM Brandon Allbery <allber...@gmail.com> wrote: > That's not helping. What didn't you understand? Are you still expecting > that it is words() that must know all the details of what a list is, > because a list can't know what itself is? > > On Wed, Sep 26, 2018 at 10:09 PM ToddAndMargo <toddandma...@zoho.com> > wrote: > >> On 9/26/18 7:04 PM, Brandon Allbery wrote: >> > It doesn't. It just improves error messages. >> > >> > words() produces a list-like thing; that's what really matters, because >> > list-like things do the Positional role. Declaring it up front lets >> Perl >> > 6 give you an error message early if you use the result in the wrong >> way >> > or if the actual implementation of words() doesn't produce something >> > that does the Positional role. >> > >> > pyanfar Z$ 6 'say (sub { [5] })()[0]' >> > 5 >> > >> > I didn't declare the anonymous sub as producing a Positional; it just >> > returns a List. I then invoke it with (), and apply [] to the resulting >> > List. It's the fact that it produced a List that matters; any List or >> > Seq or Array or Buf, etc. can be []-ed,because they all do the >> > Positional role that defines []. >> >> Uhhh okay. >> > > > -- > brandon s allbery kf8nh > allber...@gmail.com > -- brandon s allbery kf8nh allber...@gmail.com