There are also Blocks like : my $a = do { 5 }; say $a; (Gives 5);

Blocks turn up all over the place big different between blocks and Routines
(Sub or Method) is you can't return from them. They will return the last
thing evaluated within them though. But a return statement inside one
raises and Expection. (Might be a Failure)...

On Tue, 11 Sep 2018 at 16:24 yary <not....@gmail.com> wrote:

> And looking at questions in other threads- there are subroutines declared
> with "sub", those get called without an invocant.
>
> sub i-am-a-sub() { say "Hi from subroutine land!" }
>
> i-am-a-sub; # says "Hi from subroutine land!"
>
> and methods are declared inside a class, and are called with an invocant
> of that class type.
>
> class sample-class {
>   method speak-to-me {say "We are classy"}
> }
> my sample-class $object;
> $object. speak-to-me; # Guess what it says
>
> ... subroutines and methods, in the perl6 class hierarchy, are both
> subclasses "Routine"
> maybe that's the word your looking for!
>
> -y
>
> On Tue, Sep 11, 2018 at 8:12 AM, yary <not....@gmail.com> wrote:
>
>> I would call them subroutines, since that's the long form of "sub"
>>
>> -y
>>
>> On Tue, Sep 11, 2018 at 3:47 AM, ToddAndMargo <toddandma...@zoho.com>
>> wrote:
>>
>>> Hi All,
>>>
>>> I use subs like ducks use water.  It is about time
>>> I learned what to properly call them.
>>>
>>> I come from Modula2 and Pascal (as well as bash), "functions"
>>> return a value outside the declared parameters and "(sub)routines"
>>> only can modify values through the declarations parameters.
>>>
>>> Sort of like
>>>     function:   sub add($a, $b){return $a+$b}
>>>     routine:    sub add($a, $b, rw $c){$c = $a+$b}
>>>
>>> In Perl, what is the proper terminology?
>>>
>>> Many thanks,
>>> -T
>>>
>>> I no longer use "rw $c".  I always use "return".
>>> The guys told me this was the best way on the
>>> chat line, so I adopted it.
>>>
>>
>>
> --
Simon Proctor
Cognoscite aliquid novum cotidie

Reply via email to