Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

I'm working on a module named Data::Alias to provide a comprehensive set of aliasing operations. For those who don't know, aliasing is getting two expressions to identify exactly the same thing. So while setting $x to $y will make $x and $y the same, aliasing $x to $y will make \$x and \$y the same (Diagram).

Its interface is simple: alias LIST or alias BLOCK. The function itself is essentially a no-op, but the entire argument list is evaluated with altered semantics where aliasing occurs wheever copying would normally be done. This is achieved by diddling the optree, not by using a source filter.

This means you can use natural perl syntax to do all sorts of aliasing:

alias my ($x, $y) = @_;Named aliases for sub arguments
alias @x = @{$self->{Items}};Alias for some referenced array
$x = alias [$y, $z];An anonymous array of aliases
(just like $x = sub{\@_}->($y, $z))
alias push @x, $y;Push an alias onto an array

Currently it supports aliasing assignment to variables, array/hash elements, dereferencing, and globs, including conditional assignment (&&=, ||=). Also push, unshift, splice, and anonymous array/hash constructors. do-blocks return aliases (in fact, they are lvalues). Finally you can return aliases from sub or eval, either implicitly by placing the sub/eval inside alias, or explicitly by using alias return LIST;

UPDATE: Putting a conditional expr ( ? :) on the left-side of assignment didn't work. I've added support for it and uploaded a new snapshot.

So the big question is... have I overlooked anything? Are there more operations that deserve to receive aliasing semantics inside alias?

A minor second issue what to do with aliasing elements of tied arrays and hashes. Currently I just give an error, but I considered checking for special methods like ALIAS_STORE, ALIAS_PUSH, etc. Would this be of any utility at all?

And any other sort of feedback is welcome too of course :-)


In reply to RFC: Is there more to alias? by xmath

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (6)
As of 2024-03-28 11:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found