> they were all just subs.

With perl5 code, I've gravitated to talking about "routines" when I don't
want to worry about whether something is technically a function or a
method.  It doesn't seem to confuse anyone.  (On the other hand, I've had
people make fun of me for using the word "subroutine", because it sounds
too much like jargon from Basic... CS snobbery has been around for quite
some time.)

With perl6, I find myself stumbling over what to call the built-ins...
"functions", "commands", "keywords"?

On Tue, Sep 11, 2018 at 10:40 AM, Trey Harris <t...@lopsa.org> wrote:

> To get directly at your question: in Perl 6, this is not an important
> delineation, so there are no simple names for the two Pascal/Modula
> concepts. Perl's never made a distinction between "procedures" and
> "functions" in the Pascal sense; they were all just subs. Eventually Perl
> gained classes and blessed objects and so we got "methods", but in Perl 5
> they were just gussied-up subs.
> The delineations that matter in Perl 6 are subs vs. methods vs. blocks (as
> yary and Simon have said previously in the thread).
> Perl allows you to do very naughty things, such as define a method that
> modifies its invocant, some of its parameters, returns a result that can
> indicate a failure, and throws exceptions. Doing all these things is
> allowed but would almost certainly be quite unwise. But when you try to
> find the 1:1 mapping of some other language's construct to another's, you
> always get one of four answers:
> 1. There is a thing exactly like the other language's thing at the same
> level of complexity using similar syntax and semantics.
> 2. There is a analogous thing in semantics, but it's not very similar in
> syntax.
> 3. There is a thing that's similar in syntax, but very different in
> semantics.
> 4. There is no thing like the other language's thing in syntax or
> semantics.
> The issue you get into in Perl 6 is that it's _such_ a flexible language
> that it pretty much never says number 4. It usually says both 2 and 3. The
> old joke went that you could write FORTRAN in any language. Well, you can
> write any language in Perl 6. That doesn't mean it's a good idea.
> My suggestion would be: if you call it with a dot, it's a method. If you
> don't, it's a sub. Whether a sub returns something or not should be obvious
> from the purpose and how you name it. Whether a sub alters something or not
> should also be obvious from how you call it. The signatures are different,
> but the names don't matter.
> On Tue, Sep 11, 2018 at 11:31 Simon Proctor <simon.proc...@gmail.com>
> wrote:
>> 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