Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: RFC: Is there more to alias?

by tilly (Archbishop)
on Aug 25, 2004 at 02:18 UTC ( [id://385557]=note: print w/replies, xml ) Need Help??


in reply to RFC: Is there more to alias?

I know that you didn't use a source filter to implement this, but someone will want a source filter variant so that the Perl 6 syntax of := can be supported. So you might think about ways to support that.

In that line of thought, what happens when you do this?

my @y = 1..10; alias my @x = @y; push @y, 11; print map "$_\n", @x;
Will @x turn out to have 1..11 or 1..10 at this point?

The answer should be clearly documented, and will matter a lot if someone wants to make the source filter that I suggested above.

Replies are listed 'Best First'.
Re^2: RFC: Is there more to alias?
by xmath (Hermit) on Aug 25, 2004 at 08:49 UTC

    1..11. If the lhs of assignment is a bare unparenthesized array or hash, the whole thing is aliased. If it's in parens (alias my (@x) = @y), then the contents will be aliased. This is actually in the documentation under "list assignment to whole aggregate".

    I'm not going to do source filtering myself, but the author of Perl6::Binding is of course free to use Data::Alias as "back-end".

    UPDATE: On a side note.. I've now already answered a few "would this work?"-questions.. why doesn't anyone just download and try? perl is an empirical science, remember! :-D

Re^2: RFC: Is there more to alias? (perl6)
by tye (Sage) on Aug 25, 2004 at 14:33 UTC

    Heh, I wonder if I'm missing something, but it appears that Data::Alias's interface is better in several ways than Perl6's. How will Perl6 support the following tasks other than with these relatively ugly hacks:

    $w = alias [$x, $y, $z]; # vs. $w[0] := $x; $w[1] := $y; $w[2] := $z; alias push @x, $y; # vs. push @x, 0; @x[-1] := $y; alias my( @x )= @y; # vs. @x= (); @x[$_] := @y[$_] for 0 .. @y.last; alias my( @x )= GetList(); # vs. is this possible with Perl6's syntax?

    Perhaps Perl6 should have 'alias' built in along with the more succinct := operator?

    - tye        

      The following might work, and if so would cover several of the cases:

      push @x, my $x := $_ for @y;

      But that's still much clumsier than Data::Alias.

      I have a hunch though that in Perl6 we'll be using the splat to do this, something remotely looking like

      *@x := *@y;

      Don't ask me about the precise syntax though.

      Makeshifts last the longest.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://385557]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (6)
As of 2024-04-23 20:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found