New Perl6 """""feature"""""

Do you mean generic functions?

Generics in Perl 6 could refer to use of generic methods, generic functions, generic roles, or generic containers. I think you mean either generic methods or generic functions. Generic methods are just an object oriented specialization of generic functions so I'll focus on the latter.

Note that all this stuff sounds a lot more complicated than it feels in practice. In practice it just works.

A generic function consists of, at least semantically (the compiler optimizes away or caches this machinery much of the time):

  • a proto function that establishes whatever is common among overloads (automatically generated if the coder doesn't write one) and which serves as a (arbitrarily customizable) dispatcher.

  • one or more individual multi functions that serve as potential dispatchees, i.e. where a call might end up.

The compiler uses type information from an individual function call and from the multi function definitions that have matching name and signature to establish a candidate list of dispatchees for a call. (There's a compile-time error if the candidate list is empty or unacceptably ambiguous.)

At call time the dispatcher tries to call the top candidate from the list created earlier by the compiler. If the candidate fails a (run-time) subset constraint at binding time the next candidate is tried. (The next candidate also gets tried if a previous candidate is successfully called and asks for dispatch to continue to the next candidate.)

Hopefully the foregoing addressed what you meant.

And to tie up a couple loose ends from your comment:

  • Methods can be defined wherever but are usually part of a class or role.

  • Once the closing curly of a class definition has been parsed the class becomes immutable (unless it's later explicitly augmented or superseded).

/r/ProgrammerHumor Thread Parent Link - i.imgur.com