Perl 6 Quick Syntax Reference by J. J. Merelo

Perl 6 Quick Syntax Reference by J. J. Merelo

Author:J. J. Merelo
Language: eng
Format: epub
ISBN: 9781484249567
Publisher: Apress


will return True and False, and the result of using eq followed by a collapse via so or ?. As a matter of fact, this is what where does in signatures: it smartmatches against the value of the argument.

Decoupling Signatures

You have seen that Perl 6 is able to capture all values that are going to be used to invoke a routine in a, well, Capture; in fact, it has also objects, called Signatures, which contain the format of the signature a routine is called with. They are mostly used to check if a routine follows a certain signature via smartmatch.

Sometimes all the possibilities with which a routine is going to be called are not known in advance. You know the general layout, but the details might vary, and several possible types might be used as an argument. There’s a straightforward solution: to go sigilless, but then you lose all type information and the possibility of tailoring the implementation to the different types used.my $card-printer = :(Int,Str);

sub print-card( Int $card-number,

Str $suit,

&printer where .signature ~~ $card-printer) {

return printer( $card-number, $suit);

}

my &de-printer = -> Int $card, Str $suit { "$card de $suit" };

my &printer:<♦> = -> Int $card, Str $suit { "$card ♦ $suit" };

say print-card( 2, "Bastos", &de-printer); # 2 de Bastos

say print-card( 9, "Espadas", &printer:<♦>); # 9 ♦ Espadas



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.