Author: lwall
Date: 2010-03-05 01:03:51 +0100 (Fri, 05 Mar 2010)
New Revision: 29937
Modified:
docs/Perl6/Spec/S09-data.pod
Log:
[S09] kill masak++'s @array[%100_000] in favor of a mapping closure
(The fact that % vars can't use _ is a different bug.)
Modified: docs/Perl6/Spec/S09-data.pod
===================================================================
--- docs/Perl6/Spec/S09-data.pod 2010-03-04 16:17:41 UTC (rev 29936)
+++ docs/Perl6/Spec/S09-data.pod 2010-03-05 00:03:51 UTC (rev 29937)
@@ -13,8 +13,8 @@
Created: 13 Sep 2004
- Last Modified: 26 Feb 2010
- Version: 43
+ Last Modified: 4 Mar 2010
+ Version: 44
=head1 Overview
@@ -244,18 +244,29 @@
There is no autotruncation on the left end. It's not that
hard to write C<0>, and standard indexes always start there.
-As a special form, numeric subscripts may be declared as cyclical
-using an initial C<%>:
+As a special form, subscript declarations may add a C<:map> modifier
+supplying a closure, indicating that all index values are to be mapped
+through that closure. For example, a subscript may be declared as cyclical:
- my @seasons[%4];
+ my @seasons[4:map(*%4)];
In this case, all numeric values are taken modulo 4, and no range truncation
can
ever happen. If you say
@seasons[-4..7] = 'a' .. 'l';
-then each element is written three times and the array ends up with
C<['i','j','k','l']>.
+then each element is written three times and the array ends up with
+C<['i','j','k','l']>. The mapping function is allowed to return
+fractional values; the index will be the C<floor> of that value.
+(It is still illegal to use a numeric index less that 0.) One could
+map indexes logarithmically, for instance, as long as the numbers
+aren't so small they produce negative indices.
+Another use might be to map positive numbers to even slots and negative
+numbers to odd slots, so you get indices that are symmetric around 0
+(though Perl is not going to track the max-used even and odd slots
+for you when the data isn't symmetric).
+
=head1 Typed arrays
The type of value stored in each element of the array (normally C<Any> for
unspecified type)