Question:
Is there/What is the Perl6 counterpart of Powershells get-member
to "analyse" the attributes of a variable?
Explanation:
In Perl 6 you can get properties/attributes of a variable, e.g.:
my $num=16.03;
say $num.numerator; # output: 1603
say $num.denominator; # output: 100
say $num.nude; # output: (1603 100)
say $num.WHAT; # output: (Rat)
How can I find out, which attributes/properties (numerator etc.) and methods/functions (WHAT) a variable has?
In Powershell I would pipe the variable to get-member
, like:
$num | get-member
and would get all properties and function displayed.
The best way would be to consult the docs for whatever type .WHAT
told you, e.g. https://docs.perl6.org/type/Rat for Rat
.
If you must have it programmatically, you can ask the object for its methods with .^methods
.
> my $num = 16.03
16.03
> $num.^methods
(Rat FatRat Range atanh Bridge sign sqrt asech sin tan atan2 acosech truncate
asinh narrow base floor abs conj acosh pred new asec cosec acotan cosh ceiling
nude acos acosec sech unpolar log exp roots cotan norm sinh tanh acotanh Int
Num Real sec asin rand polymod log10 cos round REDUCE-ME succ base-repeating
cis cosech isNaN Complex cotanh atan perl WHICH Str ACCEPTS gist Bool Numeric
DUMP numerator denominator)
You can similarly see the attributes ('properties') with .^attributes
, but any that you should access will have accessor methods anyway, so you shouldn't really need to do that.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With