You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
As part of pull request #56, I asked @thoughtstream why \ (to make a parameter an alias for the passed-in variable) could not be combined with : (to indicate a named parameter). He replied:
The problem is that, without the check, MS current would unpack named and aliased parameters using code like this:
my %args = @_[0..$#_];
alias my $named_and_aliased = delete $args{named_and_aliased};
In other words, named args are copied into %args, then deleted (i.e. copied) out of it again. So you're aliasing a copy of a copy, not the original argument.
The generated code would have to be changed to something like:
my %args;
alias $args{shift @_} = shift @_ while @_;
my $named_and_aliased = $args{named_and_aliased};
delete $args{named};
Feel free to do that if you like. It would certainly be a vast improvement.
(PS: Untested code above...don't rely on it!)
Damian
This should be fixed, and Damian's code added and tested, because the current restriction is unnecessary.
The text was updated successfully, but these errors were encountered:
Once the current set of @thoughtstream mods has been integrated, I
intend to produce a new patch against that updated code. That
patch will provide for more efficient (i.e. with less copying and less
aliasing) extraction of named arguments, including the ability to
alias named args.
The code will not be exactly as described above: after further thought
I realise that there are more optimal ways to achieve the effect.
The attached patch (against yesterday's dev release)
adds the ability to alias named parameters, using either
the '\:@param' or ':@param is alias' syntaxes.
I was surprised how easy it turned out to be to add in this
feature. Data::Alias to the rescue again!
As part of pull request #56, I asked @thoughtstream why
\
(to make a parameter an alias for the passed-in variable) could not be combined with:
(to indicate a named parameter). He replied:This should be fixed, and Damian's code added and tested, because the current restriction is unnecessary.
The text was updated successfully, but these errors were encountered: