Beefy Boxes and Bandwidth Generously Provided by pair Networks Bob
Syntactic Confectionery Delight
 
PerlMonks  

Re: RFC: Is there more to alias?

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

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.


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 04: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 10: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
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.