Author: autrijus Date: Fri Feb 24 14:16:49 2006 New Revision: 7858 Modified: doc/trunk/design/syn/S09.pod
Log: * S09: Autovivification no longer happens under rvalue context. Suggested and contributed by Yuval Kogman. Modified: doc/trunk/design/syn/S09.pod ============================================================================== --- doc/trunk/design/syn/S09.pod (original) +++ doc/trunk/design/syn/S09.pod Fri Feb 24 14:16:49 2006 @@ -672,3 +672,33 @@ a list of keys, the size of which is the number of declared dimensions of the hash. [XXX but this seems to imply another lookup to find the value. Perhaps the associated value can also be bundled in somehow.] + +=head1 Autovivification + +Autovivification will only happen if the vivifiable path is used as a +container, by binding, assigning, or taking a reference. On the other hand, +value extraction does not autovivify. + +This is as opposed to Perl 5, where autovivification could happen +unintentionally, even when the code looks like a non-destructive test: + + my %hash; + exists $hash{foo}{bar}; # creates $hash{foo} as an empty hash reference + +In Perl 6 these read-only operations are indeed non-destructive: + + my %hash; + exists $hash{foo}{bar}; # %hash is still empty + +But these ones I<do> autovivify: + + my %hash; + my $val := $hash{foo}{bar}; + + my @array; + my $ref = \$array[0][0]; + + my %hash; + $hash{foo}{bar} = "foo"; # duh + +This rule applies to dereferencing arrays, hashes, and scalar references.