On 1/2/19 2:27 PM, ToddAndMargo via perl6-users wrote:
On 1/2/19 2:11 PM, Simon Proctor wrote:
Have you tried defining your return values in the signature?
sub AddThree( Int $a, Int $b, Int $c --> Int) {...}
With this the compiler knows what your function is supposed to return
and can earn you in advance.
I did and it blew up in my face so I stopped doing it.
For example:
$ cat RtnBooBoo2.pl6
#!/usr/bin/env perl6
sub AddThree( Int $a, Int $b, Int $c --> Str, Int ) {
my Int $d = $a + $b + $c;
return ( "a+b+c=", $d );
}
my Int $X = 0;
my Int $Y = 0;
my Str $Z;
( $X, $Y, $Y ) = AddThree( 1, 2, 3 );
say "X = <$X>\tY = <$Y>\tZ = <$Z>";
RtnBooBoo2.pl6
===SORRY!=== Error while compiling /home/linuxutil/./RtnBooBoo2.pl6
Malformed return value (return constraints only allowed at the end of
the signature)
at /home/linuxutil/./RtnBooBoo2.pl6:3
------> AddThree( Int $a, Int $b, Int $c --> Str⏏, Int ) {