in reply to Re: Aliasing bites
in thread Aliasing bites

While I understand that perl6 will have this feature, I belive there will be less need for it because of the other changes in the language.

The times I feel the need of lexical aliases (in perl5) most are nested datastructures and lexical subs.

For example, when I have a ref-to-hash $h, I can only access elements like $$h{"foo"} (or the arrow notation), which is ugly. It would be much simpler to alias it to %h and then I could just access the elements as $h{"foo"}. Of course, you can make a copy like my %h = %$h;, but that can be slow, and you have to copy it back with %$h = %h; if you modifiy %h. In perl6, however, $$h{"foo"} will become $h{"foo"}, which is a simple enough notation so the problem will be gone. (As a sidenote, there are nonstandard modules for perl5 that allow lexical aliasing.)

Lexical subs are very similar. Today, the way to create lexical subs is my $frobnicate = sub { ... }; and we call them by &$frobnicate(@args) (or the arrow notation), which is, again, ugly. In perl6, this shall simplify to $frobnicate(@args).

Of course, perl6 will have lexical aliases like my %h := %$h and true lexical &-variables in addition to $, @, % so you can use aliasing to solve either of these too. TIMTOWTDI.

Update: lexical aliases wouldn't solve my second problem. We'd need lexical subs for that.

Replies are listed 'Best First'.
Re^3: Aliasing bites
by revdiablo (Prior) on May 11, 2005 at 16:28 UTC

    Perl6 also won't need the arrow notation to dereference values:

    my %hash = (a => 1, b => 2); my $href = \%hash; say %hash<a>++; # prints 1 say $href<a>; # prints 2

    Update: noticed ambrus already mentioned that. Sorry for the repitition. :-)