develooper Front page | perl.perl6.language | Postings from June 2005

Re: OO magic (at least for me)

Thread Previous | Thread Next
From:
Juerd
Date:
June 26, 2005 10:45
Subject:
Re: OO magic (at least for me)
Message ID:
20050626174458.GA7720@c4.convolution.nl
BÁRTHÁZI András skribis 2005-06-26 19:35 (+0200):
>     method fun1() { fun2(); }
>     method fun2() { say "fun2!"; }
> *** No compatible subroutine found: "&fun2"

fun2 is a method, not a sub. You need method syntax to call it:

    ./fun2;

> class MyMethod { method fun1() { fun2(); } sub fun2() { say "fun2!"; }
> } class Child is MyMethod { }
> Child.fun1();
> Sounds good. It seems to me, that I can call fun2() from inside 
> MyMethod, from everywhere. OK, Child is MyMethod, so can I do it there 
> too? No. :(

IIRC, that's what submethods are for. Submethods aren't inherited. It is
unclear to me whether subs are.

Two requests:

1. Please indent code and don't use cutting lines.

2. Please use visually more different names, fun1 and fun2 look a lot
alike. Consider foo and bar.


Juerd
-- 
http://convolution.nl/maak_juerd_blij.html
http://convolution.nl/make_juerd_happy.html 
http://convolution.nl/gajigu_juerd_n.html

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About