develooper Front page | perl.perl6.users | Postings from June 2018

Re: mixin syntax: does vs but

Thread Previous | Thread Next
From:
Elizabeth Mattijsen
Date:
June 12, 2018 08:01
Subject:
Re: mixin syntax: does vs but
Message ID:
32F2C8DC-A7D6-447F-AF01-3D63D8D1E608@dijkmat.nl
> On 12 Jun 2018, at 09:06, Joseph Brenner <doomvox@gmail.com> wrote:
> 
> I thought this would work to make a copy of @x but with the role
> "LookInside" attached to it:
> 
>   my @y = @x but LookInside;
> 
> But that didn't add the role to @y. E.g.
> 
>  say @y.^WHAT
> 
> Would just report (Array), not (Array+{LookInside}).

What you’re doing here, is assigning the elements of an Array but Lookinside to a normal Array.  The elements of the Array do not have any roles mixed in, so you wind up with a normal Array with normal elements in them.  Perhaps you meant:

    my @y does LookInside = @x;

Here you create an Array @y with the role LookInside mixed in, and *then* assign the values from @x.



Also, what JJ Merelo said: StackOverflow is your friend  :-)



Liz
Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About