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

Re: mixin syntax: does vs but

Thread Previous | Thread Next
From:
Brandon Allbery
Date:
June 12, 2018 16:34
Subject:
Re: mixin syntax: does vs but
Message ID:
CAKFCL4UiPhboUS68GYurZMT1zEtFeyqi=A91fZOKwS6FOSh8Zg@mail.gmail.com
You really do want to be exclusionary, don't you?

yada yada stackoverflow is the one truth yada yada.

Enough.

On Tue, Jun 12, 2018 at 3:12 AM JJ Merelo <jjmerelo@gmail.com> wrote:

> (also: ask questions in StackOverflow whenever possible :-) )
>
> El mar., 12 jun. 2018 a las 9:09, JJ Merelo (<jjmerelo@gmail.com>)
> escribió:
>
>> Use binding:
>>
>> my @x= <1 2 3>; my @y := @x but Iterable; say @y.^name; #  OUTPUT:
>> «Array+{Iterable}␤»
>>
>> El mar., 12 jun. 2018 a las 9:06, Joseph Brenner (<doomvox@gmail.com>)
>> escribió:
>>
>>> 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}).
>>>
>>> I found that this would do what I was trying to do though:
>>>
>>>    my @y = @x;
>>>    @y does LookInside;
>>>
>>> I didn't think there would be any difference between the two
>>> though.  What am I not getting?
>>>
>>> The full code looks like this:
>>>
>>> trial_introspect.pl6:
>>>
>>>   use v6;
>>>   use Trial::Introspect;
>>>   my @x = <wuhn tew thuree foah fahv sex>;
>>>   my @y = @x;
>>>   @y does LookInside;
>>>   say "Methods: ";
>>>   say @y.methodical_methods;
>>>
>>>
>>> .../Trial/Introspect.pm6:
>>>
>>>   role LookInside {
>>>     method methodical_methods {
>>>       self.^methods.map({ .gist }).sort.unique.map({ "$_\n" }).grep({
>>> ! /^Method/ });
>>>     }
>>>   }
>>>
>>
>>
>> --
>> JJ
>>
>
>
> --
> JJ
>


-- 
brandon s allbery kf8nh                               sine nomine associates
allbery.b@gmail.com                                  ballbery@sinenomine.net
unix, openafs, kerberos, infrastructure, xmonad        http://sinenomine.net

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