On Wed, Jun 03, 2020 at 07:00:53PM -0700, ToddAndMargo via perl6-users wrote:
> On 2020-06-03 02:21, Peter Pentchev wrote:
> > On Wed, Jun 03, 2020 at 01:06:33AM -0700, ToddAndMargo via perl6-users 
> > wrote:
> > > On 2020-06-02 22:15, Peter Pentchev wrote:
> > > > On Tue, Jun 02, 2020 at 07:39:16PM -0700, ToddAndMargo via perl6-users 
> > > > wrote:
> > > > > On 2020-06-01 23:02, Peter Pentchev wrote:
> > > > > > https://docs.raku.org/language/classtut
> > > > > 
> > > > > Error 522 Ray ID: 59d609616954eb79 • 2020-06-03 02:38:12 UTC
> > > > > Connection timed out
> > > > > 
> > > > > Poop!
> > > > 
> > > > This is usually some kind of temporary error - something broke down
> > > > between your computer and the server. Try again later, it might work.
> > > > (it's the Raku docs site, you've used it before, you know it usually
> > > > works :)
> > > > 
> > > > G'luck,
> > > > Peter
> > > > 
> > > 
> > > Hi Peter,
> > > 
> > > It is working now.  Thank you.
> > > 
> > > You would happen to know of a tutorial.  Me and
> > > the documents ... well, lets say they are not
> > > written with the same outcome in mind as perldocs.
> > > 
> > > Is there a way to write a methods as I would write
> > > a sub and avoiding the class thing?
> > 
> > OK, now I really have to ask, just like other people have.
> > 
> > What exactly do you mean by "method"?
> > 
> > G'luck,
> > Peter
> > 
> 
> > say "AbCd".lc
> abcd
> 
> lc would be the method:
> multi method lc(Str:D: --> Str:D)

Right. So apart from the & trick that Fernando Santagata showed you (but
see below, it's not really calling a method) and that is neat but has
its drawbacks (like for instance you cannot ask an object if it .can()
do a specific method), you want to call a method on an object.

In general, and the point of this subthread is, methods are not
standalone subroutines; they are defined as part of the whole "variables
have types, those types are called classes, each class defines
the methods that you may call on its variables" object-oriented
programming thing. When you say "method", this is what people think
you're talking about, because, well, this is what "method" kind of means
when one uses it in a conversation about computer programming,
especially when talking about a language with a class-, role-, and
inheritance-based type system.

The trick that Fernando showed you is not really calling a method;
it is a cute way of the Raku syntax to specify the first argument when
calling a subroutine. The subroutine is not a method, it does not show
up in .can() or .^methods or .HOW or any of the way to ask a variable
what methods it supports. Yes, it is possible to define a multi sub that
does different things when called on different types of first argument,
but it is still not a method, it is a subroutine.

A method is something that is tied to a class. For a quick overview of
classes, methods, and the main ideas of object-oriented programming, try
https://www.freecodecamp.org/news/object-oriented-programming-concepts-21bb035f7260/
Also, take another look at https://docs.raku.org/language/classtut -
especially the part "Starting with a class" and onwards.

G'luck,
Peter

-- 
Peter Pentchev  r...@ringlet.net r...@debian.org p...@storpool.com
PGP key:        http://people.FreeBSD.org/~roam/roam.key.asc
Key fingerprint 2EE7 A7A5 17FC 124C F115  C354 651E EFB0 2527 DF13

Attachment: signature.asc
Description: PGP signature

Reply via email to