On Fri Mar 25 11:53:59 2016, [email protected] wrote: > Let's start with an example that works: > > Code: > my @a; > @a[^8] = 5, 6; > say @a > > Result: > [5 6 (Mu) (Mu) (Mu) (Mu) (Mu) (Mu)] > > That's fine. But let's try an infinite range now: > > Code: > my @a; > @a[^∞] = 5, 6; > say @a > > Result: > [] > > That's definitely not what I meant. > We've been around the block a few times on this one, and the current semantics that you observe here are the ones we've settled on, so this is not a bug. But to explain why things are this way...
Note also that: $ perl6-m -e "my @a; @a[lazy ^8] = 5, 6; say @a;" [] The iterator of ^∞ considers itself wanting lazy evaluation, and this lazy marking is what we use to decide between truncating at the current length of the array (lazy) or taking the range at face value and indexing all the elements (non-lazy). For a while, we always trimmed ranges at the length of the array, meaning: @a[0,1] = <a b>; Would assign, and: @a[^1] = <a b>; Would do nothing. We fixed that to make the above two equivalent, which is a lot less surprising, and by hanging it off the laziness peg we still let @a[2..*] (or @a[2..Inf]) truncate as expected when slicing. Note that since l-values are first class in Perl 6, we can't in general know whether a given indexing is going to be used as an l-value or not, so making: @a[^∞] = ... Do something different to: ... = @a[^∞] Is also not an option. And I think we can agree that r-value auto-truncating is highly useful. Also note that slicing in and of itself is an eager operation. Thanks, /jnthn
