Bad syntax check

Dear Perl 6 Developers,

Fedora 29, x64
Xfce 4.13

$ perl6 -v
     This is Rakudo version 2018.11 built on MoarVM version
     2018.11 implementing Perl 6.d.

I am constantly improving (changing things) in my subs,
etc..  As such, the things I return often change.

Because of this, I have a found something I just do not like
in the checker (Perl6 -c xxx) and the run time compiler.

Here is a simplified sample code with the error in it:

<code RtnBooBoo.pl6>
#!/usr/bin/env perl6

sub AddThree( Int $a, Int $b, Int $c ) {
    my Int $d = $a + $b + $c;
    return $d;
}

my Int $X = 0;
my Int $Y = 0;

( $X, $Y ) = AddThree( 1, 2, 3 );
say "X = <$X>\tY = <$Y>";
</code RtnBooBoo.pl6>


The error is that the subroutine is only returning one
value and two are trying to be read.

And the checker passes it!

     $ perl6 -c RtnBooBoo.pl6
     Syntax OK

No, it is not okay.  The sub and the caller do not match up!


If you run the flawed code, you get:

     $ RtnBooBoo.pl6
     Use of uninitialized value of type Int in string context.
     Methods .^name, .perl, .gist, or .say can be used to stringify
     it to something meaningful.  in block <unit> at ./RtnBooBoo.pl6
     line 12

     X = <6>	Y = <>

Which is a bizarre warning (it does not stop on this error).  And
it is also not the error.  The error was that the return line's
returned variables and the caller do not match up.  Not an
uninitialized value.

If you send too few variables to a sub, you get the finger shaken
at you.  The return should also have the same checking capability.

Would you guys please consider improving the checker and the compiler?

Many thanks,
-T
0
perl6
1/2/2019 8:04:01 PM
perl.perl6.users 1199 articles. 0 followers. Follow

6 Replies
87 Views

Similar Articles

[PageSpeed] 15

--000000000000a2fd0a057e80edeb
Content-Type: text/plain; charset="UTF-8"

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.

On Wed, 2 Jan 2019, 20:04 ToddAndMargo via perl6-users <perl6-users@perl.org
wrote:

> Dear Perl 6 Developers,
>
> Fedora 29, x64
> Xfce 4.13
>
> $ perl6 -v
>      This is Rakudo version 2018.11 built on MoarVM version
>      2018.11 implementing Perl 6.d.
>
> I am constantly improving (changing things) in my subs,
> etc..  As such, the things I return often change.
>
> Because of this, I have a found something I just do not like
> in the checker (Perl6 -c xxx) and the run time compiler.
>
> Here is a simplified sample code with the error in it:
>
> <code RtnBooBoo.pl6>
> #!/usr/bin/env perl6
>
> sub AddThree( Int $a, Int $b, Int $c ) {
>     my Int $d = $a + $b + $c;
>     return $d;
> }
>
> my Int $X = 0;
> my Int $Y = 0;
>
> ( $X, $Y ) = AddThree( 1, 2, 3 );
> say "X = <$X>\tY = <$Y>";
> </code RtnBooBoo.pl6>
>
>
> The error is that the subroutine is only returning one
> value and two are trying to be read.
>
> And the checker passes it!
>
>      $ perl6 -c RtnBooBoo.pl6
>      Syntax OK
>
> No, it is not okay.  The sub and the caller do not match up!
>
>
> If you run the flawed code, you get:
>
>      $ RtnBooBoo.pl6
>      Use of uninitialized value of type Int in string context.
>      Methods .^name, .perl, .gist, or .say can be used to stringify
>      it to something meaningful.  in block <unit> at ./RtnBooBoo.pl6
>      line 12
>
>      X = <6>    Y = <>
>
> Which is a bizarre warning (it does not stop on this error).  And
> it is also not the error.  The error was that the return line's
> returned variables and the caller do not match up.  Not an
> uninitialized value.
>
> If you send too few variables to a sub, you get the finger shaken
> at you.  The return should also have the same checking capability.
>
> Would you guys please consider improving the checker and the compiler?
>
> Many thanks,
> -T
>

--000000000000a2fd0a057e80edeb
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"auto"><div>Have you tried defining your return values in the si=
gnature?</div><div dir=3D"auto"><br></div><div dir=3D"auto"><span style=3D"=
font-family:sans-serif">sub AddThree( Int $a, Int $b, Int $c --&gt; Int) {.=
...}</span><br></div><div dir=3D"auto"><br></div><div dir=3D"auto">With this=
 the compiler knows what your function is supposed to return and can earn y=
ou in advance.<br><br><div class=3D"gmail_quote" dir=3D"auto"><div dir=3D"l=
tr">On Wed, 2 Jan 2019, 20:04 ToddAndMargo via perl6-users &lt;<a href=3D"m=
ailto:perl6-users@perl.org">perl6-users@perl.org</a> wrote:<br></div><block=
quote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc=
 solid;padding-left:1ex">Dear Perl 6 Developers,<br>
<br>
Fedora 29, x64<br>
Xfce 4.13<br>
<br>
$ perl6 -v<br>
=C2=A0 =C2=A0 =C2=A0This is Rakudo version 2018.11 built on MoarVM version<=
br>
=C2=A0 =C2=A0 =C2=A02018.11 implementing Perl 6.d.<br>
<br>
I am constantly improving (changing things) in my subs,<br>
etc..=C2=A0 As such, the things I return often change.<br>
<br>
Because of this, I have a found something I just do not like<br>
in the checker (Perl6 -c xxx) and the run time compiler.<br>
<br>
Here is a simplified sample code with the error in it:<br>
<br>
&lt;code RtnBooBoo.pl6&gt;<br>
#!/usr/bin/env perl6<br>
<br>
sub AddThree( Int $a, Int $b, Int $c ) {<br>
=C2=A0 =C2=A0 my Int $d =3D $a + $b + $c;<br>
=C2=A0 =C2=A0 return $d;<br>
}<br>
<br>
my Int $X =3D 0;<br>
my Int $Y =3D 0;<br>
<br>
( $X, $Y ) =3D AddThree( 1, 2, 3 );<br>
say &quot;X =3D &lt;$X&gt;\tY =3D &lt;$Y&gt;&quot;;<br>
&lt;/code RtnBooBoo.pl6&gt;<br>
<br>
<br>
The error is that the subroutine is only returning one<br>
value and two are trying to be read.<br>
<br>
And the checker passes it!<br>
<br>
=C2=A0 =C2=A0 =C2=A0$ perl6 -c RtnBooBoo.pl6<br>
=C2=A0 =C2=A0 =C2=A0Syntax OK<br>
<br>
No, it is not okay.=C2=A0 The sub and the caller do not match up!<br>
<br>
<br>
If you run the flawed code, you get:<br>
<br>
=C2=A0 =C2=A0 =C2=A0$ RtnBooBoo.pl6<br>
=C2=A0 =C2=A0 =C2=A0Use of uninitialized value of type Int in string contex=
t.<br>
=C2=A0 =C2=A0 =C2=A0Methods .^name, .perl, .gist, or .say can be used to st=
ringify<br>
=C2=A0 =C2=A0 =C2=A0it to something meaningful.=C2=A0 in block &lt;unit&gt;=
 at ./RtnBooBoo.pl6<br>
=C2=A0 =C2=A0 =C2=A0line 12<br>
<br>
=C2=A0 =C2=A0 =C2=A0X =3D &lt;6&gt;=C2=A0 =C2=A0 Y =3D &lt;&gt;<br>
<br>
Which is a bizarre warning (it does not stop on this error).=C2=A0 And<br>
it is also not the error.=C2=A0 The error was that the return line&#39;s<br=
>
returned variables and the caller do not match up.=C2=A0 Not an<br>
uninitialized value.<br>
<br>
If you send too few variables to a sub, you get the finger shaken<br>
at you.=C2=A0 The return should also have the same checking capability.<br>
<br>
Would you guys please consider improving the checker and the compiler?<br>
<br>
Many thanks,<br>
-T<br>
</blockquote></div></div></div>

--000000000000a2fd0a057e80edeb--
0
simon
1/2/2019 10:11:15 PM
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.
0
perl6
1/2/2019 10:27:01 PM
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.
>=20
> 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 =3D $a + $b + $c;
    return ( "a+b+c=3D", $d );
}

my Int $X =3D 0;
my Int $Y =3D 0;
my Str $Z;

( $X, $Y, $Y ) =3D AddThree( 1, 2, 3 );
say "X =3D <$X>\tY =3D <$Y>\tZ =3D <$Z>";



RtnBooBoo2.pl6
=3D=3D=3DSORRY!=3D=3D=3D Error while compiling /home/linuxutil/./RtnBooBo=
o2.pl6
Malformed return value (return constraints only allowed at the end of=20
the signature)
at /home/linuxutil/./RtnBooBoo2.pl6:3
------> AddThree( Int $a, Int $b, Int $c --> Str=E2=8F=8F, Int ) {
0
perl6
1/2/2019 10:50:08 PM
--0000000000002c0c55057e8273b8
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

You can only list one type as a return type.

If there were a hypothetical Tuple type:

    sub AddThree( Int $a, Int $b, Int $c --> Tuple[Str, Int] {
        my Int $d =3D $a + $b + $c;
        return Tuple[Str,Int].new( "a+b+c=3D", $d );
    }


    my Int $X =3D 0;
    my Int $Y =3D 0;
    my Str $Z;

    Tuple[Str,Int].new( $X, $Y, $Y ) =3D AddThree( 1, 2, 3 );
    say "X =3D <$X>\tY =3D <$Y>\tZ =3D <$Z>";

 There could be a circumfix operator to generate the Tuple objects.

You are dealing with Lists, which don't have a type specifier for their
elements.

On Wed, Jan 2, 2019 at 4:51 PM ToddAndMargo via perl6-users <
perl6-users@perl.org> wrote:

> 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 =3D $a + $b + $c;
>     return ( "a+b+c=3D", $d );
> }
>
> my Int $X =3D 0;
> my Int $Y =3D 0;
> my Str $Z;
>
> ( $X, $Y, $Y ) =3D AddThree( 1, 2, 3 );
> say "X =3D <$X>\tY =3D <$Y>\tZ =3D <$Z>";
>
>
>
> RtnBooBoo2.pl6
> =3D=3D=3DSORRY!=3D=3D=3D Error while compiling /home/linuxutil/./RtnBooBo=
o2.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=E2=8F=8F, Int ) {
>

--0000000000002c0c55057e8273b8
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div dir=3D"ltr"><div dir=3D"ltr">You can only list one ty=
pe as a return type.<div><br></div><div>If there were a hypothetical Tuple =
type:</div><div><br></div><div>=C2=A0 =C2=A0 sub AddThree( Int $a, Int $b, =
Int $c --&gt; Tuple[Str, Int] {</div><div>=C2=A0 =C2=A0 =C2=A0 =C2=A0 my In=
t $d =3D $a + $b + $c;</div><div>=C2=A0 =C2=A0 =C2=A0 =C2=A0 return Tuple[S=
tr,Int].new( &quot;a+b+c=3D&quot;, $d );</div><div>=C2=A0 =C2=A0 }</div><di=
v><br></div><div><div><br></div><div>=C2=A0 =C2=A0 my Int $X =3D 0;</div><d=
iv>=C2=A0 =C2=A0 my Int $Y =3D 0;</div><div>=C2=A0 =C2=A0 my Str $Z;</div><=
div><br></div><div>=C2=A0 =C2=A0 Tuple[Str,Int].new( $X, $Y, $Y ) =3D AddTh=
ree( 1, 2, 3 );</div><div>=C2=A0 =C2=A0 say &quot;X =3D &lt;$X&gt;\tY =3D &=
lt;$Y&gt;\tZ =3D &lt;$Z&gt;&quot;;</div></div><div><br></div><div>=C2=A0The=
re could be a circumfix operator to generate the Tuple objects.</div><div><=
br></div><div>You are dealing with Lists, which don&#39;t have a type speci=
fier for their elements.</div></div></div></div><br><div class=3D"gmail_quo=
te"><div dir=3D"ltr">On Wed, Jan 2, 2019 at 4:51 PM ToddAndMargo via perl6-=
users &lt;<a href=3D"mailto:perl6-users@perl.org">perl6-users@perl.org</a>&=
gt; wrote:<br></div><blockquote class=3D"gmail_quote" style=3D"margin:0px 0=
px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">On 1/=
2/19 2:27 PM, ToddAndMargo via perl6-users wrote:<br>
&gt; On 1/2/19 2:11 PM, Simon Proctor wrote:<br>
&gt;&gt; Have you tried defining your return values in the signature?<br>
&gt;&gt;<br>
&gt;&gt; sub AddThree( Int $a, Int $b, Int $c --&gt; Int) {...}<br>
&gt;&gt;<br>
&gt;&gt; With this the compiler knows what your function is supposed to ret=
urn <br>
&gt;&gt; and can earn you in advance.<br>
&gt; <br>
&gt; I did and it blew up in my face so I stopped doing it.<br>
<br>
For example:<br>
<br>
$ cat RtnBooBoo2.pl6<br>
#!/usr/bin/env perl6<br>
<br>
sub AddThree( Int $a, Int $b, Int $c --&gt; Str, Int ) {<br>
=C2=A0 =C2=A0 my Int $d =3D $a + $b + $c;<br>
=C2=A0 =C2=A0 return ( &quot;a+b+c=3D&quot;, $d );<br>
}<br>
<br>
my Int $X =3D 0;<br>
my Int $Y =3D 0;<br>
my Str $Z;<br>
<br>
( $X, $Y, $Y ) =3D AddThree( 1, 2, 3 );<br>
say &quot;X =3D &lt;$X&gt;\tY =3D &lt;$Y&gt;\tZ =3D &lt;$Z&gt;&quot;;<br>
<br>
<br>
<br>
RtnBooBoo2.pl6<br>
=3D=3D=3DSORRY!=3D=3D=3D Error while compiling /home/linuxutil/./RtnBooBoo2=
..pl6<br>
Malformed return value (return constraints only allowed at the end of <br>
the signature)<br>
at /home/linuxutil/./RtnBooBoo2.pl6:3<br>
------&gt; AddThree( Int $a, Int $b, Int $c --&gt; Str=E2=8F=8F, Int ) {<br=
>
</blockquote></div>

--0000000000002c0c55057e8273b8--
0
b2gills
1/3/2019 12:00:15 AM
On 1/2/19 4:00 PM, Brad Gilbert wrote:
> You can only list one type as a return type.
>=20
> If there were a hypothetical Tuple type:
>=20
>  =C2=A0 =C2=A0 sub AddThree( Int $a, Int $b, Int $c --> Tuple[Str, Int]=
 {
>  =C2=A0 =C2=A0 =C2=A0 =C2=A0 my Int $d =3D $a + $b + $c;
>  =C2=A0 =C2=A0 =C2=A0 =C2=A0 return Tuple[Str,Int].new( "a+b+c=3D", $d =
);
>  =C2=A0 =C2=A0 }

I drew the line at creating new types
0
perl6
1/3/2019 1:53:58 AM
On 1/3/19 1:52 AM, JJ Merelo wrote:
>=20
>=20
> El mi=C3=A9., 2 ene. 2019 a las 21:04, ToddAndMargo via perl6-users=20
> (<perl6-users@perl.org <mailto:perl6-users@perl.org>>) escribi=C3=B3:
>=20
>     Dear Perl 6 Developers,
>=20
>     Fedora 29, x64
>     Xfce 4.13
>=20
>     $ perl6 -v
>      =C2=A0 =C2=A0 =C2=A0This is Rakudo version 2018.11 built on MoarVM=
 version
>      =C2=A0 =C2=A0 =C2=A02018.11 implementing Perl 6.d.
>=20
>     I am constantly improving (changing things) in my subs,
>     etc..=C2=A0 As such, the things I return often change.
>=20
>     Because of this, I have a found something I just do not like
>     in the checker (Perl6 -c xxx) and the run time compiler.
>=20
>     Here is a simplified sample code with the error in it:
>=20
>     <code RtnBooBoo.pl6>
>     #!/usr/bin/env perl6
>=20
>     sub AddThree( Int $a, Int $b, Int $c ) {
>      =C2=A0 =C2=A0 my Int $d =3D $a + $b + $c;
>      =C2=A0 =C2=A0 return $d;
>     }
>=20
>     my Int $X =3D 0;
>     my Int $Y =3D 0;
>=20
>     ( $X, $Y ) =3D AddThree( 1, 2, 3 );
>     say "X =3D <$X>\tY =3D <$Y>";
>     </code RtnBooBoo.pl6>
>=20
>=20
>     The error is that the subroutine is only returning one
>     value and two are trying to be read.
>=20
>     And the checker passes it!
>=20
>      =C2=A0 =C2=A0 =C2=A0$ perl6 -c RtnBooBoo.pl6
>      =C2=A0 =C2=A0 =C2=A0Syntax OK
>=20
>     No, it is not okay.=C2=A0 The sub and the caller do not match up!
>=20
>=20
>     If you run the flawed code, you get:
>=20
>      =C2=A0 =C2=A0 =C2=A0$ RtnBooBoo.pl6
>      =C2=A0 =C2=A0 =C2=A0Use of uninitialized value of type Int in stri=
ng context.
>      =C2=A0 =C2=A0 =C2=A0Methods .^name, .perl, .gist, or .say can be u=
sed to stringify
>      =C2=A0 =C2=A0 =C2=A0it to something meaningful.=C2=A0 in block <un=
it> at ./RtnBooBoo.pl6
>      =C2=A0 =C2=A0 =C2=A0line 12
>=20
>      =C2=A0 =C2=A0 =C2=A0X =3D <6>=C2=A0 =C2=A0 Y =3D <>
>=20
> This is a runtime error, not a compile time error. And it's got nothing=
,=20
> or very little, to do with the routine itself. When you are doing the=20
> assignment of x and y, you are giving Y a null value. There's no way th=
e=20
> static type checker (run by -c) knows this. You know, Turing halting=20
> problem and all that.
>=20
>=20
>     Which is a bizarre warning (it does not stop on this error).=C2=A0 =
And
>=20
>=20
> A warning, by definition, does not stop. It's simply saying: hey, you=20
> are trying to convert into a string something that cannot be converted =

> (a null value). Let's say it's nothing (empty string), and let's leave =

> it at that.
>=20
>     it is also not the error.=C2=A0 The error was that the return line'=
s
>     returned variables and the caller do not match up.=C2=A0 Not an
>     uninitialized value.
>=20
>=20
> There's no type checking _at return time_ it happens _at assignment=20
> time_. And that time is runtime, not compile time.
>=20
>=20
>     If you send too few variables to a sub, you get the finger shaken
>     at you.=C2=A0 The return should also have the same checking capabil=
ity.
>=20
>=20
> You can assign a null value to any typed variable. That's not a problem=
=2E=20
> The problem is trying to print it.
>=20
>=20
>     Would you guys please consider improving the checker and the compil=
er?
>=20
>=20
> I would say that would need solving the Turing halting problem (or=20
> variation thereof) https://en.wikipedia.org/wiki/Halting_problem So=20
> that's not within reach of a bunch of Perl programmers, even if hubris =

> is one of our qualities.
>=20
> Cheers
>=20
> JJ

Hi JJ,

Indeed.  That does not mean I like the way it is done.

You know, if you guys ever decide to allow more than one
return type without having to create a new type, that would
make me happy:

sub AddThree( Int $a, Int $b, Int $c --> Str, Int ) {
     my Int $d =3D $a + $b + $c;
     return ( "a+b+c=3D", $d );
}

I would post it as an RFE at the bug reporter, but I don't feel
like the ...

-T
0
perl6
1/4/2019 7:58:20 PM
Reply: