, , , , . -, Cat Go , (Int). Perl 6 Fail, &fail, , .defined // operator;
if $something_wrong {
return fail "Dang! Even the squaring function isn't working today."
}
else {
return $x ** 2
}
, , ? , , ?
, (Int) -. , (Str), .Str, , .
return $x * $x but "Suprise! Bet you weren't expecting that!"
, , . , (Int) .size;
return $x but role { has $.size = calculate_size() }
, , , , (Int) , ;
role Size { has UInt:D $.size = 0 }
subset MyInt of Int where Size;
sub sqr(Int:D $x, UInt:D :$size = 12) returns MyInt:D {
return $x * $x but Size($size)
}
my $square5 = sqr(5);
say "5 squared is $square5 with size $square5.size()."
# prints: 5 squared is 25 with size 12.
S14 S12 - mixin