perl11 / cperl

A perl5 with classes, types, compilable, company friendly, security
http://perl11.org/
Other
142 stars 17 forks source link

class, method, multi keywords #16

Closed rurban closed 7 years ago

rurban commented 9 years ago

Parse them into the existing structures. See https://design.perl6.org/S12.html#multi_Declarations

perl6 creates a longname of the sig types and aliases them to the combined shortname, the proto (aka generic). Their multiple dispatch is the global shortest distance over all argument types, as in Damian's Class::MultiMethods http://cpansearch.perl.org/src/DCONWAY/Class-Multimethods-1.70/tutorial.html with an error if there are equally ranked candidates. perl6 allows multi subs and methods, plus proto and only prefix keywords. (similar to extern/native). sub is even optional, so they favor multi subs over methods.

For the beginning with cperl only allow it within classes, and favor methods over subs: allow method only within class {} blocks, to allow stricter and better semantics. allow sub class{} and class() sub decl and calls, which e.g. is used in B allow multi (aka generics) outside of class {} blocks. allow $class: invocant syntax pass $self onto the signature of methods automatically, but not with :method attributes, only method declarations. add has fields and methods accessor methods re-implement pseudo-hashes for the internal object layout for the default BUILD method for class->new objects. method-dispatch via global shortest distance, as in Class::MultiMethods, seems to be too much overhead and counterintuitive. much better would be a trivial left-to-right shortest distance (via c3 of course) without backtracking. This can be optimized to simple dynamic decision trees embedded into the method op, as in most other efficient method dispatch implementations. (see e.g "Efficient Method Dispatch in PCL", Kiczales, Rodriguez 1990", or the Cecil, profile guided Self-93 or Squeak dispatcher) classes can have the :native attribute, to layout the hash fields as in C, to be used as native structs for the ffi.

fail at 'Invalid method call on class subroutine' and vice versa 'Invalid subroutine call on class method'. warn on redefining packages as classes, as classes are more restrictive. when redefining classes as packages it will fail at the readonly stash.

See the branch feature/gh16-multi

rurban commented 7 years ago

Todo: