As explained in the docs, you can reference an existing function by prepending the &
sigil:
&say # reference to the `say` function
&infix:<+> # reference to the infix `+` operator
How do I do this for methods?
As explained in the docs, you can reference an existing function by prepending the &
sigil:
&say # reference to the `say` function
&infix:<+> # reference to the infix `+` operator
How do I do this for methods?
This article's author explains there are a few possibilities to get hold of a method object, however the most relevant one here is to use the MOP method .^lookup
:
say Array.^lookup('push').raku
#`«
proto method push ($: |) {*}
»
For example to get all the candidates's signatures for Array
's push
method you'd do:
.say for Array.^lookup('push').candidates.map(*.signature);
#`«
(Any:U \SELF: |values)
(Array:D: Slip \value, *%_ --> Array:D)
(Array:D: \value, *%_ --> Array:D)
(Array:D: **@values is raw, *%_ --> Array:D)
»
© 2022 - 2024 — McMap. All rights reserved.
lookup
it "does not provide a full list of candidates ... if you're after something which can be invoked you probably want to usefind_method
[which] will use a default candidate for parametric roles, whereaslookup
throws an exception ... and ... [find_method
] honorsFALLBACK
methods, whichlookup
does not." (And I presume what is true forfind_method
is also true forfind_method_qualified
.) – Marciemarcile