On 2020-01-21 18:57, Tom Browder wrote:
On Tue, Jan 21, 2020 at 18:34 Todd Chester via perl6-users <perl6-users@perl.org <mailto:perl6-users@perl.org>> wrote:

    On 2020-01-21 16:09, Todd Chester via perl6-users wrote:
     >> 4) A block (that is the { ... } bit) will always 'return' the last
     >> expression evaluated.
     >
     > Seems to me I have see the last expression returned even without
     > the {...}.  Maybe I am misremembering.


Todd, the {} is the block defining the subroutine.

      > sub AplusB( $a, $b --> Int ){$a+$b;}


The above is the sub's definition.



    &AplusB


The above should generate an error because the mandatory args are missing, depending on the context (don't quote me on that).

&AplusB is printer out by REPL.  I don't know why.  REPL
does that a lot.


      > AplusB 2, 3
    5

The above shows the sub being called with the required two args, and the 5 is the returned value which is probably shown in the REPL since there is no semicolon after the call and the 5 is not usually seen otherwise.

$ p6 'sub AplusB( $a, $b --> Int ){$a+$b}; say AplusB 2, 3;'
5


-Tom

Hi Tom,

I was trying to cut things down to the simplest terms.
I was responding to Richard's statement

 >> 4) A block (that is the { ... } bit) will always 'return' the last
 >>    expression evaluated.

I created a sub without the "{...}" and showed where it would
return the last equation without the "{...}".  I may have
misunderstood Richard.

-T

Reply via email to