On Thu, Aug 10, 2000 at 10:21:37PM -0000, Perl6 RFC Librarian wrote:
> This and other RFCs are available on the web at
> http://dev.perl.org/rfc/
>
> =head1 TITLE
>
> Replace => (stringifying comma) with => (pair constructor)
>
> =head2 Pairs and arrays
>
> When a pair reference is assigned (in)to an array, it remains a single scalar
> (referential) value. So:
>
> @array = ( a=>1, b=>2, 'c', 3 );
>
> assigns four elements (not six) to @array.
But won't this cause breakage to existing scripts
> =head2 Pairs and subroutines
>
> When a pair reference is used in the argument list of a subroutine with
> no parameter list, it is passed as a single scalar value (i.e it remains
> a pair reference).
>
> When a pair reference is passed to a subroutine with named parameters, it
> binds its value to the parameter of the same name, regardless of the order
> in which it is passed.
>
> Thus:
>
> use Data::Dumper;
>
> sub no_params {
> print "no_params:\n"
> print join "\n", map {ref||"scalar val"} @_;
> print Dumper @_;
> }
>
> sub params ( $name, $rank, $serial_num) {
> print "params:\n"
> print join "\n", map {ref||"scalar val"} @_;
> print Dumper @_;
> }
>
> no_params(serial_num=>1234, name=>'demo', rank=>'RFC');
>
> params(serial_num=>1234, name=>'demo', rank=>'RFC');
>
> prints:
>
> no_params:
> PAIR
> PAIR
> PAIR
> $VAR1 = ( 'serial_num' => 1234 );
> $VAR2 = ( 'name' => 'demo' );
> $VAR3 = ( 'rank' => 'RFC' );
>
> params:
> scalar val
> scalar val
> scalar val
> $VAR1 = 'demo';
> $VAR2 = 'RFC';
> $VAR1 = 1234;
>
>
> Note that these semantics still support the popular:
>
> sub hash_like_args {
> my %args = @_;
> # etc.
> }
But they will break the idiom of
sub list_of_op_value_parameters {
while(my($op,$value) = splice(@_,0,2)) {
# process
}
}
list_of_op_value_paramaters(add => $v1, replace => $v2, add => $v3);
Graham.