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

Re: augment again

Thread Previous | Thread Next
From:
Elizabeth Mattijsen
Date:
October 20, 2018 12:01
Subject:
Re: augment again
Message ID:
84D7999F-4B51-4757-A7BD-49AAAA172BD7@dijkmat.nl
It is a good start, but you will only see classes that have been bound to a pad somewhere.  There are many classes that are just created on the fly that won’t be seen, as the parents do not know about their children.  For example, a little bit contrived, but hopefully gets the point across:

    $ 6 'say 42 but role { method gist() { "foo" } }'
    foo

The “42 but role …” creates a class derived from Int with an extra method “gist” mixed in.  However, that class is not bound to anything.  So you won’t see it.  OTOH, you probably don’t want to bother re-composing that.  But I guess there could be edge cases where it does matter (although I can’t think of one right now).


Liz

> On 19 Oct 2018, at 21:14, Joseph Brenner <doomvox@gmail.com> wrote:
> 
> Okay, good enough... if I can't slip my changes in ahead of
> everything then reinitializing everything viz ^compose sounds
> workable.
> 
> And so, my next question would be "Can I get a list of all
> the built-in classes?"  and I see brian d foy got there
> a little over a year ago:
> 
> https://stackoverflow.com/questions/44861432/is-there-a-way-to-get-a-list-of-all-known-types-in-a-perl-6-program
> 
> The answer from smis suggest I need to be looking in the CORE:: psuedo-package.
> Starting from his code snippet, and hacking quite a bit I've got a start on an
> elephant gun that recomposes everything in CORE:
> 
>  for (|CORE::) .grep({ .key eq .value.^name }) .map( *.value ) -> $class {
>    my $class_name = $class.^name;
>    try {
>        say $class;
>        $class.^compose;
>        CATCH { default { say "Problem with $class_name"; } }
>    }
>  }
> 
> 
> 
> On 10/19/18, Elizabeth Mattijsen <liz@dijkmat.nl> wrote:
>> See also:
>> https://stackoverflow.com/questions/52718499/how-to-correctly-augment-any
>> 
>>> On 19 Oct 2018, at 03:52, Joseph Brenner <doomvox@gmail.com> wrote:
>>> 
>>> I've got another question about aug--yes, I know--ment.
>>> 
>>> I've got a module ides_of_augment.pm6:
>>> 
>>> use MONKEY-TYPING;
>>> augment class Any {
>>>     method hiccup {
>>>         say "hic!";
>>>     }
>>> }
>>> 
>>> I would've thought it could be used in the repl like this:
>>> 
>>> perl6 -Mides_of_augment
>>> 
>>>> (Any).hiccup
>>> hic!
>>>> my @a=< a b c d >;
>>> [a b c d]
>>>> @a.hiccup
>>> No such method 'hiccup' for invocant of type 'Array'. Did you mean
>>> 'hiccup'?
>>>   in block <unit> at <unknown file> line 1
>>> 
>>> As you can see, it kind-of augments the Any class, but evidently
>>> does it too late to (completely) change an instance of Array.
>>> 
>>> I tried a few things like "BEGIN augment" or "INIT augment"
>>> without any luck.
>>> 
>>> Any suggestions (besides "don't do it")?
>> 

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