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

Re: MMD as an object.

Thread Previous | Thread Next
From:
Miroslav Silovic
Date:
March 10, 2005 01:53
Subject:
Re: MMD as an object.
Message ID:
42301687.9020507@puremagic.com
rod@rodadams.net wrote:

> It would behave like a tied sub (or method), with a .dispatch method 
> to decide which of the contained routines should be called this 
> particular time. Manhattan would be the default. However, one can 
> override the dispatch logic; implementing Luke's Patterns idea, for 
> example.
>
Hmm, that ties into my wishlist item. Would it be possible to implement 
method combinators (or rather, multimethod combinators) from Common LISP 
in addition to this? The only CLOS feature that A12 doesn't mention, 
can't let that happen. ;)

class A { ... }
class B is A { ... }

1> multi foo ($a) is before { ... }
2> multi foo (B $a) { ... next METHOD; ...}
3> multi foo (A $a) { ... }
4> multi foo ($a) is after { ... }
5> multi foo ($a) is around { ... next METHOD; }
6> multi foo ($a) is before { ... }

.... and this runs all 5 methods, in order 5 > 1 > 2 > 6 > 3 > (returns 
to 2) > 4 > (returns to 5)
And yes, 6 and 1 do have the same signature. The rule is to run all 
before methods in order of the currently selected distance (ties broken 
in random order ;) ), and all after methods in the reverse order.

Oh, and the reason why around methods are useful?

multi foo ($a) is around {
    CATCH { ... }
    next METHOD;
}

Note that this catches the exceptions thrown by any version of foo, even 
though at this point you don't know whether foo will be specialised. 
before methods aren't useful for this since their stack frame and 
handler blocks don't linger during the executions of other methods.

Common LISP references:

Standard method combination (before, after, around)
http://www.lispworks.com/documentation/HyperSpec/Body/07_ffb.htm

Other method combinations (+, and, etc)
http://www.lispworks.com/documentation/HyperSpec/Body/07_ffd.htm

Creating your own method combinations (define-method-combination)
http://www.lispworks.com/documentation/HyperSpec/Body/m_defi_4.htm

Come to think of this, it seems that the only thing that'd need to be 
modified to accomodate both Rod's and mine proposal is to move CALLONE 
and CALLALL from the class to be MMD object somehow. Perhaps

multi CALLONE ($obj, $method where { $_ == &func }, *@_) { ... }

Hmm, but this syntax strikes me as icky.

    Miro


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