develooper Front page | perl.perl6.language | Postings from August 2001

Re: CLOS multiple dispatch

Thread Previous | Thread Next
Michael G Schwern
August 29, 2001 23:02
Re: CLOS multiple dispatch
Message ID:
On Wed, Aug 29, 2001 at 10:49:25PM -0700, Hong Zhang wrote:
> What is the need for CLOS? Are we trying to build a kitchen
> sink here?

Umm, I think you mean "What's the need for multiple dispatch?"

Currently, if I want to write a method that does this:

    my $name = $foo->name;

I have to write:

    sub name {
        my($self) = shift;

        if( @_ ) {
            my $name = shift;
            $self->{name} = $name;

        return $self->{name};

With multiple dispatch, I could instead write:

    # Following RFC 256
    sub name (Foo $self) : multi {
        return $self->{name};

    sub name (Foo $self, STRING $name) : multi {
        $self->{name} = $name;
        return $self->{name};

which is quite a bit simpler.


Michael G. Schwern   <>
Perl6 Quality Assurance     <>	     Kwalitee Is Job One
My lips, your breast and a whole lotta strange arguing.

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About