At 07:54 PM 4/10/2002 +0100, Piers Cawley wrote: >Graham Barr <[EMAIL PROTECTED]> writes: > > > On Wed, Apr 10, 2002 at 01:35:22PM -0400, Mark J. Reed wrote: > >> On Wed, Apr 10, 2002 at 10:30:25AM -0700, Glenn Linderman wrote: > >> > method m1 > >> > { > >> > m2; # calls method m2 in the same class > >> Yes, but does it call it as an instance method on the current invocant > >> or as a class method with no invocant? If the former, how would you > >> do the latter? > > > > This may be a case of keep up at the back, but if that is a method call, > > how do I call a subroutine from within a method ? > >And anyone who says "You don't" will receive a good hard talking to >from me. Being able to declare private subroutines within classes is >really useful, witness: > > class SchemeNumber is SchemeExpr { > my sub apply($self: $target, $rhs, &block) { > if $is_rhs { $self.new(+ &block( $target, $self.value )) } > else { $self.new(+ &block( $self.value, $target )) } > } > > method operator:+ { apply(*@_, {$^a + $^b}) } > method operator:* { apply(*@_, {$^a * $^b}) } > method operator:- { apply(*@_, {$^a * $^b}) } > method operator:/ { apply(*@_, {$^a * $^b}) } > > method is_number { 1 } > } > >Yes, I know there's several different ways I could do it, but this >approach feels right.
I agree, however you passed in the invocant so there is no ambiguity in your case. Calling a class method off of an object, I've found use for. Calling an instance method from a class invocant scope doesn't make sense to me which is what I _think_ Graham's example was implying. I suppose this would be akin to: if(typeof(self) is 'class') { ... } else { # instance ... } I think that would be just plain bad design, but I'd be happy if someone showed me a use for it. :) -Melvin