Apocalypse 5
by Larry Wall
|
Pages: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24
Editor's Note: this Apocalypse is out of date and remains here for historic reasons. See Synopsis 05 for the latest information.
RFC 166: Alternative lists and quoting of things
Alternative lists of literals are included simply by mentioning the array:
/@names/
Alternative lists of subrules are included with:
/<@names>/
There's no longer any need for quoting constructs because variables match as literals by default. You have to use angle brackets to get interpretation of a string as a subrule. (But it's still preferable to precompile your regexen.)
RFC 191: smart container slicing
As proposed, this might prevent us from using a regex object as a key to a hash. However, with some tweaking, it'll fit in with how slicing is done in Perl 6.
Perl 6 will DWIM subscripts based on their appearance. Obviously,
%hash{"foo"}
has a single subscript. And just as obviously,
%hash{"a" .. "z"}
has 26 subscripts or so. In the absence of any scalar guidance, a subscript will be interpreted in list context. So
%hash{ @array }
will automatically slice on the list of keys in the array. Any function will be called in a list context by default, giving it the opportunity to return multiple values. Perl 6 subscripts are naturally biased toward slicing. To unbias it, here are some of the specifically recognized subscripts:
%hash{"foo"} # scalar literal
%hash{bar} # scalar literal
%hash{1} # scalar literal
%hash{$x} # scalar variable
%hash{\$x} # scalar reference
%hash{["a", "b"]} # array reference
%hash{{"a" => "b"}} # hash reference
%hash{ "a" => "b" } # pair reference
%hash{ /pat/ } # rule reference
%hash{ _ expr } # force expr to return a single string
%hash{ + expr } # force expr to return a single number
Boolean expressions and closures look like singular values but cause a match against all possible values of the subscript.
%hash{ ?1 } # select all subscripts
%hash{ ?/pat/ } # select subscripts for which pat matches
%hash{ $_ =~ /pat/ }# select subscripts for which pat matches
%hash{ $_ ge "a" } # select lowercase keys (assuming ASCII)
%hash{ .ge "a" } # same thing, maybe
%hash{ { expr } } # select subscripts for which closure returns true
Multiple slice subscripts are separated by semicolons, so that you can use commas within each slice subscript for list building. This is more important for multi-dimensional arrays:
my @array is dim(9,9,9) = cubic();
@3d_slice = @array[ @x; @y; @z ];
@3d_slice = @array[ 0,1,3,8 ; 0,1,3,8; ?1 ];
@3d_slice = @array[ 0..9 ; 0..9:-1; ?test($_) ];
@3d_slice = @array[ !($_ % 2) ; 0..9:3; ?test($_) ];
Pages: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24 |

