develooper Front page | perl.perl6.users | Postings from January 2019

Re: Bad syntax check

Thread Previous | Thread Next
From:
ToddAndMargo via perl6-users
Date:
January 2, 2019 22:50
Subject:
Re: Bad syntax check
Message ID:
ab4773c7-4186-95ab-4f29-9b941372474f@zoho.com
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 ) {

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About