Perl 6 More laziness and lists #36

Slicing and infinity

> my @words = < orange lime cherry banana lemon >;

> say @words[0,4,2];
orange lemon cherry

> say @words[3..7];     # slice beyond the end of the list
banana lemon Any() Any() Any()

> say @words[3..Inf];   # now what...?
> say @words[3..*];     # now what...?

If a subscript is "known infinite", then slicing does an "autotrim" operation that stops at the first index beyond the end.

> say @words[3..*];     
banana lemon

@words[3..7]            # always 5 elements
@words[3..*]            # autotrims to @words.elems
Copyright © 2012
http://www.pmichaud.com/2012/pres/