Luke,

On Oct 10, 2005, at 7:47 PM, Luke Palmer wrote:
How do you explain this:

    class Foo {
        method bar (Class $class:) { "class method" }
    }
    say Foo.bar;        # class method
    my $foo = Foo.new;
    say $foo.bar;       # class method

Assuming that that is valid Perl.

It is "valid" Perl 5, however (IMHO) it is *not* valid Perl 6.

To start with, the type of the invocant is Class, which $foo is not derived from (it is an instance of something which itself is an instance of Class).

I think that

  $foo.class.bar()

should work. And changing the method defintion to be

  method bar (Class|Foo $class:) { ... }

should work, but the code as you wrote it should not. Which means that when we deal with Perl 5 classes within Perl 6, we should likely give them an implied signature of (Class|Foo $self:) or some other weirdness (I haven't thought that far down the line yet).

Class methods are strange creatures, in Perl 5 they were nothing different than instance methods. In Java (static methods), they are really just odd functions which need to be qualified by a class name. Python doesn't even really have them (you have to jump through odd hoops to make the method "callable"). Ruby uses Eigenclasses, and CLOS uses something akin to eigenclasses. I am not sure how Smalltalk handles things, but my guess is that class methods on Foo are instance methods of classFoo, or some such.

They are ugly beasties no matter what, but eigenclasses (so far) seem to be the prettiest of the uglies.

Stevan


Reply via email to