Re: ^mro_unhidden

2021-08-21 Thread Vadim Belman

I have tried to explain the essential part of this in a comment to the related 
issue. Regarding the traits, Elizabeth has mostly covered the subject. Coming 
down to the `is hidden` trait, neither Any nor Mu are hidden:

say Any.^hidden; # 0

And, normally, no other class hides them:

say Int.^hides_parent(Any); # 0

Speaking about traits, `is hidden` makes a class hidden by setting 
corresponding attribute on its metamodel object. Trait `hides` adds a parent to 
the list of hidden parents on the child it is applied to. The second approach 
is the way to have a class non-hidden by default but still exclude it from 
method dispatch when necessary.

Best regards,
Vadim Belman

> On Aug 21, 2021, at 2:03 PM, Joseph Brenner  wrote:
> 
> Given and example like this:
> 
>  class A {}
>  class B is A {}
>  class D is B {}
> 
>  say D.^parents(); # ((B) (A))
>  say D.^parents( :all ); # ((B) (A) (Any) (Mu))
> 
> So, I conclude that Any and Mu are "hidden" as far as ^parents is concerned.
> 
> According to the documentation, ^mro_unhidden does this:
> 
>  "Returns a list of types in method resolution order, excluding
>  those that are marked with is hidden."
> 
> And yet, what I see is:
> 
>  say D.^mro_unhidden; # ((D) (B) (A) (Any) (Mu))
> 
> So why does this include Any/Mu?
> 
> A somewhat related question:  How do you check whether a trait is set
> on something?
> Can you get a list of all traits?
> 
>  raku --version
>  Welcome to 퐑퐚퐤퐮퐝퐨™ v2020.10.
>  Implementing the 퐑퐚퐤퐮™ programming language v6.d.
>  Built on MoarVM version 2020.10.
> 



Re: ^mro_unhidden

2021-08-21 Thread Elizabeth Mattijsen
> On 21 Aug 2021, at 20:03, Joseph Brenner  wrote:
> 
> Given and example like this:
> 
>  class A {}
>  class B is A {}
>  class D is B {}
> 
>  say D.^parents(); # ((B) (A))
>  say D.^parents( :all ); # ((B) (A) (Any) (Mu))
> 
> So, I conclude that Any and Mu are "hidden" as far as ^parents is concerned.
> 
> According to the documentation, ^mro_unhidden does this:
> 
>  "Returns a list of types in method resolution order, excluding
>  those that are marked with is hidden."
> 
> And yet, what I see is:
> 
>  say D.^mro_unhidden; # ((D) (B) (A) (Any) (Mu))
> 
> So why does this include Any/Mu?

Good question, I don't have an answer handy.


> A somewhat related question:  How do you check whether a trait is set
> on something?
> Can you get a list of all traits?

No.

A trait is nothing else than a piece of code that gets executed at compile time 
with the object to which it is applied as the parameter (and the value 
specified with the trait).  Whatever the code of that trait actually does, is 
up to that trait.  Most traits mix in a role into the object, but not all.

For instance, the "is hidden-from-backtrace" trait on subroutines and methods, 
mixes in a role:

multi sub trait_mod:(Routine:D $r, :$hidden-from-backtrace!) {
$r.^mixin( role is-hidden-from-backtrace {
method is-hidden-from-backtrace(--> True) { }
}) if $hidden-from-backtrace;
}

But others, like the "is rw" trait on an attribute, just calls a method on the 
Attribute object.

multi sub trait_mod:(Attribute:D $attr, :rw($)!) {
$attr.set_rw();
warn "useless use of 'is rw' on $attr.name()" unless $attr.has_accessor;
}

So there is no generic way to tell what traits have been applied to an object.



Liz

^mro_unhidden

2021-08-21 Thread Joseph Brenner
Given and example like this:

  class A {}
  class B is A {}
  class D is B {}

  say D.^parents(); # ((B) (A))
  say D.^parents( :all ); # ((B) (A) (Any) (Mu))

So, I conclude that Any and Mu are "hidden" as far as ^parents is concerned.

According to the documentation, ^mro_unhidden does this:

  "Returns a list of types in method resolution order, excluding
  those that are marked with is hidden."

And yet, what I see is:

  say D.^mro_unhidden; # ((D) (B) (A) (Any) (Mu))

So why does this include Any/Mu?

A somewhat related question:  How do you check whether a trait is set
on something?
Can you get a list of all traits?

  raku --version
  Welcome to 퐑퐚퐤퐮퐝퐨™ v2020.10.
  Implementing the 퐑퐚퐤퐮™ programming language v6.d.
  Built on MoarVM version 2020.10.