Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

Re^6: RFC: Is there more to alias?

by xmath (Hermit)
on Aug 25, 2004 at 00:17 UTC ( #385548=note: print w/replies, xml ) Need Help??

in reply to Re^5: RFC: Is there more to alias?
in thread RFC: Is there more to alias?

You still misundestand how Data::Alias works, and you seem to see too much magic where there is none. Data::Alias does no parsing, perl does the parsing, so all syntax is just perl's syntax. Like I said in the description, "alias" itself is a nop. To perl, it's thin air. In fact, if you look at the operations executed (-MO=Concise,-exec), for example for alias push @x, $y:

3 <0> pushmark s 4 <#> gv[*x] s 5 <1> rv2av[t3] lKRM/1 6 <#> gvsv[*y] sM 7 <@> push[t5] vK/2 - <1> ex-list vK

See the call to alias? Nope, it isn't even there, apart from a miniscule stub "ex-list" (a nop). Alias just changes the semantics of whatever is inside it, and in a very simple way: whereever perl normally copies data, aliasing occurs instead.

So, let's analyze the cases. Take $x = alias [$y, $z] for example. What does it do? The [$y, $z] is just the array constructor which normally creates a new array, fills it with copies of $y and $z, and returns a reference to the array. Within the scope of "alias", it therefore creates a new array, fills it with aliases to $y and $z, and returns a reference to the array, which it then normally assigned to $x.

alias push @x, $y is indeed as you noted parsed as alias(push(@x, $y)). This push would normally add a copy of $y onto the end of @x, so within "alias" it adds an alias to $y onto the end of @x. This obviously differs from alias $x[-1] = $y which would overwrite the last element of @x with an alias to $y.

You finally mentioned using a comma... ($x, $y) involves no copying, therefore alias($x, $y) does nothing remarkable. It behaves 100% identical to plain ($x, $y).

All cleared up now? :-)

Time for me to get some sleep too.. zZ

Replies are listed 'Best First'.
Re^7: RFC: Is there more to alias?
by fergal (Chaplain) on Aug 25, 2004 at 08:53 UTC
    I didn't think you were parsing anything but I misunderstood what alias does and so assumed that my parsing of alias push @x, $y was wrong. I'm used to thinking of "alias this to that" rather than "turn on aliasing for this bit of code".

    I know you changed the lexer to make this unnecessary but I think syntax like

    alias { push(@x, y) }
    would give a clearer indication of what is going on. It would also cause problems with scoping when you want to use my:-(
      You can use either syntax, so if you think alias { push(@x, $y) } is clearer, use that. (I'm personally a fan of sparse use of parens and braces, but maybe that's just my strange taste). Note however indeed that if you try to do my-declarations, you can run into trouble... alias { my $x = $y } would do nothing useful, since the scope of $x is limited to the block.

      On a side note, the lexer hack is actually to make alias { .. } work. alias LIST is the normal mode of operation.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://385548]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (7)
As of 2017-03-26 16:26 GMT
Find Nodes?
    Voting Booth?
    Should Pluto Get Its Planethood Back?

    Results (315 votes). Check out past polls.