Signature Reference
Parameter list pattern
What it is #
Routines #
Signatures are reproduced from the documentation, including their declared return types. A routine listed here is part of the type's published interface; whether Raku++ implements it is a separate question, answered by the examples below.
method params #
method params(Signature:D: --> Positional)
Returns Positional.
Returns the list of Parameter objects that make up the signature.
method arity #
method arity(Signature:D: --> Int:D)
Returns Int:D.
Returns the minimal number of positional arguments required to satisfy the signature.
method count #
method count(Signature:D: --> Real:D)
Returns Real:D.
Returns the maximal number of positional arguments which can be bound to the signature. Returns Inf if there is a slurpy positional parameter.
method returns #
Whatever the Signature's return constraint is:
method ACCEPTS #
multi method ACCEPTS(Signature:D: Signature $topic)
multi method ACCEPTS(Signature:D: Capture $topic)
multi method ACCEPTS(Signature:D: Mu \topic)
If $topic is a Signature returns True if anything accepted by $topic would also be accepted by the invocant, otherwise returns False: The $topic is a Capture, returns True if it can be bound to the invocant, i.e., if a function with invocant's Signature would be able to be called with the $topic: Lastly, the candidate with Mu \topic converts topic to
method Capture #
method Capture()
Throws X::Cannot::Capture. In some situations, specifically when working with the MetaObject Protocol, it makes sense to create Signature objects programmatically. For this purpose, you can call the new method with the following named parameters: A list of Parameter objects for this signature. Any constraint the return value should match. Defaults to Mu, which
Examples, run three ways #
Every example below comes from the official documentation, together with the output that documentation asserts. Each was then executed by Rakudo and by Raku++ when this page was built. Where the three agree, one result is shown; where they do not, all three are — because which of them is wrong is exactly the information worth having.
4 doc-drift · 2 no-output · 1 rakupp-differs
class Signature { }Not executed: the documentation states no expected output for this example.
:($a, $b --> Int).returns # OUTPUT: «(Int)»
(Int)Both engines agree; the documentation states something else. Trust the engines.
:($a, $b) ~~ :($foo, $bar, $baz?); # OUTPUT: «True» :(Int $n) ~~ :(Str); # OUTPUT: «False»
TrueFalseBoth engines agree; the documentation states something else. Trust the engines.
\(1, 2, :foo) ~~ :($a, $b, :foo($bar)); # OUTPUT: «True» \(1, :bar) ~~ :($a); # OUTPUT: «False»
TrueFalseBoth engines agree; the documentation states something else. Trust the engines.
<a b c d> ~~ :(Int $a); # OUTPUT: «False» 42 ~~ :(Int); # OUTPUT: «False» (Int.Capture throws) set(<a b>) ~~ :(:$a, :$b); # OUTPUT: «True»
FalseFalseTrueBoth engines agree; the documentation states something else. Trust the engines.
say :(42) ~~ :($ where 42) # OUTPUT: «False»
False
False
True
Raku++ disagrees with both the documentation and Rakudo — a defect.
Signature.new(params => (...), returns => Type, arity => 1, count => 1.Num)
Not executed: the documentation states no expected output for this example.