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
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)

?

internal names

But 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 arguments

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?

where constraints

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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.