Perl6 Objects vs. the Common Lisp Object System

Home : Perl : Perl6 vs. CLOS

[this is a work in progress. -- rgr, 3-Apr-05.]

Table of contents

  1. Perl6 Objects vs. the Common Lisp Object System
    1. Table of contents
    2. Feature comparison
    3. Puzzles
    4. Glossary

Feature comparison

Class scoping.
[finish. -- rgr, 3-Apr-05.]
Method scoping.
Perl6 supports lexical and package scoping for multimethods. Lisp methods, even if named by unexported symbols, are nevertheless visible globally.
Local methods and submethods.
Perl6 has 'em; Lisp does not.
Anonymous metaobjects.
Lisp supports anonymous classes and generic functions; Perl6 does not. Needless to say, this is only useful if you indent to define methods on them dynamically.
Multiple vs. single dispatch.
Perl6 supports separate syntax for both independently (Perl5 had only single dispatch), but tries to blur the boundaries. Lisp has only multimethod syntax; if you want single dispatch, then only specialize the first argument. [Still trying to figure out the extent of semantic differences. -- rgr, 3-Apr-05.]
Typed methods and method combination.
Lisp has a concept of "method combination," which controls how to call the matching methods, and how to use their return values; method combinations are user-extensible, one of which is specified by each generic function (at least implicitly), and method combination is done at compile time. Perl6 has no typed methods, and no explicit notion of method combination, but provides flexible tools for finding and calling methods at dispatch time; some aspects of method combination are provided by the .*, .?, and .+ operators [is this for single-dispatch only?], which is under the control of the caller and not the multisub.
Dispatch specializers.
Perl6 supports discrimination based only on the class of the argument, while Lisp additionally supports EQL specializers, which are essentially singleton classes.

Puzzles

  1. What the heck is a "multi sub" decl for, given the existence of "multi method"? -- rgr, 3-Apr-05.

Glossary

Perl6 name Lisp name Definition
attribute slot These are state variables. Both languages support a choice of class or instance scope for a given attribute/slot.
long name method name This is how methods are named, and is composed of the short or GF name plus the list of specializers (called the signature in Perl6).
multisub generic function This is how a program invokes multiple-dispatch methods; in both languages, it looks like an ordinary subroutine call.
next call-next-method Within a method, this calls the next applicable method. [is it possible to change the arglist in perl6? -- rgr, 3-Apr-05.]
short name generic function name This is the name invoked by the caller.
?? specializer The restricted type of a multimethod argument, which is said to be "specialized to that type.

Appendix: Other MMD implementations


Bob Rogers <rogers@rgrjr.dyndns.org>
$Id$