Come for the quick hacks, stay for the epiphanies. | |
PerlMonks |
(Perl6) Signaturesby LanX (Saint) |
on Aug 08, 2017 at 13:11 UTC ( [id://1196984]=perlquestion: print w/replies, xml ) | Need Help?? |
LanX has asked for the wisdom of the Perl Monks concerning the following question:
Hi 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
named parameters
call syntax
Could this call also be written as doctor( prop => "cricket bat" , number => 5) ?
internal namesBut when defining another internal name it shouldn't be possible to write sub doctor(:$prop => $internal) { ... , right? rather sub doctor(:$prop($internal) ) { ... , right?
mandatory named argumentsTalking 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?
where constraints
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
Back to
Seekers of Perl Wisdom
|
|