HaloO, Larry Wall wrote:
The operator iterates each function until the function fails to produce any list elements....
What is the list type these days? It used to be List for writeable lists and Seq for readonly ones. But isn't the latter superseded by Capture? I would think it handy to have a type like Range that allows to introspect the list e.g. to get the routine that calculates the next item when given a previous one or the routine that calculates the nth item in a random access fashion. Random access for a numeric Range is particularly easy: multi method postcircumfix:<[ ]> ( Range[Num] $range, Int $index ) { my $ret = $range.from + $index * $range.by; return $ret <= $range.to ?? $ret !! undef; } How would the corresponding method look like for List? multi method postcircumfix:<[ ]> ( List $list, Int $index ) { my &nth = $list.nth; # get nth item generator if &nth { return nth($index); } else { # use iterator interface } } Note that every function that takes an Int as first parameter could then be wrapped up as a list with random access. > Note you can go the other way too: the > function can actually return multiple list elements at once, so you > can interleave two (or more) independent lists: > > 0,1 ... { $^even + 2, $^odd + 2 } > > Interestingly, since the returned list is a capture, such a list > in slice context would turn into [0,1],[2,3],[4,5]..., In list > context it's just 0,1,2,3,4,5 >
I think that's just wicked cool.
Very subtle it is. And I wonder how exactly this is implemented. I mean the pairs returned from the generator are captured into what, protoarrays that auto-flatten into a list and become real arrays in a slice? Regards, TSa. -- "The unavoidable price of reliability is simplicity" -- C.A.R. Hoare "Simplicity does not precede complexity, but follows it." -- A.J. Perlis 1 + 2 + 3 + 4 + ... = -1/12 -- Srinivasa Ramanujan