Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot make named parameters aliases #57

Closed
barefootcoder opened this issue Oct 22, 2012 · 2 comments
Closed

Cannot make named parameters aliases #57

barefootcoder opened this issue Oct 22, 2012 · 2 comments

Comments

@barefootcoder
Copy link
Contributor

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.

@thoughtstream
Copy link
Contributor

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.

Damian

thoughtstream added a commit that referenced this issue Dec 15, 2012
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!
@barefootcoder
Copy link
Contributor Author

This is fixed in version 20130222.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants