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.


In reply to Re^2: Aliasing bites by ambrus
in thread Aliasing bites by ambrus

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.