I picked some examples from https://perl6advent.wordpress.com/2013/12/21/day-21-signatures/ but am not sure if they are still valid syntax, because of confusion with Synopsies S06
sub doctor(:$number, :$prop) { say "Doctor # $number liked his $prop"; } doctor(:prop("cricket bat"), :number<5>);
Could this call also be written as
doctor( prop => "cricket bat" , number => 5)
?
But when defining another internal name it shouldn't be possible to write
sub doctor(:$prop => $internal) { ... , right?
rather
sub doctor(:$prop($internal) ) { ... , right?
Talking about mandatory named parameters where do I place the ! then?
sub doctor(:$prop! => $internal)
resp
sub doctor(:$prop($internal)! ) { ... , right?
or
sub doctor(:$prop!($internal) ) { ... , right?
==== default values
And when defining a default value, where do I place it?
sub doctor(:$prop($internal) = 'something ) { ... ' , right?
==== why optional inverted default for named
BTW positional arguments are by default mandatory and become optional when a default value is provided.
But named arguments are by default optional, why not the same trick?
use v6; multi odd-or-even(Int $i where * %% 2) { say "even" }; multi odd-or-even(Int $i) { say "odd"};
apparently means something like sub { $_ % 2 } .
why two %% and is it possible to use a more familiar P5 syntax here? like where {$x % 2} ?
Cheers Rolf
(addicted to the Perl Programming Language and ☆☆☆☆ :)
Je suis Charlie!
In reply to (Perl6) Signatures by LanX
For: | Use: | ||
& | & | ||
< | < | ||
> | > | ||
[ | [ | ||
] | ] |